FileDocCategorySizeDatePackage
ExecutorCompletionServiceTest.javaAPI DocAndroid 1.5 API4705Wed May 06 22:41:02 BST 2009tests.api.java.util.concurrent

ExecutorCompletionServiceTest

public class ExecutorCompletionServiceTest extends JSR166TestCase

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run (suite());  
    
public static junit.framework.Testsuite()

        return new TestSuite(ExecutorCompletionServiceTest.class);
    
public voidtestConstructorNPE()
Creating a new ECS with null Executor throw NPE

        try {
            ExecutorCompletionService ecs = new ExecutorCompletionService(null);
            shouldThrow();
        } catch (NullPointerException success) {
        }
    
public voidtestConstructorNPE2()
Creating a new ECS with null queue throw NPE

        try {
            ExecutorService e = Executors.newCachedThreadPool();
            ExecutorCompletionService ecs = new ExecutorCompletionService(e, null);
            shouldThrow();
        } catch (NullPointerException success) {
        }
    
public voidtestPoll1()
If poll returns non-null, the returned task is completed

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            assertNull(ecs.poll());
            Callable c = new StringTask();
            ecs.submit(c);
            Thread.sleep(SHORT_DELAY_MS);
            for (;;) {
                Future f = ecs.poll();
                if (f != null) {
                    assert(f.isDone());
                    break;
                }
            }
        } catch (Exception ex) {
            unexpectedException();
        } finally {
            joinPool(e);
        }
    
public voidtestPoll2()
If timed poll returns non-null, the returned task is completed

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            assertNull(ecs.poll());
            Callable c = new StringTask();
            ecs.submit(c);
            Future f = ecs.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
            if (f != null) 
                assert(f.isDone());
        } catch (Exception ex) {
            unexpectedException();
        } finally {
            joinPool(e);
        }
    
public voidtestSubmitNPE()
Submitting a null callable throws NPE

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            Callable c = null;
            ecs.submit(c);
            shouldThrow();
        } catch (NullPointerException success) {
        } finally {
            joinPool(e);
        }
    
public voidtestSubmitNPE2()
Submitting a null runnable throws NPE

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            Runnable r = null;
            ecs.submit(r, Boolean.TRUE);
            shouldThrow();
        } catch (NullPointerException success) {
        } finally {
            joinPool(e);
        }
    
public voidtestTake()
A taken submitted task is completed

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            Callable c = new StringTask();
            ecs.submit(c);
            Future f = ecs.take();
            assert(f.isDone());
        } catch (Exception ex) {
            unexpectedException();
        } finally {
            joinPool(e);
        }
    
public voidtestTake2()
Take returns the same future object returned by submit

        ExecutorService e = Executors.newCachedThreadPool();
        ExecutorCompletionService ecs = new ExecutorCompletionService(e);
        try {
            Callable c = new StringTask();
            Future f1 = ecs.submit(c);
            Future f2 = ecs.take();
            assertSame(f1, f2);
        } catch (Exception ex) {
            unexpectedException();
        } finally {
            joinPool(e);
        }