--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/21 20:13:20 1.14 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2010/10/09 22:27:16 1.20 @@ -192,7 +192,7 @@ public class ThreadPoolExecutorSubclassT /** - * execute successfully executes a runnable + * execute successfully executes a runnable */ public void testExecute() throws InterruptedException { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -205,8 +205,8 @@ public class ThreadPoolExecutorSubclassT } /** - * 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 { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -218,7 +218,7 @@ public class ThreadPoolExecutorSubclassT } /** - * prestartCoreThread starts a thread if under corePoolSize, else doesn't + * prestartCoreThread starts a thread if under corePoolSize, else doesn't */ public void testPrestartCoreThread() { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -233,7 +233,7 @@ public class ThreadPoolExecutorSubclassT } /** - * prestartAllCoreThreads starts all corePoolSize threads + * prestartAllCoreThreads starts all corePoolSize threads */ public void testPrestartAllCoreThreads() { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -246,8 +246,8 @@ public class ThreadPoolExecutorSubclassT } /** - * getCompletedTaskCount increases, but doesn't overestimate, - * when tasks complete + * getCompletedTaskCount increases, but doesn't overestimate, + * when tasks complete */ public void testGetCompletedTaskCount() throws InterruptedException { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -260,7 +260,7 @@ public class ThreadPoolExecutorSubclassT } /** - * getCorePoolSize returns size given in constructor if not otherwise set + * getCorePoolSize returns size given in constructor if not otherwise set */ public void testGetCorePoolSize() { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -269,7 +269,7 @@ public class ThreadPoolExecutorSubclassT } /** - * getKeepAliveTime returns value given in constructor if not otherwise set + * getKeepAliveTime returns value given in constructor if not otherwise set */ public void testGetKeepAliveTime() { ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -353,8 +353,8 @@ public class ThreadPoolExecutorSubclassT /** - * 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 { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -367,8 +367,8 @@ public class ThreadPoolExecutorSubclassT } /** - * getMaximumPoolSize returns value given in constructor if not - * otherwise set + * getMaximumPoolSize returns value given in constructor if not + * otherwise set */ public void testGetMaximumPoolSize() { ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -377,8 +377,8 @@ public class ThreadPoolExecutorSubclassT } /** - * getPoolSize increases, but doesn't overestimate, when threads - * become active + * getPoolSize increases, but doesn't overestimate, when threads + * become active */ public void testGetPoolSize() { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -389,7 +389,7 @@ public class ThreadPoolExecutorSubclassT } /** - * getTaskCount increases, but doesn't overestimate, when tasks submitted + * getTaskCount increases, but doesn't overestimate, when tasks submitted */ public void testGetTaskCount() throws InterruptedException { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -401,7 +401,7 @@ public class ThreadPoolExecutorSubclassT } /** - * isShutDown is false before shutdown, true after + * isShutDown is false before shutdown, true after */ public void testIsShutdown() { @@ -414,7 +414,7 @@ public class ThreadPoolExecutorSubclassT /** - * isTerminated is false before termination, true after + * isTerminated is false before termination, true after */ public void testIsTerminated() throws InterruptedException { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -429,7 +429,7 @@ public class ThreadPoolExecutorSubclassT } /** - * isTerminating is not true when running or when terminated + * isTerminating is not true when running or when terminated */ public void testIsTerminating() throws InterruptedException { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -498,7 +498,7 @@ public class ThreadPoolExecutorSubclassT } /** - * purge removes cancelled tasks from the queue + * purge removes cancelled tasks from the queue */ public void testPurge() { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -516,7 +516,7 @@ public class ThreadPoolExecutorSubclassT } /** - * shutDownNow returns a list containing tasks that were not run + * shutDownNow returns a list containing tasks that were not run */ public void testShutDownNow() { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); @@ -529,7 +529,6 @@ public class ThreadPoolExecutorSubclassT try { l = p1.shutdownNow(); } catch (SecurityException ok) { return; } - } assertTrue(p1.isShutdown()); assertTrue(l.size() <= 4); @@ -795,7 +794,7 @@ public class ThreadPoolExecutorSubclassT } /** - * Constructor throws if workQueue is set to null + * Constructor throws if workQueue is null */ public void testConstructorNullPointerException6() { try { @@ -805,7 +804,7 @@ public class ThreadPoolExecutorSubclassT } /** - * Constructor throws if handler is set to null + * Constructor throws if handler is null */ public void testConstructorNullPointerException7() { try { @@ -816,7 +815,7 @@ public class ThreadPoolExecutorSubclassT } /** - * Constructor throws if ThreadFactory is set top null + * Constructor throws if ThreadFactory is null */ public void testConstructorNullPointerException8() { try { @@ -828,8 +827,7 @@ public class ThreadPoolExecutorSubclassT /** - * execute throws RejectedExecutionException - * if saturated. + * execute throws RejectedExecutionException if saturated. */ public void testSaturatedExecute() { ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1)); @@ -844,7 +842,7 @@ public class ThreadPoolExecutorSubclassT } /** - * executor using CallerRunsPolicy runs task if saturated. + * executor using CallerRunsPolicy runs task if saturated. */ public void testSaturatedExecute2() { RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); @@ -870,7 +868,7 @@ public class ThreadPoolExecutorSubclassT } /** - * executor using DiscardPolicy drops task if saturated. + * executor using DiscardPolicy drops task if saturated. */ public void testSaturatedExecute3() { RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); @@ -895,7 +893,7 @@ public class ThreadPoolExecutorSubclassT } /** - * executor using DiscardOldestPolicy drops oldest task if saturated. + * executor using DiscardOldestPolicy drops oldest task if saturated. */ public void testSaturatedExecute4() { RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); @@ -916,7 +914,7 @@ public class ThreadPoolExecutorSubclassT } /** - * execute throws RejectedExecutionException if shutdown + * execute throws RejectedExecutionException if shutdown */ public void testRejectedExecutionExceptionOnShutdown() { ThreadPoolExecutor tpe = @@ -931,7 +929,7 @@ public class ThreadPoolExecutorSubclassT } /** - * execute using CallerRunsPolicy drops task on shutdown + * execute using CallerRunsPolicy drops task on shutdown */ public void testCallerRunsOnShutdown() { RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); @@ -948,7 +946,7 @@ public class ThreadPoolExecutorSubclassT } /** - * execute using DiscardPolicy drops task on shutdown + * execute using DiscardPolicy drops task on shutdown */ public void testDiscardOnShutdown() { RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); @@ -966,7 +964,7 @@ public class ThreadPoolExecutorSubclassT /** - * execute using DiscardOldestPolicy drops task on shutdown + * execute using DiscardOldestPolicy drops task on shutdown */ public void testDiscardOldestOnShutdown() { RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); @@ -984,7 +982,7 @@ public class ThreadPoolExecutorSubclassT /** - * execute (null) throws NPE + * execute(null) throws NPE */ public void testExecuteNull() { ThreadPoolExecutor tpe = null; @@ -998,7 +996,7 @@ public class ThreadPoolExecutorSubclassT } /** - * setCorePoolSize of negative value throws IllegalArgumentException + * setCorePoolSize of negative value throws IllegalArgumentException */ public void testCorePoolSizeIllegalArgumentException() { ThreadPoolExecutor tpe = @@ -1014,8 +1012,8 @@ public class ThreadPoolExecutorSubclassT } /** - * setMaximumPoolSize(int) throws IllegalArgumentException if - * given a value less the core pool size + * setMaximumPoolSize(int) throws IllegalArgumentException + * if given a value less the core pool size */ public void testMaximumPoolSizeIllegalArgumentException() { ThreadPoolExecutor tpe = @@ -1031,8 +1029,8 @@ public class ThreadPoolExecutorSubclassT } /** - * setMaximumPoolSize throws IllegalArgumentException - * if given a negative value + * setMaximumPoolSize throws IllegalArgumentException + * if given a negative value */ public void testMaximumPoolSizeIllegalArgumentException2() { ThreadPoolExecutor tpe = @@ -1049,8 +1047,8 @@ public class ThreadPoolExecutorSubclassT /** - * setKeepAliveTime throws IllegalArgumentException - * when given a negative value + * setKeepAliveTime throws IllegalArgumentException + * when given a negative value */ public void testKeepAliveTimeIllegalArgumentException() { ThreadPoolExecutor tpe = @@ -1169,18 +1167,12 @@ public class ThreadPoolExecutorSubclassT * 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 CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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 ok) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l); shouldThrow(); } catch (NullPointerException success) { @@ -1195,9 +1187,9 @@ public class ThreadPoolExecutorSubclassT */ public void testInvokeAny4() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + List> l = new ArrayList>(); + l.add(new NPETask()); try { - ArrayList> l = new ArrayList>(); - l.add(new NPETask()); e.invokeAny(l); shouldThrow(); } catch (ExecutionException success) { @@ -1213,7 +1205,7 @@ public class ThreadPoolExecutorSubclassT public void testInvokeAny5() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l); @@ -1255,10 +1247,10 @@ public class ThreadPoolExecutorSubclassT */ public void testInvokeAll3() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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) { @@ -1272,15 +1264,15 @@ public class ThreadPoolExecutorSubclassT */ public void testInvokeAll4() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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); } finally { joinPool(e); } @@ -1292,12 +1284,12 @@ public class ThreadPoolExecutorSubclassT public void testInvokeAll5() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1325,9 +1317,9 @@ public class ThreadPoolExecutorSubclassT */ public void testTimedInvokeAnyNullTimeUnit() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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) { @@ -1354,18 +1346,12 @@ public class ThreadPoolExecutorSubclassT * 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 CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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 ok) {} - return TEST_STRING; - }}); - l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) { @@ -1380,9 +1366,9 @@ public class ThreadPoolExecutorSubclassT */ public void testTimedInvokeAny4() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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) { @@ -1398,7 +1384,7 @@ public class ThreadPoolExecutorSubclassT public void testTimedInvokeAny5() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1427,9 +1413,9 @@ public class ThreadPoolExecutorSubclassT */ public void testTimedInvokeAllNullTimeUnit() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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) { @@ -1456,10 +1442,10 @@ public class ThreadPoolExecutorSubclassT */ public void testTimedInvokeAll3() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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) { @@ -1473,13 +1459,13 @@ public class ThreadPoolExecutorSubclassT */ public void testTimedInvokeAll4() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + 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); @@ -1494,12 +1480,13 @@ public class ThreadPoolExecutorSubclassT public void testTimedInvokeAll5() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1512,13 +1499,14 @@ public class ThreadPoolExecutorSubclassT public void testTimedInvokeAll6() throws Exception { ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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();