001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.net.protocol.tcm;
006:
007: import com.tc.async.api.AddPredicate;
008: import com.tc.async.api.EventContext;
009: import com.tc.async.api.Sink;
010: import com.tc.exception.ImplementMe;
011: import com.tc.net.TCSocketAddress;
012: import com.tc.net.groups.ClientID;
013: import com.tc.net.protocol.NetworkStackID;
014: import com.tc.net.protocol.TCNetworkMessage;
015: import com.tc.object.session.SessionID;
016: import com.tc.stats.Stats;
017: import com.tc.test.TCTestCase;
018:
019: import java.util.Collection;
020: import java.util.List;
021:
022: public class HydrateHandlerTest extends TCTestCase {
023:
024: public void testHydrateException() {
025: HydrateHandler handler = new HydrateHandler();
026:
027: Channel channel = new Channel(1);
028: Message message = new Message(channel);
029: HydrateContext context = new HydrateContext(message,
030: new TestSink());
031:
032: handler.handleEvent(context);
033: assertTrue(channel.wasClosed);
034: assertTrue(message.wasHydrated);
035: }
036:
037: private static class TestSink implements Sink {
038:
039: public void add(EventContext context) {
040: throw new AssertionError("not supposed to happen");
041: }
042:
043: public boolean addLossy(EventContext context) {
044: throw new AssertionError("not supposed to happen");
045: }
046:
047: public void addMany(Collection contexts) {
048: throw new AssertionError("not supposed to happen");
049: }
050:
051: public void clear() {
052: throw new AssertionError("not supposed to happen");
053: }
054:
055: public AddPredicate getPredicate() {
056: throw new AssertionError("not supposed to happen");
057: }
058:
059: public void pause(List pauseEvents) {
060: throw new AssertionError("not supposed to happen");
061: }
062:
063: public void setAddPredicate(AddPredicate predicate) {
064: throw new AssertionError("not supposed to happen");
065: }
066:
067: public int size() {
068: throw new AssertionError("not supposed to happen");
069: }
070:
071: public void unpause() {
072: throw new AssertionError("not supposed to happen");
073: }
074:
075: public void enableStatsCollection(boolean enable) {
076: throw new ImplementMe();
077:
078: }
079:
080: public Stats getStats(long frequency) {
081: throw new ImplementMe();
082: }
083:
084: public Stats getStatsAndReset(long frequency) {
085: throw new ImplementMe();
086: }
087:
088: public boolean isStatsCollectionEnabled() {
089: throw new ImplementMe();
090: }
091:
092: public void resetStats() {
093: throw new ImplementMe();
094: }
095:
096: }
097:
098: private static class Channel implements MessageChannel {
099:
100: private final ChannelID channelID;
101: private boolean wasClosed = false;
102:
103: public Channel(int id) {
104: channelID = new ChannelID(id);
105: }
106:
107: public void addAttachment(String key, Object value,
108: boolean replace) {
109: throw new ImplementMe();
110: }
111:
112: public void addListener(ChannelEventListener listener) {
113: throw new ImplementMe();
114: }
115:
116: public void close() {
117: this .wasClosed = true;
118: }
119:
120: public TCMessage createMessage(TCMessageType type) {
121: throw new ImplementMe();
122: }
123:
124: public Object getAttachment(String key) {
125: throw new ImplementMe();
126: }
127:
128: public ChannelID getChannelID() {
129: return channelID;
130: }
131:
132: public TCSocketAddress getLocalAddress() {
133: throw new ImplementMe();
134: }
135:
136: public TCSocketAddress getRemoteAddress() {
137: throw new ImplementMe();
138: }
139:
140: public boolean isClosed() {
141: throw new ImplementMe();
142: }
143:
144: public boolean isConnected() {
145: throw new ImplementMe();
146: }
147:
148: public boolean isOpen() {
149: throw new ImplementMe();
150: }
151:
152: public NetworkStackID open() {
153: throw new ImplementMe();
154: }
155:
156: public Object removeAttachment(String key) {
157: throw new ImplementMe();
158: }
159:
160: public void send(TCNetworkMessage message) {
161: throw new ImplementMe();
162: }
163:
164: }
165:
166: private static class Message implements TCMessage {
167:
168: private final Channel channel;
169: private boolean wasHydrated = false;
170:
171: public Message(Channel channel) {
172: this .channel = channel;
173: }
174:
175: public void dehydrate() {
176: throw new ImplementMe();
177: }
178:
179: public MessageChannel getChannel() {
180: return channel;
181: }
182:
183: public ClientID getClientID() {
184: return new ClientID(channel.getChannelID());
185: }
186:
187: public SessionID getLocalSessionID() {
188: throw new ImplementMe();
189: }
190:
191: public TCMessageType getMessageType() {
192: return TCMessageType.PING_MESSAGE;
193: }
194:
195: public int getTotalLength() {
196: throw new ImplementMe();
197: }
198:
199: public void hydrate() {
200: this .wasHydrated = true;
201: throw new RuntimeException(
202: "This exception is SUPPOSED to happen -- please don't squelch it's printing in HydrateHandler");
203: }
204:
205: public void send() {
206: throw new ImplementMe();
207: }
208:
209: }
210:
211: }
|