import com.google.code.yanf4j.util.DispatcherFactory;
public class DispatcherFactoryUnitTest {
@Test
public void testNewDispatcher() throws Exception {
Dispatcher dispatcher = DispatcherFactory.newDispatcher(1,
new ThreadPoolExecutor.AbortPolicy(),"test");
Assert.assertNotNull(dispatcher);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger count = new AtomicInteger();
dispatcher.dispatch(new Runnable() {
public void run() {
count.incrementAndGet();
latch.countDown();
}
});
latch.await();
Assert.assertEquals(1, count.get());
Assert.assertNull(DispatcherFactory.newDispatcher(0,
new ThreadPoolExecutor.AbortPolicy(),"test"));
Assert.assertNull(DispatcherFactory.newDispatcher(-1,
new ThreadPoolExecutor.AbortPolicy(),"test"));
dispatcher.stop();
try {
dispatcher.dispatch(new Runnable() {
public void run() {
Assert.fail();
}
});
} catch (Exception e) {