1 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 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 34 public StageManagerImplTest(String arg0) { 35 super(arg0); 36 } 37 38 public static void main(String [] args) { 39 } 41 42 45 protected void setUp() throws Exception { 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 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 77 protected void tearDown() throws Exception { 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 |