Package com.google.code.yanf4j.test.unittest.utils

Source Code of com.google.code.yanf4j.test.unittest.utils.DispatcherFactoryUnitTest

package com.google.code.yanf4j.test.unittest.utils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;

import junit.framework.Assert;

import org.junit.Test;

import com.google.code.yanf4j.core.Dispatcher;
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) {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of com.google.code.yanf4j.test.unittest.utils.DispatcherFactoryUnitTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.