--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/16 04:57:10 1.3 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/21 20:13:20 1.14 @@ -7,6 +7,7 @@ */ import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.locks.*; import junit.framework.*; @@ -14,10 +15,10 @@ import java.util.*; public class ThreadPoolExecutorSubclassTest 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); + return new TestSuite(ThreadPoolExecutorSubclassTest.class); } static class CustomTask implements RunnableFuture { @@ -29,8 +30,13 @@ public class ThreadPoolExecutorSubclassT V result; Thread thread; Exception exception; - CustomTask(Callable c) { callable = c; } - CustomTask(final Runnable r, final V res) { callable = new Callable() { + CustomTask(Callable c) { + if (c == null) throw new NullPointerException(); + callable = c; + } + CustomTask(final Runnable r, final V res) { + if (r == null) throw new NullPointerException(); + callable = new Callable() { public V call() throws Exception { r.run(); return res; }}; } public boolean isDone() { @@ -93,7 +99,7 @@ public class ThreadPoolExecutorSubclassT finally { lock.unlock(); } } public V get(long timeout, TimeUnit unit) - throws InterruptedException, ExecutionException, TimeoutException{ + throws InterruptedException, ExecutionException, TimeoutException { long nanos = unit.toNanos(timeout); lock.lock(); try { @@ -162,7 +168,7 @@ public class ThreadPoolExecutorSubclassT volatile boolean afterCalled = false; volatile boolean terminatedCalled = false; public CustomTPE() { - 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; @@ -176,9 +182,9 @@ public class ThreadPoolExecutorSubclassT } - 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); } @@ -188,38 +194,25 @@ public class ThreadPoolExecutorSubclassT /** * execute successfully executes a runnable */ - public void testExecute() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testExecute() throws InterruptedException { + ThreadPoolExecutor p1 = new CustomTPE(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 */ - public void testGetActiveCount() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testGetActiveCount() throws InterruptedException { + ThreadPoolExecutor p2 = new CustomTPE(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); } @@ -228,7 +221,7 @@ public class ThreadPoolExecutorSubclassT * prestartCoreThread starts a thread if under corePoolSize, else doesn't */ public void testPrestartCoreThread() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getPoolSize()); assertTrue(p2.prestartCoreThread()); assertEquals(1, p2.getPoolSize()); @@ -243,7 +236,7 @@ public class ThreadPoolExecutorSubclassT * prestartAllCoreThreads starts all corePoolSize threads */ public void testPrestartAllCoreThreads() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p2.getPoolSize()); p2.prestartAllCoreThreads(); assertEquals(2, p2.getPoolSize()); @@ -256,15 +249,11 @@ public class ThreadPoolExecutorSubclassT * getCompletedTaskCount increases, but doesn't overestimate, * when tasks complete */ - public void testGetCompletedTaskCount() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testGetCompletedTaskCount() throws InterruptedException { + ThreadPoolExecutor p2 = new CustomTPE(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); @@ -274,7 +263,7 @@ public class ThreadPoolExecutorSubclassT * getCorePoolSize returns size given in constructor if not otherwise set */ public void testGetCorePoolSize() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(1, p1.getCorePoolSize()); joinPool(p1); } @@ -283,7 +272,7 @@ public class ThreadPoolExecutorSubclassT * getKeepAliveTime returns value given in constructor if not otherwise set */ public void testGetKeepAliveTime() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(1, p2.getKeepAliveTime(TimeUnit.SECONDS)); joinPool(p2); } @@ -294,7 +283,7 @@ public class ThreadPoolExecutorSubclassT */ public void testGetThreadFactory() { ThreadFactory tf = new SimpleThreadFactory(); - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10), tf, new NoOpREHandler()); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10), tf, new NoOpREHandler()); assertSame(tf, p.getThreadFactory()); joinPool(p); } @@ -303,7 +292,7 @@ public class ThreadPoolExecutorSubclassT * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() { - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); ThreadFactory tf = new SimpleThreadFactory(); p.setThreadFactory(tf); assertSame(tf, p.getThreadFactory()); @@ -315,7 +304,7 @@ public class ThreadPoolExecutorSubclassT * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() { - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { p.setThreadFactory(null); shouldThrow(); @@ -330,7 +319,7 @@ public class ThreadPoolExecutorSubclassT */ public void testGetRejectedExecutionHandler() { RejectedExecutionHandler h = new NoOpREHandler(); - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10), h); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10), h); assertSame(h, p.getRejectedExecutionHandler()); joinPool(p); } @@ -340,7 +329,7 @@ public class ThreadPoolExecutorSubclassT * getRejectedExecutionHandler */ public void testSetRejectedExecutionHandler() { - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); RejectedExecutionHandler h = new NoOpREHandler(); p.setRejectedExecutionHandler(h); assertSame(h, p.getRejectedExecutionHandler()); @@ -352,7 +341,7 @@ public class ThreadPoolExecutorSubclassT * setRejectedExecutionHandler(null) throws NPE */ public void testSetRejectedExecutionHandlerNull() { - ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { p.setRejectedExecutionHandler(null); shouldThrow(); @@ -367,17 +356,13 @@ public class ThreadPoolExecutorSubclassT * getLargestPoolSize increases, but doesn't overestimate, when * multiple threads active */ - public void testGetLargestPoolSize() { - ThreadPoolExecutor p2 = new CustomTPE(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 CustomTPE(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); } @@ -386,7 +371,7 @@ public class ThreadPoolExecutorSubclassT * otherwise set */ public void testGetMaximumPoolSize() { - ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(2, p2.getMaximumPoolSize()); joinPool(p2); } @@ -396,7 +381,7 @@ public class ThreadPoolExecutorSubclassT * become active */ public void testGetPoolSize() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertEquals(0, p1.getPoolSize()); p1.execute(new MediumRunnable()); assertEquals(1, p1.getPoolSize()); @@ -406,16 +391,12 @@ public class ThreadPoolExecutorSubclassT /** * getTaskCount increases, but doesn't overestimate, when tasks submitted */ - public void testGetTaskCount() { - ThreadPoolExecutor p1 = new CustomTPE(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 CustomTPE(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); } @@ -424,10 +405,10 @@ public class ThreadPoolExecutorSubclassT */ public void testIsShutdown() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new CustomTPE(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); } @@ -435,27 +416,23 @@ public class ThreadPoolExecutorSubclassT /** * isTerminated is false before termination, true after */ - public void testIsTerminated() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testIsTerminated() throws InterruptedException { + ThreadPoolExecutor p1 = new CustomTPE(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 */ - public void testIsTerminating() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testIsTerminating() throws InterruptedException { + ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(p1.isTerminating()); try { p1.execute(new SmallRunnable()); @@ -463,23 +440,19 @@ public class ThreadPoolExecutorSubclassT } 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 CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); + ThreadPoolExecutor p1 = new CustomTPE(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]); } @@ -492,8 +465,6 @@ public class ThreadPoolExecutorSubclassT for (int i = 1; i < 5; ++i) tasks[i].cancel(true); p1.shutdownNow(); - } catch (Exception e) { - unexpectedException(); } finally { joinPool(p1); } @@ -502,11 +473,11 @@ public class ThreadPoolExecutorSubclassT /** * 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 CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q); + ThreadPoolExecutor p1 = new CustomTPE(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]); } @@ -521,8 +492,6 @@ public class ThreadPoolExecutorSubclassT assertTrue(q.contains(tasks[3])); assertTrue(p1.remove(tasks[3])); assertFalse(q.contains(tasks[3])); - } catch (Exception e) { - unexpectedException(); } finally { joinPool(p1); } @@ -532,9 +501,9 @@ public class ThreadPoolExecutorSubclassT * purge removes cancelled tasks from the queue */ public void testPurge() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new CustomTPE(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]); } @@ -550,7 +519,7 @@ public class ThreadPoolExecutorSubclassT * shutDownNow returns a list containing tasks that were not run */ public void testShutDownNow() { - ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); List l; try { for (int i = 0; i < 5; i++) @@ -562,8 +531,8 @@ public class ThreadPoolExecutorSubclassT } catch (SecurityException ok) { return; } } - assertTrue(p1.isShutdown()); - assertTrue(l.size() <= 4); + assertTrue(p1.isShutdown()); + assertTrue(l.size() <= 4); } // Exception Tests @@ -574,10 +543,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor1() { try { - new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -585,10 +553,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor2() { try { - new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -596,10 +563,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor3() { try { - new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -607,10 +573,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor4() { try { - new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -618,10 +583,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor5() { try { - new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -629,10 +593,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructorNullPointerException() { try { - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -642,9 +605,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor6() { try { - new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -652,10 +615,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor7() { try { - new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -663,10 +625,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor8() { try { - new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -674,10 +635,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor9() { try { - new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -685,10 +645,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor10() { try { - new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); + new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -696,10 +655,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructorNullPointerException2() { try { - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -708,10 +666,9 @@ public class ThreadPoolExecutorSubclassT public void testConstructorNullPointerException3() { try { ThreadFactory f = null; - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),f); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -720,10 +677,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor11() { try { - new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -731,10 +687,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor12() { try { - new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -742,10 +697,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor13() { try { - new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -753,10 +707,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor14() { try { - new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -764,10 +717,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor15() { try { - new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); + new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -775,10 +727,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructorNullPointerException4() { try { - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -787,10 +738,9 @@ public class ThreadPoolExecutorSubclassT public void testConstructorNullPointerException5() { try { RejectedExecutionHandler r = null; - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),r); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),r); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } @@ -799,10 +749,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor16() { try { - new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -810,10 +759,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor17() { try { - new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -821,10 +769,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor18() { try { - new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -832,10 +779,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor19() { try { - new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -843,10 +789,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructor20() { try { - new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10),new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (IllegalArgumentException success){} + } catch (IllegalArgumentException success) {} } /** @@ -854,10 +799,9 @@ public class ThreadPoolExecutorSubclassT */ public void testConstructorNullPointerException6() { try { - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -866,10 +810,9 @@ public class ThreadPoolExecutorSubclassT public void testConstructorNullPointerException7() { try { RejectedExecutionHandler r = null; - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),new SimpleThreadFactory(),r); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),new SimpleThreadFactory(),r); shouldThrow(); - } - catch (NullPointerException success){} + } catch (NullPointerException success) {} } /** @@ -878,10 +821,9 @@ public class ThreadPoolExecutorSubclassT public void testConstructorNullPointerException8() { try { ThreadFactory f = null; - new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f,new NoOpREHandler()); + new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10),f,new NoOpREHandler()); shouldThrow(); - } - catch (NullPointerException successdn8){} + } catch (NullPointerException success) {} } @@ -890,14 +832,14 @@ public class ThreadPoolExecutorSubclassT * if saturated. */ public void testSaturatedExecute() { - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1)); + ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1)); try { - for (int i = 0; i < 5; ++i){ + for (int i = 0; i < 5; ++i) { p.execute(new MediumRunnable()); } shouldThrow(); - } catch (RejectedExecutionException success){} + } catch (RejectedExecutionException success) {} joinPool(p); } @@ -906,24 +848,22 @@ public class ThreadPoolExecutorSubclassT */ public void testSaturatedExecute2() { RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(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); } @@ -934,23 +874,21 @@ public class ThreadPoolExecutorSubclassT */ public void testSaturatedExecute3() { RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(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); } @@ -961,7 +899,7 @@ public class ThreadPoolExecutorSubclassT */ public void testSaturatedExecute4() { RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), h); try { p.execute(new TrackedLongRunnable()); TrackedLongRunnable r2 = new TrackedLongRunnable(); @@ -972,8 +910,6 @@ public class ThreadPoolExecutorSubclassT assertFalse(p.getQueue().contains(r2)); assertTrue(p.getQueue().contains(r3)); try { p.shutdownNow(); } catch (SecurityException ok) { return; } - } catch (RejectedExecutionException ex){ - unexpectedException(); } finally { joinPool(p); } @@ -984,14 +920,14 @@ public class ThreadPoolExecutorSubclassT */ public void testRejectedExecutionExceptionOnShutdown() { ThreadPoolExecutor tpe = - new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(1)); + new CustomTPE(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); } /** @@ -999,15 +935,13 @@ public class ThreadPoolExecutorSubclassT */ public void testCallerRunsOnShutdown() { RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(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); } @@ -1018,15 +952,13 @@ public class ThreadPoolExecutorSubclassT */ public void testDiscardOnShutdown() { RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(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); } @@ -1038,15 +970,13 @@ public class ThreadPoolExecutorSubclassT */ public void testDiscardOldestOnShutdown() { RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); - ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); + ThreadPoolExecutor p = new CustomTPE(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); } @@ -1059,26 +989,24 @@ public class ThreadPoolExecutorSubclassT public void testExecuteNull() { ThreadPoolExecutor tpe = null; try { - tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - tpe.execute(null); + tpe = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10)); + tpe.execute(null); shouldThrow(); - } catch (NullPointerException success){} + } catch (NullPointerException success) {} - joinPool(tpe); + joinPool(tpe); } /** * setCorePoolSize of negative value throws IllegalArgumentException */ public void testCorePoolSizeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; - try { - tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} - try { - tpe.setCorePoolSize(-1); - shouldThrow(); - } catch (IllegalArgumentException success){ + ThreadPoolExecutor tpe = + new CustomTPE(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; } } @@ -1090,14 +1018,12 @@ public class ThreadPoolExecutorSubclassT * given a value less the core pool size */ public void testMaximumPoolSizeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; - try { - tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} + ThreadPoolExecutor tpe = + new CustomTPE(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; } } @@ -1109,14 +1035,12 @@ public class ThreadPoolExecutorSubclassT * if given a negative value */ public void testMaximumPoolSizeIllegalArgumentException2() { - ThreadPoolExecutor tpe = null; - try { - tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} + ThreadPoolExecutor tpe = + new CustomTPE(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; } } @@ -1129,15 +1053,13 @@ public class ThreadPoolExecutorSubclassT * when given a negative value */ public void testKeepAliveTimeIllegalArgumentException() { - ThreadPoolExecutor tpe = null; - try { - tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch (Exception e){} + ThreadPoolExecutor tpe = + new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue(10)); - try { - tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); + try { + tpe.setKeepAliveTime(-1,MILLISECONDS); shouldThrow(); - } catch (IllegalArgumentException success){ + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -1157,7 +1079,7 @@ public class ThreadPoolExecutorSubclassT /** * beforeExecute and afterExecute are called when executing task */ - public void testBeforeAfter() { + public void testBeforeAfter() throws InterruptedException { CustomTPE tpe = new CustomTPE(); try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); @@ -1167,9 +1089,6 @@ public class ThreadPoolExecutorSubclassT assertTrue(tpe.beforeCalled); assertTrue(tpe.afterCalled); try { tpe.shutdown(); } catch (SecurityException ok) { return; } - } - catch (Exception ex) { - unexpectedException(); } finally { joinPool(tpe); } @@ -1178,18 +1097,12 @@ public class ThreadPoolExecutorSubclassT /** * completed submit of callable returns result */ - public void testSubmitCallable() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitCallable() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1198,18 +1111,12 @@ public class ThreadPoolExecutorSubclassT /** * completed submit of runnable returns successfully */ - public void testSubmitRunnable() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitRunnable() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1218,37 +1125,27 @@ public class ThreadPoolExecutorSubclassT /** * completed submit of (runnable, result) returns result */ - public void testSubmitRunnable2() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testSubmitRunnable2() throws Exception { + ExecutorService e = new CustomTPE(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 CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny1() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { e.invokeAny(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1257,13 +1154,12 @@ public class ThreadPoolExecutorSubclassT /** * invokeAny(empty collection) throws IAE */ - public void testInvokeAny2() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny2() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1272,17 +1168,24 @@ public class ThreadPoolExecutorSubclassT /** * invokeAny(c) throws NPE if c has null elements */ - public void testInvokeAny3() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny3() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> l = new ArrayList>(); - l.add(new StringTask()); + 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) { - } catch (Exception ex) { - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -1290,15 +1193,15 @@ public class ThreadPoolExecutorSubclassT /** * invokeAny(c) throws ExecutionException if no task completes */ - public void testInvokeAny4() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny4() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1307,17 +1210,14 @@ public class ThreadPoolExecutorSubclassT /** * invokeAny(c) returns result of some task */ - public void testInvokeAny5() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAny5() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> 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); } @@ -1326,13 +1226,12 @@ public class ThreadPoolExecutorSubclassT /** * invokeAll(null) throws NPE */ - public void testInvokeAll1() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll1() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { e.invokeAll(null); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1341,13 +1240,11 @@ public class ThreadPoolExecutorSubclassT /** * invokeAll(empty collection) returns empty collection */ - public void testInvokeAll2() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll2() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1356,16 +1253,15 @@ public class ThreadPoolExecutorSubclassT /** * invokeAll(c) throws NPE if c has null elements */ - public void testInvokeAll3() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll3() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1374,18 +1270,17 @@ public class ThreadPoolExecutorSubclassT /** * get of element of invokeAll(c) throws exception on failed task */ - public void testInvokeAll4() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll4() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> 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(); + for (Future future : result) + future.get(); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1394,19 +1289,16 @@ public class ThreadPoolExecutorSubclassT /** * invokeAll(c) returns results of all completed tasks */ - public void testInvokeAll5() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testInvokeAll5() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> 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(); + for (Future future : result) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -1417,13 +1309,12 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(null) throws NPE */ - public void testTimedInvokeAny1() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny1() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1432,15 +1323,14 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(,,null) throws NPE */ - public void testTimedInvokeAnyNullTimeUnit() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAnyNullTimeUnit() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1449,13 +1339,12 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(empty collection) throws IAE */ - public void testTimedInvokeAny2() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny2() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1464,18 +1353,24 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(c) throws NPE if c has null elements */ - public void testTimedInvokeAny3() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny3() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> l = new ArrayList>(); - l.add(new StringTask()); + 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, TimeUnit.MILLISECONDS); + e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); } catch (NullPointerException success) { - } catch (Exception ex) { - ex.printStackTrace(); - unexpectedException(); } finally { + latch.countDown(); joinPool(e); } } @@ -1483,15 +1378,15 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(c) throws ExecutionException if no task completes */ - public void testTimedInvokeAny4() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny4() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1500,17 +1395,14 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAny(c) returns result of some task */ - public void testTimedInvokeAny5() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAny5() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> 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); } @@ -1519,13 +1411,12 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(null) throws NPE */ - public void testTimedInvokeAll1() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll1() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1534,15 +1425,14 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(,,null) throws NPE */ - public void testTimedInvokeAllNullTimeUnit() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAllNullTimeUnit() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1551,13 +1441,11 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(empty collection) returns empty collection */ - public void testTimedInvokeAll2() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll2() throws Exception { + ExecutorService e = new CustomTPE(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); } @@ -1566,16 +1454,15 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(c) throws NPE if c has null elements */ - public void testTimedInvokeAll3() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll3() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); } @@ -1584,18 +1471,18 @@ public class ThreadPoolExecutorSubclassT /** * get of element of invokeAll(c) throws exception on failed task */ - public void testTimedInvokeAll4() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll4() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> l = new ArrayList>(); l.add(new NPETask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) - it.next().get(); + for (Future future : result) + future.get(); + shouldThrow(); } catch (ExecutionException success) { - } catch (Exception ex) { - unexpectedException(); + assertTrue(success.getCause() instanceof NullPointerException); } finally { joinPool(e); } @@ -1604,19 +1491,16 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(c) returns results of all completed tasks */ - public void testTimedInvokeAll5() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll5() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> l = new ArrayList>(); l.add(new StringTask()); l.add(new StringTask()); - List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); + List> result = e.invokeAll(l, MEDIUM_DELAY_MS, 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(); + for (Future future : result) + assertSame(TEST_STRING, future.get()); } finally { joinPool(e); } @@ -1625,14 +1509,14 @@ public class ThreadPoolExecutorSubclassT /** * timed invokeAll(c) cancels tasks not completed by timeout */ - public void testTimedInvokeAll6() { - ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testTimedInvokeAll6() throws Exception { + ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try { ArrayList> 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); + List> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); assertEquals(3, result.size()); Iterator> it = result.iterator(); Future f1 = it.next(); @@ -1643,8 +1527,6 @@ public class ThreadPoolExecutorSubclassT assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1654,16 +1536,13 @@ public class ThreadPoolExecutorSubclassT * Execution continues if there is at least one thread even if * thread factory fails to create more */ - public void testFailingThreadFactory() { - ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); + public void testFailingThreadFactory() throws InterruptedException { + ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue(), new FailingThreadFactory()); try { - ArrayList> 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); } @@ -1673,7 +1552,7 @@ public class ThreadPoolExecutorSubclassT * allowsCoreThreadTimeOut is by default false. */ public void testAllowsCoreThreadTimeOut() { - ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + ThreadPoolExecutor tpe = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(tpe.allowsCoreThreadTimeOut()); joinPool(tpe); } @@ -1681,15 +1560,13 @@ public class ThreadPoolExecutorSubclassT /** * allowCoreThreadTimeOut(true) causes idle threads to time out */ - public void testAllowCoreThreadTimeOut_true() { - ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testAllowCoreThreadTimeOut_true() throws InterruptedException { + ThreadPoolExecutor tpe = new CustomTPE(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); } @@ -1698,15 +1575,13 @@ public class ThreadPoolExecutorSubclassT /** * allowCoreThreadTimeOut(false) causes idle threads not to time out */ - public void testAllowCoreThreadTimeOut_false() { - ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); + public void testAllowCoreThreadTimeOut_false() throws InterruptedException { + ThreadPoolExecutor tpe = new CustomTPE(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); }