--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2009/11/16 04:57:10 1.25 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2010/10/09 19:30:35 1.35 @@ -7,13 +7,14 @@ */ import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.atomic.*; import junit.framework.*; import java.util.*; public class ThreadPoolExecutorTest 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(ThreadPoolExecutorTest.class); @@ -24,7 +25,7 @@ public class ThreadPoolExecutorTest exte volatile boolean afterCalled = false; volatile boolean terminatedCalled = false; public ExtendedTPE() { - super(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new SynchronousQueue()); + super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue()); } protected void beforeExecute(Thread t, Runnable r) { beforeCalled = true; @@ -37,9 +38,9 @@ public class ThreadPoolExecutorTest exte } } - static class FailingThreadFactory implements ThreadFactory{ + static class FailingThreadFactory implements ThreadFactory { int calls = 0; - public Thread newThread(Runnable r){ + public Thread newThread(Runnable r) { if (++calls > 1) return null; return new Thread(r); } @@ -47,49 +48,36 @@ public class ThreadPoolExecutorTest exte /** - * execute successfully executes a runnable + * execute successfully executes a runnable */ - public void testExecute() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testExecute() throws InterruptedException { + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - p1.execute(new Runnable() { - public void run() { - try { - Thread.sleep(SHORT_DELAY_MS); - } catch (InterruptedException e){ - threadUnexpectedException(); - } - } - }); - Thread.sleep(SMALL_DELAY_MS); - } catch (InterruptedException e){ - unexpectedException(); + p1.execute(new ShortRunnable()); + Thread.sleep(SMALL_DELAY_MS); + } finally { + joinPool(p1); } - joinPool(p1); } /** - * 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() { - ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testGetActiveCount() throws InterruptedException { + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getActiveCount()); p2.execute(new MediumRunnable()); - try { - Thread.sleep(SHORT_DELAY_MS); - } catch (Exception e){ - unexpectedException(); - } + Thread.sleep(SHORT_DELAY_MS); assertEquals(1, p2.getActiveCount()); joinPool(p2); } /** - * 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 ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getPoolSize()); assertTrue(p2.prestartCoreThread()); assertEquals(1, p2.getPoolSize()); @@ -101,10 +89,10 @@ public class ThreadPoolExecutorTest exte } /** - * prestartAllCoreThreads starts all corePoolSize threads + * prestartAllCoreThreads starts all corePoolSize threads */ public void testPrestartAllCoreThreads() { - ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getPoolSize()); p2.prestartAllCoreThreads(); assertEquals(2, p2.getPoolSize()); @@ -114,37 +102,33 @@ public class ThreadPoolExecutorTest exte } /** - * getCompletedTaskCount increases, but doesn't overestimate, - * when tasks complete + * getCompletedTaskCount increases, but doesn't overestimate, + * when tasks complete */ - public void testGetCompletedTaskCount() { - ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testGetCompletedTaskCount() throws InterruptedException { + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getCompletedTaskCount()); p2.execute(new ShortRunnable()); - try { - Thread.sleep(SMALL_DELAY_MS); - } catch (Exception e){ - unexpectedException(); - } + Thread.sleep(SMALL_DELAY_MS); assertEquals(1, p2.getCompletedTaskCount()); try { p2.shutdown(); } catch (SecurityException ok) { return; } joinPool(p2); } /** - * 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 ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(1, p1.getCorePoolSize()); joinPool(p1); } /** - * 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 ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS)); joinPool(p2); } @@ -155,7 +139,7 @@ public class ThreadPoolExecutorTest exte */ public void testGetThreadFactory() { ThreadFactory tf = new SimpleThreadFactory(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10), tf, new NoOpREHandler()); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10), tf, new NoOpREHandler()); assertSame(tf, p.getThreadFactory()); joinPool(p); } @@ -164,7 +148,7 @@ public class ThreadPoolExecutorTest exte * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); ThreadFactory tf = new SimpleThreadFactory(); p.setThreadFactory(tf); assertSame(tf, p.getThreadFactory()); @@ -176,7 +160,7 @@ public class ThreadPoolExecutorTest exte * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { p.setThreadFactory(null); shouldThrow(); @@ -191,7 +175,7 @@ public class ThreadPoolExecutorTest exte */ public void testGetRejectedExecutionHandler() { RejectedExecutionHandler h = new NoOpREHandler(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10), h); assertSame(h, p.getRejectedExecutionHandler()); joinPool(p); } @@ -201,7 +185,7 @@ public class ThreadPoolExecutorTest exte * getRejectedExecutionHandler */ public void testSetRejectedExecutionHandler() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); RejectedExecutionHandler h = new NoOpREHandler(); p.setRejectedExecutionHandler(h); assertSame(h, p.getRejectedExecutionHandler()); @@ -213,7 +197,7 @@ public class ThreadPoolExecutorTest exte * setRejectedExecutionHandler(null) throws NPE */ public void testSetRejectedExecutionHandlerNull() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { p.setRejectedExecutionHandler(null); shouldThrow(); @@ -225,39 +209,35 @@ public class ThreadPoolExecutorTest exte /** - * getLargestPoolSize increases, but doesn't overestimate, when - * multiple threads active + * getLargestPoolSize increases, but doesn't overestimate, when + * multiple threads active */ - public void testGetLargestPoolSize() { - ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); - try { - assertEquals(0, p2.getLargestPoolSize()); - p2.execute(new MediumRunnable()); - p2.execute(new MediumRunnable()); - Thread.sleep(SHORT_DELAY_MS); - assertEquals(2, p2.getLargestPoolSize()); - } catch (Exception e){ - unexpectedException(); - } + public void testGetLargestPoolSize() throws InterruptedException { + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + assertEquals(0, p2.getLargestPoolSize()); + p2.execute(new MediumRunnable()); + p2.execute(new MediumRunnable()); + Thread.sleep(SHORT_DELAY_MS); + assertEquals(2, p2.getLargestPoolSize()); joinPool(p2); } /** - * 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 ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(2, p2.getMaximumPoolSize()); joinPool(p2); } /** - * 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 ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p1.getPoolSize()); p1.execute(new MediumRunnable()); assertEquals(1, p1.getPoolSize()); @@ -265,58 +245,50 @@ public class ThreadPoolExecutorTest exte } /** - * getTaskCount increases, but doesn't overestimate, when tasks submitted + * getTaskCount increases, but doesn't overestimate, when tasks submitted */ - public void testGetTaskCount() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); - try { - assertEquals(0, p1.getTaskCount()); - p1.execute(new MediumRunnable()); - Thread.sleep(SHORT_DELAY_MS); - assertEquals(1, p1.getTaskCount()); - } catch (Exception e){ - unexpectedException(); - } + public void testGetTaskCount() throws InterruptedException { + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + assertEquals(0, p1.getTaskCount()); + p1.execute(new MediumRunnable()); + Thread.sleep(SHORT_DELAY_MS); + assertEquals(1, p1.getTaskCount()); joinPool(p1); } /** - * isShutDown is false before shutdown, true after + * isShutDown is false before shutdown, true after */ public void testIsShutdown() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(p1.isShutdown()); try { p1.shutdown(); } catch (SecurityException ok) { return; } - assertTrue(p1.isShutdown()); + assertTrue(p1.isShutdown()); joinPool(p1); } /** - * isTerminated is false before termination, true after + * isTerminated is false before termination, true after */ - public void testIsTerminated() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testIsTerminated() throws InterruptedException { + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(p1.isTerminated()); try { p1.execute(new MediumRunnable()); } finally { try { p1.shutdown(); } catch (SecurityException ok) { return; } } - try { - assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); - assertTrue(p1.isTerminated()); - } catch (Exception e){ - unexpectedException(); - } + assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(p1.isTerminated()); } /** - * isTerminating is not true when running or when terminated + * isTerminating is not true when running or when terminated */ - public void testIsTerminating() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testIsTerminating() throws InterruptedException { + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(p1.isTerminating()); try { p1.execute(new SmallRunnable()); @@ -324,23 +296,19 @@ public class ThreadPoolExecutorTest exte } finally { try { p1.shutdown(); } catch (SecurityException ok) { return; } } - try { - assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); - assertTrue(p1.isTerminated()); - assertFalse(p1.isTerminating()); - } catch (Exception e){ - unexpectedException(); - } + assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(p1.isTerminated()); + assertFalse(p1.isTerminating()); } /** * getQueue returns the work queue, which contains queued tasks */ - public void testGetQueue() { + public void testGetQueue() throws InterruptedException { BlockingQueue q = new ArrayBlockingQueue(10); - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q); FutureTask[] tasks = new FutureTask[5]; - for (int i = 0; i < 5; i++){ + for (int i = 0; i < 5; i++) { tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); p1.execute(tasks[i]); } @@ -353,8 +321,6 @@ public class ThreadPoolExecutorTest exte for (int i = 1; i < 5; ++i) tasks[i].cancel(true); p1.shutdownNow(); - } catch (Exception e) { - unexpectedException(); } finally { joinPool(p1); } @@ -363,11 +329,11 @@ public class ThreadPoolExecutorTest exte /** * remove(task) removes queued task, and fails to remove active task */ - public void testRemove() { + public void testRemove() throws InterruptedException { BlockingQueue q = new ArrayBlockingQueue(10); - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q); FutureTask[] tasks = new FutureTask[5]; - for (int i = 0; i < 5; i++){ + for (int i = 0; i < 5; i++) { tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); p1.execute(tasks[i]); } @@ -382,20 +348,18 @@ public class ThreadPoolExecutorTest exte assertTrue(q.contains(tasks[3])); assertTrue(p1.remove(tasks[3])); assertFalse(q.contains(tasks[3])); - } catch (Exception e) { - unexpectedException(); } finally { joinPool(p1); } } /** - * purge removes cancelled tasks from the queue + * purge removes cancelled tasks from the queue */ public void testPurge() { - ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); FutureTask[] tasks = new FutureTask[5]; - for (int i = 0; i < 5; i++){ + for (int i = 0; i < 5; i++) { tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE); p1.execute(tasks[i]); } @@ -408,10 +372,10 @@ public class ThreadPoolExecutorTest exte } /** - * 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 ThreadPoolExecutor(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); List l; try { for (int i = 0; i < 5; i++) @@ -421,10 +385,9 @@ public class ThreadPoolExecutorTest exte try { l = p1.shutdownNow(); } catch (SecurityException ok) { return; } - } - assertTrue(p1.isShutdown()); - assertTrue(l.size() <= 4); + assertTrue(p1.isShutdown()); + assertTrue(l.size() <= 4); } // Exception Tests @@ -435,10 +398,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor1() { try { - new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -446,10 +408,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor2() { try { - new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -457,10 +418,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor3() { try { - new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -468,10 +428,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor4() { try { - new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -479,10 +438,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor5() { try { - new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -490,10 +448,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructorNullPointerException() { try { - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -503,9 +460,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor6() { try { - new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -513,10 +470,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor7() { try { - new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -524,10 +480,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor8() { try { - new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -535,10 +490,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor9() { try { - new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -546,10 +500,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor10() { try { - new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -557,10 +510,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructorNullPointerException2() { try { - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -569,10 +521,9 @@ public class ThreadPoolExecutorTest exte public void testConstructorNullPointerException3() { try { ThreadFactory f = null; - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),f); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -581,10 +532,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor11() { try { - new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -592,10 +542,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor12() { try { - new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -603,10 +552,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor13() { try { - new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -614,10 +562,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor14() { try { - new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -625,10 +572,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor15() { try { - new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -636,10 +582,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructorNullPointerException4() { try { - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -648,10 +593,9 @@ public class ThreadPoolExecutorTest exte public void testConstructorNullPointerException5() { try { RejectedExecutionHandler r = null; - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),r); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),r); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -660,10 +604,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor16() { try { - new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -671,10 +614,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor17() { try { - new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -682,10 +624,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor18() { try { - new ThreadPoolExecutor(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -693,10 +634,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor19() { try { - new ThreadPoolExecutor(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -704,10 +644,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructor20() { try { - new ThreadPoolExecutor(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -715,10 +654,9 @@ public class ThreadPoolExecutorTest exte */ public void testConstructorNullPointerException6() { try { - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -727,10 +665,9 @@ public class ThreadPoolExecutorTest exte public void testConstructorNullPointerException7() { try { RejectedExecutionHandler r = null; - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),new SimpleThreadFactory(),r); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),new SimpleThreadFactory(),r); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -739,90 +676,91 @@ public class ThreadPoolExecutorTest exte public void testConstructorNullPointerException8() { try { ThreadFactory f = null; - new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f,new NoOpREHandler()); + new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),f,new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException successdn8){} + } catch (NullPointerException success) {} } /** - * execute throws RejectedExecutionException - * if saturated. + * execute throws RejectedExecutionException if saturated. */ public void testSaturatedExecute() { - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1)); + ThreadPoolExecutor p = + new ThreadPoolExecutor(1, 1, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(1)); try { - - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 2; ++i) p.execute(new MediumRunnable()); + for (int i = 0; i < 2; ++i) { + try { + p.execute(new MediumRunnable()); + shouldThrow(); + } catch (RejectedExecutionException success) {} } - shouldThrow(); - } catch (RejectedExecutionException success){} - joinPool(p); + } finally { + joinPool(p); + } } /** - * executor using CallerRunsPolicy runs task if saturated. + * executor using CallerRunsPolicy runs task if saturated. */ public void testSaturatedExecute2() { RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { tasks[i] = new TrackedNoOpRunnable(); } TrackedLongRunnable mr = new TrackedLongRunnable(); p.execute(mr); - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { p.execute(tasks[i]); } for (int i = 1; i < 5; ++i) { assertTrue(tasks[i].done); } try { p.shutdownNow(); } catch (SecurityException ok) { return; } - } catch (RejectedExecutionException ex){ - unexpectedException(); } finally { joinPool(p); } } /** - * executor using DiscardPolicy drops task if saturated. + * executor using DiscardPolicy drops task if saturated. */ public void testSaturatedExecute3() { RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { tasks[i] = new TrackedNoOpRunnable(); } p.execute(new TrackedLongRunnable()); - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { p.execute(tasks[i]); } - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { assertFalse(tasks[i].done); } try { p.shutdownNow(); } catch (SecurityException ok) { return; } - } catch (RejectedExecutionException ex){ - unexpectedException(); } finally { joinPool(p); } } /** - * executor using DiscardOldestPolicy drops oldest task if saturated. + * executor using DiscardOldestPolicy drops oldest task if saturated. */ public void testSaturatedExecute4() { RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { p.execute(new TrackedLongRunnable()); TrackedLongRunnable r2 = new TrackedLongRunnable(); @@ -833,61 +771,55 @@ public class ThreadPoolExecutorTest exte assertFalse(p.getQueue().contains(r2)); assertTrue(p.getQueue().contains(r3)); try { p.shutdownNow(); } catch (SecurityException ok) { return; } - } catch (RejectedExecutionException ex){ - unexpectedException(); } finally { joinPool(p); } } /** - * execute throws RejectedExecutionException if shutdown + * execute throws RejectedExecutionException if shutdown */ public void testRejectedExecutionExceptionOnShutdown() { ThreadPoolExecutor tpe = - new ThreadPoolExecutor(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(1)); + new ThreadPoolExecutor(1,1,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(1)); try { tpe.shutdown(); } catch (SecurityException ok) { return; } - try { - tpe.execute(new NoOpRunnable()); - shouldThrow(); - } catch (RejectedExecutionException success){} + try { + tpe.execute(new NoOpRunnable()); + shouldThrow(); + } catch (RejectedExecutionException success) {} - joinPool(tpe); + joinPool(tpe); } /** - * execute using CallerRunsPolicy drops task on shutdown + * execute using CallerRunsPolicy drops task on shutdown */ public void testCallerRunsOnShutdown() { RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { p.shutdown(); } catch (SecurityException ok) { return; } - try { + try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); - p.execute(r); + p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } } /** - * execute using DiscardPolicy drops task on shutdown + * execute using DiscardPolicy drops task on shutdown */ public void testDiscardOnShutdown() { RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { p.shutdown(); } catch (SecurityException ok) { return; } - try { + try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); - p.execute(r); + p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } @@ -895,19 +827,17 @@ public class ThreadPoolExecutorTest exte /** - * execute using DiscardOldestPolicy drops task on shutdown + * execute using DiscardOldestPolicy drops task on shutdown */ public void testDiscardOldestOnShutdown() { RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy(); - ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { p.shutdown(); } catch (SecurityException ok) { return; } - try { + try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); - p.execute(r); + p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } @@ -915,31 +845,30 @@ public class ThreadPoolExecutorTest exte /** - * execute (null) throws NPE + * execute(null) throws NPE */ public void testExecuteNull() { - ThreadPoolExecutor tpe = null; + ThreadPoolExecutor tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10)); try { - tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - tpe.execute(null); + tpe.execute(null); shouldThrow(); - } catch (NullPointerException success){} + } catch (NullPointerException success) {} - joinPool(tpe); + joinPool(tpe); } /** - * setCorePoolSize of negative value throws IllegalArgumentException + * setCorePoolSize of negative value throws IllegalArgumentException */ public void testCorePoolSizeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; - try { - tpe = new ThreadPoolExecutor(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} - try { - tpe.setCorePoolSize(-1); - shouldThrow(); - } catch (IllegalArgumentException success){ + ThreadPoolExecutor tpe = + new ThreadPoolExecutor(1, 2, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); + try { + tpe.setCorePoolSize(-1); + shouldThrow(); + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -947,18 +876,18 @@ public class ThreadPoolExecutorTest exte } /** - * 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 = null; - try { - tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} + ThreadPoolExecutor tpe = + new ThreadPoolExecutor(2, 3, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); try { tpe.setMaximumPoolSize(1); shouldThrow(); - } catch (IllegalArgumentException success){ + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -966,18 +895,18 @@ public class ThreadPoolExecutorTest exte } /** - * setMaximumPoolSize throws IllegalArgumentException - * if given a negative value + * setMaximumPoolSize throws IllegalArgumentException + * if given a negative value */ public void testMaximumPoolSizeIllegalArgumentException2() { - ThreadPoolExecutor tpe = null; - try { - tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} + ThreadPoolExecutor tpe = + new ThreadPoolExecutor(2, 3, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); try { tpe.setMaximumPoolSize(-1); shouldThrow(); - } catch (IllegalArgumentException success){ + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -986,19 +915,18 @@ public class ThreadPoolExecutorTest exte /** - * setKeepAliveTime throws IllegalArgumentException - * when given a negative value + * setKeepAliveTime throws IllegalArgumentException + * when given a negative value */ public void testKeepAliveTimeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; + ThreadPoolExecutor tpe = + new ThreadPoolExecutor(2, 3, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); try { - tpe = new ThreadPoolExecutor(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} - - try { - tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); + tpe.setKeepAliveTime(-1,MILLISECONDS); shouldThrow(); - } catch (IllegalArgumentException success){ + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -1018,7 +946,7 @@ public class ThreadPoolExecutorTest exte /** * beforeExecute and afterExecute are called when executing task */ - public void testBeforeAfter() { + public void testBeforeAfter() throws InterruptedException { ExtendedTPE tpe = new ExtendedTPE(); try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); @@ -1028,9 +956,6 @@ public class ThreadPoolExecutorTest exte assertTrue(tpe.beforeCalled); assertTrue(tpe.afterCalled); try { tpe.shutdown(); } catch (SecurityException ok) { return; } - } - catch (Exception ex) { - unexpectedException(); } finally { joinPool(tpe); } @@ -1039,18 +964,12 @@ public class ThreadPoolExecutorTest exte /** * completed submit of callable returns result */ - public void testSubmitCallable() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitCallable() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { Future future = e.submit(new StringTask()); String result = future.get(); assertSame(TEST_STRING, result); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1059,18 +978,12 @@ public class ThreadPoolExecutorTest exte /** * completed submit of runnable returns successfully */ - public void testSubmitRunnable() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitRunnable() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { Future future = e.submit(new NoOpRunnable()); future.get(); assertTrue(future.isDone()); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1079,37 +992,27 @@ public class ThreadPoolExecutorTest exte /** * completed submit of (runnable, result) returns result */ - public void testSubmitRunnable2() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitRunnable2() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { Future future = e.submit(new NoOpRunnable(), TEST_STRING); String result = future.get(); assertSame(TEST_STRING, result); - } - catch (ExecutionException ex) { - unexpectedException(); - } - catch (InterruptedException ex) { - unexpectedException(); } finally { joinPool(e); } } - - - /** * invokeAny(null) throws NPE */ - public void testInvokeAny1() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny1() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { e.invokeAny(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1118,13 +1021,12 @@ public class ThreadPoolExecutorTest exte /** * invokeAny(empty collection) throws IAE */ - public void testInvokeAny2() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny2() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { e.invokeAny(new ArrayList>()); + shouldThrow(); } catch (IllegalArgumentException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1133,17 +1035,18 @@ public class ThreadPoolExecutorTest exte /** * invokeAny(c) throws NPE if c has null elements */ - public void testInvokeAny3() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny3() throws Exception { + CountDownLatch latch = new CountDownLatch(1); + ExecutorService e = new ThreadPoolExecutor(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 StringTask()); - l.add(null); e.invokeAny(l); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -1151,15 +1054,15 @@ public class ThreadPoolExecutorTest exte /** * invokeAny(c) throws ExecutionException if no task completes */ - public void testInvokeAny4() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny4() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -1168,17 +1071,14 @@ public class ThreadPoolExecutorTest exte /** * invokeAny(c) returns result of some task */ - public void testInvokeAny5() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny5() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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); assertSame(TEST_STRING, result); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1187,13 +1087,12 @@ public class ThreadPoolExecutorTest exte /** * invokeAll(null) throws NPE */ - public void testInvokeAll1() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll1() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { e.invokeAll(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1202,13 +1101,11 @@ public class ThreadPoolExecutorTest exte /** * invokeAll(empty collection) returns empty collection */ - public void testInvokeAll2() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll2() throws InterruptedException { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { List> r = e.invokeAll(new ArrayList>()); assertTrue(r.isEmpty()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1217,16 +1114,15 @@ public class ThreadPoolExecutorTest exte /** * invokeAll(c) throws NPE if c has null elements */ - public void testInvokeAll3() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll3() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1235,18 +1131,19 @@ public class ThreadPoolExecutorTest exte /** * get of element of invokeAll(c) throws exception on failed task */ - public void testInvokeAll4() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll4() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); l.add(new NPETask()); - List> result = e.invokeAll(l); - assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + List> futures = e.invokeAll(l); + assertEquals(1, futures.size()); + try { + futures.get(0).get(); + shouldThrow(); + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof NullPointerException); + } } finally { joinPool(e); } @@ -1255,19 +1152,16 @@ public class ThreadPoolExecutorTest exte /** * invokeAll(c) returns results of all completed tasks */ - public void testInvokeAll5() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll5() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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 (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + List> futures = e.invokeAll(l); + assertEquals(2, futures.size()); + for (Future future : futures) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -1278,13 +1172,12 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(null) throws NPE */ - public void testTimedInvokeAny1() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny1() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1293,15 +1186,14 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(,,null) throws NPE */ - public void testTimedInvokeAnyNullTimeUnit() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAnyNullTimeUnit() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1310,13 +1202,12 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(empty collection) throws IAE */ - public void testTimedInvokeAny2() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny2() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (IllegalArgumentException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1325,18 +1216,18 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(c) throws NPE if c has null elements */ - public void testTimedInvokeAny3() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny3() throws Exception { + CountDownLatch latch = new CountDownLatch(1); + ExecutorService e = new ThreadPoolExecutor(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 StringTask()); - l.add(null); - e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - ex.printStackTrace(); - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -1344,15 +1235,15 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(c) throws ExecutionException if no task completes */ - public void testTimedInvokeAny4() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny4() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.MILLISECONDS); + e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -1361,17 +1252,14 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAny(c) returns result of some task */ - public void testTimedInvokeAny5() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny5() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.MILLISECONDS); + String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); assertSame(TEST_STRING, result); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1380,13 +1268,12 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(null) throws NPE */ - public void testTimedInvokeAll1() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll1() throws Exception { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1395,15 +1282,14 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(,,null) throws NPE */ - public void testTimedInvokeAllNullTimeUnit() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAllNullTimeUnit() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1412,13 +1298,11 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(empty collection) returns empty collection */ - public void testTimedInvokeAll2() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll2() throws InterruptedException { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { - List> r = e.invokeAll(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> r = e.invokeAll(new ArrayList>(), MEDIUM_DELAY_MS, MILLISECONDS); assertTrue(r.isEmpty()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1427,16 +1311,15 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(c) throws NPE if c has null elements */ - public void testTimedInvokeAll3() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll3() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.MILLISECONDS); + e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1445,18 +1328,18 @@ public class ThreadPoolExecutorTest exte /** * get of element of invokeAll(c) throws exception on failed task */ - public void testTimedInvokeAll4() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll4() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.MILLISECONDS); - assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); + futures.get(0).get(); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -1465,19 +1348,17 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(c) returns results of all completed tasks */ - public void testTimedInvokeAll5() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll5() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.MILLISECONDS); - assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - assertSame(TEST_STRING, it.next().get()); - } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + 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); } @@ -1486,16 +1367,17 @@ public class ThreadPoolExecutorTest exte /** * timed invokeAll(c) cancels tasks not completed by timeout */ - public void testTimedInvokeAll6() { - ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll6() throws Exception { + ExecutorService e = new ThreadPoolExecutor(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, TimeUnit.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(); @@ -1504,8 +1386,6 @@ public class ThreadPoolExecutorTest exte assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1515,16 +1395,14 @@ public class ThreadPoolExecutorTest exte * Execution continues if there is at least one thread even if * thread factory fails to create more */ - public void testFailingThreadFactory() { - ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); + public void testFailingThreadFactory() throws InterruptedException { + ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); try { - ArrayList> l = new ArrayList>(); + List> l = new ArrayList>(); for (int k = 0; k < 100; ++k) { e.execute(new NoOpRunnable()); } Thread.sleep(LONG_DELAY_MS); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1534,7 +1412,7 @@ public class ThreadPoolExecutorTest exte * allowsCoreThreadTimeOut is by default false. */ public void testAllowsCoreThreadTimeOut() { - ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(tpe.allowsCoreThreadTimeOut()); joinPool(tpe); } @@ -1542,15 +1420,13 @@ public class ThreadPoolExecutorTest exte /** * allowCoreThreadTimeOut(true) causes idle threads to time out */ - public void testAllowCoreThreadTimeOut_true() { - ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testAllowCoreThreadTimeOut_true() throws InterruptedException { + ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue(10)); tpe.allowCoreThreadTimeOut(true); tpe.execute(new NoOpRunnable()); try { Thread.sleep(MEDIUM_DELAY_MS); assertEquals(0, tpe.getPoolSize()); - } catch (InterruptedException e){ - unexpectedException(); } finally { joinPool(tpe); } @@ -1559,15 +1435,13 @@ public class ThreadPoolExecutorTest exte /** * allowCoreThreadTimeOut(false) causes idle threads not to time out */ - public void testAllowCoreThreadTimeOut_false() { - ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testAllowCoreThreadTimeOut_false() throws InterruptedException { + ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, MILLISECONDS, new ArrayBlockingQueue(10)); tpe.allowCoreThreadTimeOut(false); tpe.execute(new NoOpRunnable()); try { Thread.sleep(MEDIUM_DELAY_MS); assertTrue(tpe.getPoolSize() >= 1); - } catch (InterruptedException e){ - unexpectedException(); } finally { joinPool(tpe); } @@ -1577,7 +1451,7 @@ public class ThreadPoolExecutorTest exte * execute allows the same task to be submitted multiple times, even * if rejected */ - public void testRejectedRecycledTask() { + public void testRejectedRecycledTask() throws InterruptedException { final int nTasks = 1000; final AtomicInteger nRun = new AtomicInteger(0); final Runnable recycledTask = new Runnable() { @@ -1600,9 +1474,6 @@ public class ThreadPoolExecutorTest exte } Thread.sleep(5000); // enough time to run all tasks assertEquals(nRun.get(), nTasks); - } catch (Exception ex) { - ex.printStackTrace(); - unexpectedException(); } finally { p.shutdown(); }