KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > tcm > HydrateHandlerTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.protocol.tcm;
5
6 import com.tc.async.api.AddPredicate;
7 import com.tc.async.api.EventContext;
8 import com.tc.async.api.Sink;
9 import com.tc.exception.ImplementMe;
10 import com.tc.net.TCSocketAddress;
11 import com.tc.net.protocol.NetworkStackID;
12 import com.tc.net.protocol.TCNetworkMessage;
13 import com.tc.object.session.SessionID;
14 import com.tc.stats.Stats;
15 import com.tc.test.TCTestCase;
16
17 import java.util.Collection JavaDoc;
18 import java.util.List JavaDoc;
19
20 public class HydrateHandlerTest extends TCTestCase {
21
22   public void testHydrateException() {
23     HydrateHandler handler = new HydrateHandler();
24
25     Channel channel = new Channel(1);
26     Message message = new Message(channel);
27     HydrateContext context = new HydrateContext(message, new TestSink());
28
29     handler.handleEvent(context);
30     assertTrue(channel.wasClosed);
31     assertTrue(message.wasHydrated);
32   }
33
34   private static class TestSink implements Sink {
35
36     public void add(EventContext context) {
37       throw new AssertionError JavaDoc("not supposed to happen");
38     }
39
40     public boolean addLossy(EventContext context) {
41       throw new AssertionError JavaDoc("not supposed to happen");
42     }
43
44     public void addMany(Collection JavaDoc contexts) {
45       throw new AssertionError JavaDoc("not supposed to happen");
46     }
47
48     public void clear() {
49       throw new AssertionError JavaDoc("not supposed to happen");
50     }
51
52     public AddPredicate getPredicate() {
53       throw new AssertionError JavaDoc("not supposed to happen");
54     }
55
56     public void pause(List JavaDoc pauseEvents) {
57       throw new AssertionError JavaDoc("not supposed to happen");
58     }
59
60     public void setAddPredicate(AddPredicate predicate) {
61       throw new AssertionError JavaDoc("not supposed to happen");
62     }
63
64     public int size() {
65       throw new AssertionError JavaDoc("not supposed to happen");
66     }
67
68     public void unpause() {
69       throw new AssertionError JavaDoc("not supposed to happen");
70     }
71
72     public void enableStatsCollection(boolean enable) {
73       throw new ImplementMe();
74       
75     }
76
77     public Stats getStats(long frequency) {
78       throw new ImplementMe();
79     }
80
81     public Stats getStatsAndReset(long frequency) {
82       throw new ImplementMe();
83     }
84
85     public boolean isStatsCollectionEnabled() {
86       throw new ImplementMe();
87     }
88
89     public void resetStats() {
90       throw new ImplementMe();
91     }
92
93   }
94
95   private static class Channel implements MessageChannel {
96
97     private final ChannelID channelID;
98     private boolean wasClosed = false;
99
100     public Channel(int id) {
101       channelID = new ChannelID(id);
102     }
103
104     public void addAttachment(String JavaDoc key, Object JavaDoc value, boolean replace) {
105       throw new ImplementMe();
106     }
107
108     public void addListener(ChannelEventListener listener) {
109       throw new ImplementMe();
110     }
111
112     public void close() {
113       this.wasClosed = true;
114     }
115
116     public TCMessage createMessage(TCMessageType type) {
117       throw new ImplementMe();
118     }
119
120     public Object JavaDoc getAttachment(String JavaDoc key) {
121       throw new ImplementMe();
122     }
123
124     public ChannelID getChannelID() {
125       return channelID;
126     }
127
128     public TCSocketAddress getLocalAddress() {
129       throw new ImplementMe();
130     }
131
132     public TCSocketAddress getRemoteAddress() {
133       throw new ImplementMe();
134     }
135
136     public boolean isClosed() {
137       throw new ImplementMe();
138     }
139
140     public boolean isConnected() {
141       throw new ImplementMe();
142     }
143
144     public boolean isOpen() {
145       throw new ImplementMe();
146     }
147
148     public NetworkStackID open() {
149       throw new ImplementMe();
150     }
151
152     public Object JavaDoc removeAttachment(String JavaDoc key) {
153       throw new ImplementMe();
154     }
155
156     public void send(TCNetworkMessage message) {
157       throw new ImplementMe();
158     }
159
160   }
161
162   private static class Message implements TCMessage {
163
164     private final Channel channel;
165     private boolean wasHydrated = false;
166
167     public Message(Channel channel) {
168       this.channel = channel;
169     }
170
171     public void dehydrate() {
172       throw new ImplementMe();
173     }
174
175     public MessageChannel getChannel() {
176       return channel;
177     }
178
179     public ChannelID getChannelID() {
180       return channel.getChannelID();
181     }
182
183     public SessionID getLocalSessionID() {
184       throw new ImplementMe();
185     }
186
187     public TCMessageType getMessageType() {
188       return TCMessageType.PING_MESSAGE;
189     }
190
191     public int getTotalLength() {
192       throw new ImplementMe();
193     }
194
195     public void hydrate() {
196       this.wasHydrated = true;
197       throw new RuntimeException JavaDoc(
198                                  "This exception is SUPPOSED to happen -- please don't squelch it's printing in HydrateHandler");
199     }
200
201     public void send() {
202       throw new ImplementMe();
203     }
204
205   }
206
207 }
208
Popular Tags