--- jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2009/12/01 06:47:14 1.9 +++ jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2010/10/09 19:30:35 1.14 @@ -12,7 +12,7 @@ import java.util.concurrent.atomic.*; public class ScheduledExecutorSubclassTest 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(ScheduledExecutorSubclassTest.class); @@ -74,12 +74,11 @@ public class ScheduledExecutorSubclassTe } - /** * execute successfully executes a runnable */ public void testExecute() throws InterruptedException { - TrackedShortRunnable runnable =new TrackedShortRunnable(); + TrackedShortRunnable runnable = new TrackedShortRunnable(); CustomExecutor p1 = new CustomExecutor(1); p1.execute(runnable); assertFalse(runnable.done); @@ -108,7 +107,7 @@ public class ScheduledExecutorSubclassTe } /** - * delayed schedule of runnable successfully executes after delay + * delayed schedule of runnable successfully executes after delay */ public void testSchedule3() throws InterruptedException { TrackedShortRunnable runnable = new TrackedShortRunnable(); @@ -191,7 +190,7 @@ public class ScheduledExecutorSubclassTe /** - * execute (null) throws NPE + * execute(null) throws NPE */ public void testExecuteNull() throws InterruptedException { CustomExecutor se = new CustomExecutor(1); @@ -203,7 +202,7 @@ public class ScheduledExecutorSubclassTe } /** - * schedule (null) throws NPE + * schedule(null) throws NPE */ public void testScheduleNull() throws InterruptedException { CustomExecutor se = new CustomExecutor(1); @@ -265,7 +264,7 @@ public class ScheduledExecutorSubclassTe } /** - * scheduleAtFixedRate throws RejectedExecutionException if shutdown + * scheduleAtFixedRate throws RejectedExecutionException if shutdown */ public void testScheduleAtFixedRate1_RejectedExecutionException() { CustomExecutor se = new CustomExecutor(1); @@ -297,8 +296,8 @@ public class ScheduledExecutorSubclassTe } /** - * getActiveCount increases but doesn't overestimate, when a - * thread becomes active + * getActiveCount increases but doesn't overestimate, when a + * thread becomes active */ public void testGetActiveCount() throws InterruptedException { CustomExecutor p2 = new CustomExecutor(2); @@ -310,8 +309,8 @@ public class ScheduledExecutorSubclassTe } /** - * getCompletedTaskCount increases, but doesn't overestimate, - * when tasks complete + * getCompletedTaskCount increases, but doesn't overestimate, + * when tasks complete */ public void testGetCompletedTaskCount() throws InterruptedException { CustomExecutor p2 = new CustomExecutor(2); @@ -323,7 +322,7 @@ public class ScheduledExecutorSubclassTe } /** - * getCorePoolSize returns size given in constructor if not otherwise set + * getCorePoolSize returns size given in constructor if not otherwise set */ public void testGetCorePoolSize() { CustomExecutor p1 = new CustomExecutor(1); @@ -332,8 +331,8 @@ public class ScheduledExecutorSubclassTe } /** - * getLargestPoolSize increases, but doesn't overestimate, when - * multiple threads active + * getLargestPoolSize increases, but doesn't overestimate, when + * multiple threads active */ public void testGetLargestPoolSize() throws InterruptedException { CustomExecutor p2 = new CustomExecutor(2); @@ -346,8 +345,8 @@ public class ScheduledExecutorSubclassTe } /** - * getPoolSize increases, but doesn't overestimate, when threads - * become active + * getPoolSize increases, but doesn't overestimate, when threads + * become active */ public void testGetPoolSize() { CustomExecutor p1 = new CustomExecutor(1); @@ -358,8 +357,8 @@ public class ScheduledExecutorSubclassTe } /** - * getTaskCount increases, but doesn't overestimate, when tasks - * submitted + * getTaskCount increases, but doesn't overestimate, when tasks + * submitted */ public void testGetTaskCount() throws InterruptedException { CustomExecutor p1 = new CustomExecutor(1); @@ -407,7 +406,7 @@ public class ScheduledExecutorSubclassTe } /** - * is isShutDown is false before shutdown, true after + * isShutDown is false before shutdown, true after */ public void testIsShutdown() { CustomExecutor p1 = new CustomExecutor(1); @@ -422,7 +421,7 @@ public class ScheduledExecutorSubclassTe /** - * isTerminated is false before termination, true after + * isTerminated is false before termination, true after */ public void testIsTerminated() throws InterruptedException { CustomExecutor p1 = new CustomExecutor(1); @@ -436,7 +435,7 @@ public class ScheduledExecutorSubclassTe } /** - * isTerminating is not true when running or when terminated + * isTerminating is not true when running or when terminated */ public void testIsTerminating() throws InterruptedException { CustomExecutor p1 = new CustomExecutor(1); @@ -498,7 +497,7 @@ public class ScheduledExecutorSubclassTe } /** - * purge removes cancelled tasks from the queue + * purge removes cancelled tasks from the queue */ public void testPurge() throws InterruptedException { CustomExecutor p1 = new CustomExecutor(1); @@ -527,7 +526,7 @@ public class ScheduledExecutorSubclassTe } /** - * shutDownNow returns a list containing tasks that were not run + * shutDownNow returns a list containing tasks that were not run */ public void testShutDownNow() { CustomExecutor p1 = new CustomExecutor(1); @@ -708,18 +707,12 @@ public class ScheduledExecutorSubclassTe * invokeAny(c) throws NPE if c has null elements */ public void testInvokeAny3() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(latchAwaitingStringTask(latch)); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new Callable() { - public String call() { - try { - latch.await(); - } catch (InterruptedException quittingTime) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l); shouldThrow(); } catch (NullPointerException success) { @@ -734,9 +727,9 @@ public class ScheduledExecutorSubclassTe */ public void testInvokeAny4() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); e.invokeAny(l); shouldThrow(); } catch (ExecutionException success) { @@ -752,7 +745,7 @@ public class ScheduledExecutorSubclassTe public void testInvokeAny5() throws Exception { ExecutorService e = new CustomExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l); @@ -794,10 +787,10 @@ public class ScheduledExecutorSubclassTe */ public void testInvokeAll3() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); - l.add(null); e.invokeAll(l); shouldThrow(); } catch (NullPointerException success) { @@ -811,13 +804,12 @@ public class ScheduledExecutorSubclassTe */ public void testInvokeAll4() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); + List> futures = e.invokeAll(l); + assertEquals(1, futures.size()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); - List> result = e.invokeAll(l); - assertEquals(1, result.size()); - for (Future future : result) - future.get(); + futures.get(0).get(); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); @@ -832,12 +824,12 @@ public class ScheduledExecutorSubclassTe public void testInvokeAll5() throws Exception { ExecutorService e = new CustomExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l); - assertEquals(2, result.size()); - for (Future future : result) + List> futures = e.invokeAll(l); + assertEquals(2, futures.size()); + for (Future future : futures) assertSame(TEST_STRING, future.get()); } finally { joinPool(e); @@ -863,9 +855,9 @@ public class ScheduledExecutorSubclassTe */ public void testTimedInvokeAnyNullTimeUnit() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) { @@ -892,18 +884,12 @@ public class ScheduledExecutorSubclassTe * timed invokeAny(c) throws NPE if c has null elements */ public void testTimedInvokeAny3() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(latchAwaitingStringTask(latch)); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new Callable() { - public String call() { - try { - latch.await(); - } catch (InterruptedException quittingTime) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) { @@ -918,9 +904,9 @@ public class ScheduledExecutorSubclassTe */ public void testTimedInvokeAny4() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { @@ -936,7 +922,7 @@ public class ScheduledExecutorSubclassTe public void testTimedInvokeAny5() throws Exception { ExecutorService e = new CustomExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); @@ -965,9 +951,9 @@ public class ScheduledExecutorSubclassTe */ public void testTimedInvokeAllNullTimeUnit() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) { @@ -994,10 +980,10 @@ public class ScheduledExecutorSubclassTe */ public void testTimedInvokeAll3() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new StringTask()); + l.add(null); try { - ArrayList> l = new ArrayList>(); - l.add(new StringTask()); - l.add(null); e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) { @@ -1011,13 +997,13 @@ public class ScheduledExecutorSubclassTe */ public void testTimedInvokeAll4() throws Exception { ExecutorService e = new CustomExecutor(2); + List> l = new ArrayList>(); + l.add(new NPETask()); + List> futures = + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + assertEquals(1, futures.size()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); - assertEquals(1, result.size()); - for (Future future : result) - future.get(); + futures.get(0).get(); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); @@ -1032,12 +1018,13 @@ public class ScheduledExecutorSubclassTe public void testTimedInvokeAll5() throws Exception { ExecutorService e = new CustomExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); - assertEquals(2, result.size()); - for (Future future : result) + List> futures = + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + assertEquals(2, futures.size()); + for (Future future : futures) assertSame(TEST_STRING, future.get()); } finally { joinPool(e); @@ -1050,13 +1037,14 @@ public class ScheduledExecutorSubclassTe public void testTimedInvokeAll6() throws Exception { ExecutorService e = new CustomExecutor(2); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); l.add(new StringTask()); - List> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); - assertEquals(3, result.size()); - Iterator> it = result.iterator(); + List> futures = + e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); + assertEquals(3, futures.size()); + Iterator> it = futures.iterator(); Future f1 = it.next(); Future f2 = it.next(); Future f3 = it.next();