--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2009/11/16 04:57:10 1.25 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2009/11/20 16:02:10 1.29 @@ -7,6 +7,7 @@ */ import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.atomic.*; import junit.framework.*; import java.util.*; @@ -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); } @@ -49,38 +50,25 @@ public class ThreadPoolExecutorTest exte /** * 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(); - } - } - }); + p1.execute(new ShortRunnable()); Thread.sleep(SMALL_DELAY_MS); - } catch (InterruptedException e){ - unexpectedException(); + } finally { + joinPool(p1); } - joinPool(p1); } /** * 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); } @@ -89,7 +77,7 @@ public class ThreadPoolExecutorTest exte * 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()); @@ -104,7 +92,7 @@ public class ThreadPoolExecutorTest exte * 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()); @@ -117,15 +105,11 @@ public class ThreadPoolExecutorTest exte * 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); @@ -135,7 +119,7 @@ public class ThreadPoolExecutorTest exte * 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); } @@ -144,7 +128,7 @@ public class ThreadPoolExecutorTest exte * 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(); @@ -228,17 +212,13 @@ public class ThreadPoolExecutorTest exte * 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); } @@ -247,7 +227,7 @@ public class ThreadPoolExecutorTest exte * 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); } @@ -257,7 +237,7 @@ public class ThreadPoolExecutorTest exte * 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()); @@ -267,16 +247,12 @@ public class ThreadPoolExecutorTest exte /** * 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); } @@ -285,7 +261,7 @@ public class ThreadPoolExecutorTest exte */ 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()); @@ -296,27 +272,23 @@ public class ThreadPoolExecutorTest exte /** * 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 */ - 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,8 +348,6 @@ 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); } @@ -393,9 +357,9 @@ public class ThreadPoolExecutorTest exte * 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]); } @@ -411,7 +375,7 @@ public class ThreadPoolExecutorTest exte * 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++) @@ -435,10 +399,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 +409,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 +419,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 +429,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 +439,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 +449,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 +461,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 +471,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 +481,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 +491,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 +501,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 +511,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 +522,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 +533,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 +543,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 +553,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 +563,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 +573,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 +583,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 +594,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 +605,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 +615,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 +625,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 +635,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 +645,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 +655,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 +666,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,10 +677,9 @@ 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) {} } @@ -751,15 +688,22 @@ public class ThreadPoolExecutorTest exte * 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); + } } /** @@ -767,24 +711,22 @@ public class ThreadPoolExecutorTest exte */ 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); } @@ -795,23 +737,21 @@ public class ThreadPoolExecutorTest exte */ 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); } @@ -822,7 +762,7 @@ public class ThreadPoolExecutorTest exte */ 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,8 +773,6 @@ 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); } @@ -845,12 +783,12 @@ public class ThreadPoolExecutorTest exte */ 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){} + } catch (RejectedExecutionException success) {} joinPool(tpe); } @@ -860,15 +798,13 @@ public class ThreadPoolExecutorTest exte */ 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 { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } @@ -879,15 +815,13 @@ public class ThreadPoolExecutorTest exte */ 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 { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } @@ -899,15 +833,13 @@ public class ThreadPoolExecutorTest exte */ 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 { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch (RejectedExecutionException success){ - unexpectedException(); } finally { joinPool(p); } @@ -918,12 +850,11 @@ public class ThreadPoolExecutorTest exte * 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); shouldThrow(); - } catch (NullPointerException success){} + } catch (NullPointerException success) {} joinPool(tpe); } @@ -932,14 +863,14 @@ public class ThreadPoolExecutorTest exte * 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){} + ThreadPoolExecutor tpe = + new ThreadPoolExecutor(1, 2, + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); try { tpe.setCorePoolSize(-1); shouldThrow(); - } catch (IllegalArgumentException success){ + } catch (IllegalArgumentException success) { } finally { try { tpe.shutdown(); } catch (SecurityException ok) { return; } } @@ -951,14 +882,14 @@ public class ThreadPoolExecutorTest exte * 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; } } @@ -970,14 +901,14 @@ public class ThreadPoolExecutorTest exte * 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; } } @@ -990,15 +921,14 @@ public class ThreadPoolExecutorTest exte * when given a negative value */ public void testKeepAliveTimeIllegalArgumentException() { - 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.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 +948,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 +958,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 +966,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 +980,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 +994,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 +1023,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 +1037,24 @@ 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 { + final CountDownLatch latch = new CountDownLatch(1); + ExecutorService e = new ThreadPoolExecutor(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); } } @@ -1151,15 +1062,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)); 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 +1079,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>(); 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 +1095,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 +1109,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 +1122,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)); 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 +1139,22 @@ 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>(); 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(); + for (Future future : result) { + try { + future.get(); + shouldThrow(); + } catch (ExecutionException success) { + Throwable cause = success.getCause(); + assertTrue(cause instanceof NullPointerException); + } + } } finally { joinPool(e); } @@ -1255,19 +1163,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>(); 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); } @@ -1278,13 +1183,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 +1197,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)); 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 +1213,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,17 +1227,15 @@ 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 { + ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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 { joinPool(e); } @@ -1344,15 +1244,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)); 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 +1261,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>(); 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 +1277,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 +1291,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)); 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 +1307,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 +1320,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)); 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 +1337,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)); 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); } @@ -1465,19 +1357,16 @@ 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>(); 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(); } finally { joinPool(e); } @@ -1486,14 +1375,14 @@ 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>(); 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(); @@ -1504,8 +1393,6 @@ public class ThreadPoolExecutorTest exte assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch (Exception ex) { - unexpectedException(); } finally { joinPool(e); } @@ -1515,16 +1402,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>(); 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 +1419,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 +1427,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 +1442,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 +1458,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 +1481,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(); }