KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > async > impl > StageManagerImplTest


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.async.impl;
5
6 import com.tc.async.api.EventContext;
7 import com.tc.async.api.Stage;
8 import com.tc.lang.TCThreadGroup;
9 import com.tc.lang.ThrowableHandler;
10 import com.tc.logging.TCLogger;
11 import com.tc.logging.TCLogging;
12 import com.tc.util.concurrent.ThreadUtil;
13
14 import junit.framework.TestCase;
15
16 /**
17  * @author steve To change the template for this generated type comment go to Window>Preferences>Java>Code
18  * Generation>Code and Comments
19  */

20 public class StageManagerImplTest extends TestCase {
21   private static final TCLogger logging = TCLogging.getLogger(StageManagerImplTest.class);
22   static {
23     logging.info("I have to load this class for breaking circular dependency");
24   }
25   
26   private StageManagerImpl stageManager;
27   private TestEventHandler testEventHandler;
28
29   /**
30    * Constructor for StageManagerImplTest.
31    *
32    * @param arg0
33    */

34   public StageManagerImplTest(String JavaDoc arg0) {
35     super(arg0);
36   }
37
38   public static void main(String JavaDoc[] args) {
39     //
40
}
41
42   /*
43    * @see TestCase#setUp()
44    */

45   protected void setUp() throws Exception JavaDoc {
46     super.setUp();
47     try {
48     stageManager = new StageManagerImpl(new TCThreadGroup(new ThrowableHandler(TCLogging
49         .getLogger(StageManagerImpl.class))));
50     testEventHandler = new TestEventHandler();
51     } catch(Throwable JavaDoc t) {
52       t.printStackTrace();
53     }
54   }
55
56   public void testStage() {
57     stageManager.createStage("testStage", testEventHandler, 1, 3);
58     Stage s = stageManager.getStage("testStage");
59     assertTrue(s != null);
60     s.getSink().add(new TestEventContext(1));
61     assertTrue(s.getSink().size() == 1);
62     assertTrue(testEventHandler.getContexts().size() == 0);
63     s.getSink().add(new TestEventContext(2));
64     assertTrue(s.getSink().size() == 2);
65     assertTrue(testEventHandler.getContexts().size() == 0);
66     s.start(new ConfigurationContextImpl(null));
67     ThreadUtil.reallySleep(1000);
68     System.out.println("size=" + s.getSink().size());
69     assertTrue(s.getSink().size() == 0);
70     assertTrue(testEventHandler.getContexts().size() == 2);
71     stageManager.stopAll();
72   }
73
74   /*
75    * @see TestCase#tearDown()
76    */

77   protected void tearDown() throws Exception JavaDoc {
78     super.tearDown();
79   }
80
81   private static class TestEventContext implements EventContext {
82     private int id;
83
84     public TestEventContext(int id) {
85       this.id = id;
86     }
87
88     public int getID() {
89       return id;
90     }
91   }
92 }
93
Popular Tags