@Test
  public void testPubSubThreadPoolStage() throws Exception {
    System.out.println(logPrefix + name.getMethodName());

    Monitor monitor = new Monitor();
    TimerStage timer = new TimerStage(new TimeoutHandler(monitor), 5000, 5000);

    Set<TestEvent> procSet = Collections.synchronizedSet(new HashSet<TestEvent>());
    Set<TestEvent> orgSet = Collections.synchronizedSet(new HashSet<TestEvent>());
    int expected = 10;

    PubSubEventHandler<TestEvent> handler = new PubSubEventHandler<TestEvent>();
    handler.subscribe(
        TestEvent.class, new TestEventHandler("Handler1", monitor, procSet, expected));
    handler.subscribe(
        TestEvent.class, new TestEventHandler("Handler2", monitor, procSet, expected));

    EStage<TestEvent> stage = new ThreadPoolStage<TestEvent>(handler, 10);

    for (int i = 0; i < expected; ++i) {
      TestEvent a = new TestEvent("aaa");
      orgSet.add(a);

      stage.onNext(a);

      if (i == 5) {
        handler.subscribe(
            TestEvent.class, new TestEventHandler("Handler3", monitor, procSet, expected));
      }
    }

    monitor.mwait();

    stage.close();
    timer.close();

    Assert.assertEquals(orgSet, procSet);
  }
 @Override
 public void onNext(TestEvent e) {
   set.add(e);
   System.out.println(name + " " + e + " " + e.getMsg());
   if (set.size() == expected) monitor.mnotify();
 }