KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > handler > ChannelLifeCycleHandlerTest


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

5 package com.tc.objectserver.handler;
6
7 import com.tc.net.protocol.tcm.ChannelID;
8 import com.tc.net.protocol.tcm.TestCommunicationsManager;
9 import com.tc.net.protocol.tcm.TestMessageChannel;
10 import com.tc.object.net.TestDSOChannelManager;
11 import com.tc.objectserver.core.impl.TestServerConfigurationContext;
12 import com.tc.objectserver.tx.TestServerTransactionManager;
13 import com.tc.objectserver.tx.TestTransactionBatchManager;
14
15 import junit.framework.TestCase;
16
17 public class ChannelLifeCycleHandlerTest extends TestCase {
18   private ChannelLifeCycleHandler handler;
19   private TestTransactionBatchManager transactionBatchManager;
20   private TestServerTransactionManager transactionManager;
21   private TestCommunicationsManager commsManager;
22
23   protected void setUp() throws Exception JavaDoc {
24     super.setUp();
25     transactionManager = new TestServerTransactionManager();
26     this.transactionBatchManager = new TestTransactionBatchManager();
27     this.commsManager = new TestCommunicationsManager();
28     handler = new ChannelLifeCycleHandler(this.commsManager, this.transactionManager, this.transactionBatchManager, new TestDSOChannelManager());
29     TestServerConfigurationContext tscc = new TestServerConfigurationContext();
30     handler.initialize(tscc);
31   }
32
33   public void tests() throws Exception JavaDoc {
34     final ChannelID channelID = new ChannelID(1);
35
36     TestMessageChannel channel = new TestMessageChannel();
37     channel.channelID = channelID;
38
39     ChannelLifeCycleHandler.Event disconnectEvent = new ChannelLifeCycleHandler.Event(
40                                                                                       ChannelLifeCycleHandler.Event.REMOVE,
41                                                                                       channel);
42     handler.handleEvent(disconnectEvent);
43
44     assertEquals(channelID, transactionManager.shutdownClientCalls.poll(1));
45     assertEquals(channelID, transactionBatchManager.shutdownClientCalls.poll(1));
46
47     // now make sure it doesn't do anything if the comms manager is in shutdown.
48
this.commsManager.shutdown = true;
49     handler.handleEvent(disconnectEvent);
50
51     assertNull(transactionManager.shutdownClientCalls.poll(1));
52     assertNull(transactionBatchManager.shutdownClientCalls.poll(1));
53   }
54
55 }
56
Popular Tags