--- jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2005/08/01 19:54:04 1.5 +++ jsr166/src/test/tck/ExecutorCompletionServiceTest.java 2009/11/21 06:31:05 1.10 @@ -2,21 +2,22 @@ * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at * http://creativecommons.org/licenses/publicdomain - * Other contributors include Andrew Wright, Jeffrey Hayes, - * Pat Fisher, Mike Judd. + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import junit.framework.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.atomic.*; import java.math.BigInteger; import java.security.*; -public class ExecutorCompletionServiceTest extends JSR166TestCase{ +public class ExecutorCompletionServiceTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { return new TestSuite(ExecutorCompletionServiceTest.class); @@ -25,30 +26,28 @@ public class ExecutorCompletionServiceTe /** * Creating a new ECS with null Executor throw NPE - */ + */ public void testConstructorNPE() { try { ExecutorCompletionService ecs = new ExecutorCompletionService(null); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } /** * Creating a new ECS with null queue throw NPE - */ + */ public void testConstructorNPE2() { try { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e, null); shouldThrow(); - } catch (NullPointerException success) { - } + } catch (NullPointerException success) {} } /** * Submitting a null callable throws NPE - */ + */ public void testSubmitNPE() { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); @@ -64,7 +63,7 @@ public class ExecutorCompletionServiceTe /** * Submitting a null runnable throws NPE - */ + */ public void testSubmitNPE2() { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); @@ -80,8 +79,8 @@ public class ExecutorCompletionServiceTe /** * A taken submitted task is completed - */ - public void testTake() { + */ + public void testTake() throws InterruptedException { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); try { @@ -89,8 +88,6 @@ public class ExecutorCompletionServiceTe ecs.submit(c); Future f = ecs.take(); assertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -98,8 +95,8 @@ public class ExecutorCompletionServiceTe /** * Take returns the same future object returned by submit - */ - public void testTake2() { + */ + public void testTake2() throws InterruptedException { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); try { @@ -107,8 +104,6 @@ public class ExecutorCompletionServiceTe Future f1 = ecs.submit(c); Future f2 = ecs.take(); assertSame(f1, f2); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -116,8 +111,8 @@ public class ExecutorCompletionServiceTe /** * If poll returns non-null, the returned task is completed - */ - public void testPoll1() { + */ + public void testPoll1() throws InterruptedException { ExecutorService e = Executors.newCachedThreadPool(); ExecutorCompletionService ecs = new ExecutorCompletionService(e); try { @@ -132,8 +127,6 @@ public class ExecutorCompletionServiceTe break; } } - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -141,19 +134,17 @@ public class ExecutorCompletionServiceTe /** * If timed poll returns non-null, the returned task is completed - */ - public void testPoll2() { + */ + public void testPoll2() throws InterruptedException { 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) + Future f = ecs.poll(SHORT_DELAY_MS, MILLISECONDS); + if (f != null) assertTrue(f.isDone()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -162,7 +153,7 @@ public class ExecutorCompletionServiceTe * Submitting to underlying AES that overrides newTaskFor(Callable) * returns and eventually runs Future returned by newTaskFor. */ - public void testNewTaskForCallable() { + public void testNewTaskForCallable() throws InterruptedException { final AtomicBoolean done = new AtomicBoolean(false); class MyCallableFuture extends FutureTask { MyCallableFuture(Callable c) { super(c); } @@ -186,8 +177,6 @@ public class ExecutorCompletionServiceTe Future f2 = ecs.take(); assertSame("submit and take must return same objects", f1, f2); assertTrue("completed task must have set done", done.get()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -197,7 +186,7 @@ public class ExecutorCompletionServiceTe * Submitting to underlying AES that overrides newTaskFor(Runnable,T) * returns and eventually runs Future returned by newTaskFor. */ - public void testNewTaskForRunnable() { + public void testNewTaskForRunnable() throws InterruptedException { final AtomicBoolean done = new AtomicBoolean(false); class MyRunnableFuture extends FutureTask { MyRunnableFuture(Runnable t, V r) { super(t, r); } @@ -214,20 +203,16 @@ public class ExecutorCompletionServiceTe new ExecutorCompletionService(e); try { assertNull(ecs.poll()); - Callable c = new StringTask(); - Future f1 = ecs.submit(c); + Runnable r = new NoOpRunnable(); + Future f1 = ecs.submit(r, null); assertTrue("submit must return MyRunnableFuture", f1 instanceof MyRunnableFuture); Future f2 = ecs.take(); assertSame("submit and take must return same objects", f1, f2); assertTrue("completed task must have set done", done.get()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } } - - }