01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.async.impl;
05:
06: import com.tc.async.api.EventContext;
07: import com.tc.async.api.Stage;
08: import com.tc.lang.TCThreadGroup;
09: 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
22: .getLogger(StageManagerImplTest.class);
23: static {
24: logging
25: .info("I have to load this class for breaking circular dependency");
26: }
27:
28: private StageManagerImpl stageManager;
29: private TestEventHandler testEventHandler;
30:
31: /**
32: * Constructor for StageManagerImplTest.
33: *
34: * @param arg0
35: */
36: public StageManagerImplTest(String arg0) {
37: super (arg0);
38: }
39:
40: public static void main(String[] args) {
41: //
42: }
43:
44: /*
45: * @see TestCase#setUp()
46: */
47: protected void setUp() throws Exception {
48: super .setUp();
49: try {
50: stageManager = new StageManagerImpl(new TCThreadGroup(
51: new ThrowableHandler(TCLogging
52: .getLogger(StageManagerImpl.class))));
53: testEventHandler = new TestEventHandler();
54: } catch (Throwable t) {
55: t.printStackTrace();
56: }
57: }
58:
59: public void testStage() {
60: stageManager.createStage("testStage", testEventHandler, 1, 3);
61: Stage s = stageManager.getStage("testStage");
62: assertTrue(s != null);
63: s.getSink().add(new TestEventContext(1));
64: assertTrue(s.getSink().size() == 1);
65: assertTrue(testEventHandler.getContexts().size() == 0);
66: s.getSink().add(new TestEventContext(2));
67: assertTrue(s.getSink().size() == 2);
68: assertTrue(testEventHandler.getContexts().size() == 0);
69: s.start(new ConfigurationContextImpl(null));
70: ThreadUtil.reallySleep(1000);
71: System.out.println("size=" + s.getSink().size());
72: assertTrue(s.getSink().size() == 0);
73: assertTrue(testEventHandler.getContexts().size() == 2);
74: stageManager.stopAll();
75: }
76:
77: /*
78: * @see TestCase#tearDown()
79: */
80: protected void tearDown() throws Exception {
81: super .tearDown();
82: }
83:
84: private static class TestEventContext implements EventContext {
85: private int id;
86:
87: public TestEventContext(int id) {
88: this .id = id;
89: }
90:
91: public int getID() {
92: return id;
93: }
94: }
95: }
|