--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2005/05/20 16:30:17 1.1 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2009/11/16 04:57:10 1.3 @@ -2,8 +2,8 @@ * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at * http://creativecommons.org/licenses/publicdomain - * Other contributors include Andrew Wright, Jeffrey Hayes, - * Pat Fisher, Mike Judd. + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import java.util.concurrent.*; @@ -14,7 +14,7 @@ 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); @@ -31,7 +31,7 @@ public class ThreadPoolExecutorSubclassT Exception exception; CustomTask(Callable c) { callable = c; } CustomTask(final Runnable r, final V res) { callable = new Callable() { - public V call() throws Exception { r.run(); return res; }}; + public V call() throws Exception { r.run(); return res; }}; } public boolean isDone() { lock.lock(); try { return done; } finally { lock.unlock() ; } @@ -45,7 +45,7 @@ public class ThreadPoolExecutorSubclassT if (!done) { cancelled = true; done = true; - if (mayInterrupt && thread != null) + if (mayInterrupt && thread != null) thread.interrupt(); return true; } @@ -68,7 +68,7 @@ public class ThreadPoolExecutorSubclassT try { v = callable.call(); } - catch(Exception ex) { + catch (Exception ex) { e = ex; } lock.lock(); @@ -84,7 +84,7 @@ public class ThreadPoolExecutorSubclassT public V get() throws InterruptedException, ExecutionException { lock.lock(); try { - while (!done) + while (!done) cond.await(); if (exception != null) throw new ExecutionException(exception); @@ -109,23 +109,23 @@ public class ThreadPoolExecutorSubclassT } finally { lock.unlock(); } } - } + } + - static class CustomTPE extends ThreadPoolExecutor { protected RunnableFuture newTaskFor(Callable c) { return new CustomTask(c); } protected RunnableFuture newTaskFor(Runnable r, V v) { return new CustomTask(r, v); - } - + } + CustomTPE(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } CustomTPE(int corePoolSize, @@ -154,7 +154,7 @@ public class ThreadPoolExecutorSubclassT BlockingQueue workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); } @@ -173,7 +173,7 @@ public class ThreadPoolExecutorSubclassT protected void terminated() { terminatedCalled = true; } - + } static class FailingThreadFactory implements ThreadFactory{ @@ -181,9 +181,9 @@ public class ThreadPoolExecutorSubclassT public Thread newThread(Runnable r){ if (++calls > 1) return null; return new Thread(r); - } + } } - + /** * execute successfully executes a runnable @@ -195,15 +195,15 @@ public class ThreadPoolExecutorSubclassT public void run() { try { Thread.sleep(SHORT_DELAY_MS); - } catch(InterruptedException e){ + } catch (InterruptedException e){ threadUnexpectedException(); } } }); Thread.sleep(SMALL_DELAY_MS); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); - } + } joinPool(p1); } @@ -217,7 +217,7 @@ public class ThreadPoolExecutorSubclassT p2.execute(new MediumRunnable()); try { Thread.sleep(SHORT_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(1, p2.getActiveCount()); @@ -251,7 +251,7 @@ public class ThreadPoolExecutorSubclassT assertEquals(2, p2.getPoolSize()); joinPool(p2); } - + /** * getCompletedTaskCount increases, but doesn't overestimate, * when tasks complete @@ -262,14 +262,14 @@ public class ThreadPoolExecutorSubclassT p2.execute(new ShortRunnable()); try { Thread.sleep(SMALL_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(1, p2.getCompletedTaskCount()); - try { p2.shutdown(); } catch(SecurityException ok) { return; } + try { p2.shutdown(); } catch (SecurityException ok) { return; } joinPool(p2); } - + /** * getCorePoolSize returns size given in constructor if not otherwise set */ @@ -278,7 +278,7 @@ public class ThreadPoolExecutorSubclassT assertEquals(1, p1.getCorePoolSize()); joinPool(p1); } - + /** * getKeepAliveTime returns value given in constructor if not otherwise set */ @@ -289,7 +289,7 @@ public class ThreadPoolExecutorSubclassT } - /** + /** * getThreadFactory returns factory in constructor if not set */ public void testGetThreadFactory() { @@ -299,7 +299,7 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** + /** * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() { @@ -311,7 +311,7 @@ public class ThreadPoolExecutorSubclassT } - /** + /** * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() { @@ -325,7 +325,7 @@ public class ThreadPoolExecutorSubclassT } } - /** + /** * getRejectedExecutionHandler returns handler in constructor if not set */ public void testGetRejectedExecutionHandler() { @@ -335,7 +335,7 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** + /** * setRejectedExecutionHandler sets the handler returned by * getRejectedExecutionHandler */ @@ -348,7 +348,7 @@ public class ThreadPoolExecutorSubclassT } - /** + /** * setRejectedExecutionHandler(null) throws NPE */ public void testSetRejectedExecutionHandlerNull() { @@ -362,7 +362,7 @@ public class ThreadPoolExecutorSubclassT } } - + /** * getLargestPoolSize increases, but doesn't overestimate, when * multiple threads active @@ -375,12 +375,12 @@ public class ThreadPoolExecutorSubclassT p2.execute(new MediumRunnable()); Thread.sleep(SHORT_DELAY_MS); assertEquals(2, p2.getLargestPoolSize()); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); - } + } joinPool(p2); } - + /** * getMaximumPoolSize returns value given in constructor if not * otherwise set @@ -390,7 +390,7 @@ public class ThreadPoolExecutorSubclassT assertEquals(2, p2.getMaximumPoolSize()); joinPool(p2); } - + /** * getPoolSize increases, but doesn't overestimate, when threads * become active @@ -402,7 +402,7 @@ public class ThreadPoolExecutorSubclassT assertEquals(1, p1.getPoolSize()); joinPool(p1); } - + /** * getTaskCount increases, but doesn't overestimate, when tasks submitted */ @@ -413,25 +413,25 @@ public class ThreadPoolExecutorSubclassT p1.execute(new MediumRunnable()); Thread.sleep(SHORT_DELAY_MS); assertEquals(1, p1.getTaskCount()); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); - } + } joinPool(p1); } - + /** * isShutDown is false before shutdown, true after */ public void testIsShutdown() { - + ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); assertFalse(p1.isShutdown()); - try { p1.shutdown(); } catch(SecurityException ok) { return; } + try { p1.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p1.isShutdown()); joinPool(p1); } - + /** * isTerminated is false before termination, true after */ @@ -441,14 +441,14 @@ public class ThreadPoolExecutorSubclassT try { p1.execute(new MediumRunnable()); } finally { - try { p1.shutdown(); } catch(SecurityException ok) { return; } + try { p1.shutdown(); } catch (SecurityException ok) { return; } } try { assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); assertTrue(p1.isTerminated()); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); - } + } } /** @@ -461,15 +461,15 @@ public class ThreadPoolExecutorSubclassT p1.execute(new SmallRunnable()); assertFalse(p1.isTerminating()); } finally { - try { p1.shutdown(); } catch(SecurityException ok) { return; } + 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){ + } catch (Exception e){ unexpectedException(); - } + } } /** @@ -479,7 +479,7 @@ public class ThreadPoolExecutorSubclassT BlockingQueue q = new ArrayBlockingQueue(10); ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.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,7 +492,7 @@ public class ThreadPoolExecutorSubclassT for (int i = 1; i < 5; ++i) tasks[i].cancel(true); p1.shutdownNow(); - } catch(Exception e) { + } catch (Exception e) { unexpectedException(); } finally { joinPool(p1); @@ -506,7 +506,7 @@ public class ThreadPoolExecutorSubclassT BlockingQueue q = new ArrayBlockingQueue(10); ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.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,7 +521,7 @@ public class ThreadPoolExecutorSubclassT assertTrue(q.contains(tasks[3])); assertTrue(p1.remove(tasks[3])); assertFalse(q.contains(tasks[3])); - } catch(Exception e) { + } catch (Exception e) { unexpectedException(); } finally { joinPool(p1); @@ -534,7 +534,7 @@ public class ThreadPoolExecutorSubclassT public void testPurge() { ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.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]); } @@ -553,24 +553,24 @@ public class ThreadPoolExecutorSubclassT ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(10)); List l; try { - for(int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) p1.execute(new MediumPossiblyInterruptedRunnable()); } finally { try { l = p1.shutdownNow(); } catch (SecurityException ok) { return; } - + } assertTrue(p1.isShutdown()); assertTrue(l.size() <= 4); } // Exception Tests - - /** - * Constructor throws if corePoolSize argument is less than zero + + /** + * Constructor throws if corePoolSize argument is less than zero */ public void testConstructor1() { try { @@ -579,9 +579,9 @@ public class ThreadPoolExecutorSubclassT } catch (IllegalArgumentException success){} } - - /** - * Constructor throws if maximumPoolSize is less than zero + + /** + * Constructor throws if maximumPoolSize is less than zero */ public void testConstructor2() { try { @@ -590,9 +590,9 @@ public class ThreadPoolExecutorSubclassT } catch (IllegalArgumentException success){} } - - /** - * Constructor throws if maximumPoolSize is equal to zero + + /** + * Constructor throws if maximumPoolSize is equal to zero */ public void testConstructor3() { try { @@ -602,8 +602,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if keepAliveTime is less than zero + /** + * Constructor throws if keepAliveTime is less than zero */ public void testConstructor4() { try { @@ -613,8 +613,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if corePoolSize is greater than the maximumPoolSize + /** + * Constructor throws if corePoolSize is greater than the maximumPoolSize */ public void testConstructor5() { try { @@ -623,22 +623,22 @@ public class ThreadPoolExecutorSubclassT } catch (IllegalArgumentException success){} } - - /** - * Constructor throws if workQueue is set to null + + /** + * Constructor throws if workQueue is set to null */ public void testConstructorNullPointerException() { try { new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - - - /** - * Constructor throws if corePoolSize argument is less than zero + + + /** + * Constructor throws if corePoolSize argument is less than zero */ public void testConstructor6() { try { @@ -646,9 +646,9 @@ public class ThreadPoolExecutorSubclassT shouldThrow(); } catch (IllegalArgumentException success){} } - - /** - * Constructor throws if maximumPoolSize is less than zero + + /** + * Constructor throws if maximumPoolSize is less than zero */ public void testConstructor7() { try { @@ -658,8 +658,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if maximumPoolSize is equal to zero + /** + * Constructor throws if maximumPoolSize is equal to zero */ public void testConstructor8() { try { @@ -669,8 +669,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if keepAliveTime is less than zero + /** + * Constructor throws if keepAliveTime is less than zero */ public void testConstructor9() { try { @@ -680,8 +680,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if corePoolSize is greater than the maximumPoolSize + /** + * Constructor throws if corePoolSize is greater than the maximumPoolSize */ public void testConstructor10() { try { @@ -691,19 +691,19 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if workQueue is set to null + /** + * Constructor throws if workQueue is set to null */ public void testConstructorNullPointerException2() { try { new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory()); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - /** - * Constructor throws if threadFactory is set to null + /** + * Constructor throws if threadFactory is set to null */ public void testConstructorNullPointerException3() { try { @@ -711,12 +711,12 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - - - /** - * Constructor throws if corePoolSize argument is less than zero + + + /** + * Constructor throws if corePoolSize argument is less than zero */ public void testConstructor11() { try { @@ -726,8 +726,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if maximumPoolSize is less than zero + /** + * Constructor throws if maximumPoolSize is less than zero */ public void testConstructor12() { try { @@ -737,8 +737,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if maximumPoolSize is equal to zero + /** + * Constructor throws if maximumPoolSize is equal to zero */ public void testConstructor13() { try { @@ -748,8 +748,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if keepAliveTime is less than zero + /** + * Constructor throws if keepAliveTime is less than zero */ public void testConstructor14() { try { @@ -759,8 +759,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if corePoolSize is greater than the maximumPoolSize + /** + * Constructor throws if corePoolSize is greater than the maximumPoolSize */ public void testConstructor15() { try { @@ -770,19 +770,19 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if workQueue is set to null + /** + * Constructor throws if workQueue is set to null */ public void testConstructorNullPointerException4() { try { new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler()); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - /** - * Constructor throws if handler is set to null + /** + * Constructor throws if handler is set to null */ public void testConstructorNullPointerException5() { try { @@ -790,12 +790,12 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),r); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - - /** - * Constructor throws if corePoolSize argument is less than zero + + /** + * Constructor throws if corePoolSize argument is less than zero */ public void testConstructor16() { try { @@ -805,8 +805,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if maximumPoolSize is less than zero + /** + * Constructor throws if maximumPoolSize is less than zero */ public void testConstructor17() { try { @@ -816,8 +816,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if maximumPoolSize is equal to zero + /** + * Constructor throws if maximumPoolSize is equal to zero */ public void testConstructor18() { try { @@ -827,8 +827,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if keepAliveTime is less than zero + /** + * Constructor throws if keepAliveTime is less than zero */ public void testConstructor19() { try { @@ -838,8 +838,8 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if corePoolSize is greater than the maximumPoolSize + /** + * Constructor throws if corePoolSize is greater than the maximumPoolSize */ public void testConstructor20() { try { @@ -849,19 +849,19 @@ public class ThreadPoolExecutorSubclassT catch (IllegalArgumentException success){} } - /** - * Constructor throws if workQueue is set to null + /** + * Constructor throws if workQueue is set to null */ public void testConstructorNullPointerException6() { try { new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - /** - * Constructor throws if handler is set to null + /** + * Constructor throws if handler is set to null */ public void testConstructorNullPointerException7() { try { @@ -869,11 +869,11 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),new SimpleThreadFactory(),r); shouldThrow(); } - catch (NullPointerException success){} + catch (NullPointerException success){} } - /** - * Constructor throws if ThreadFactory is set top null + /** + * Constructor throws if ThreadFactory is set top null */ public void testConstructorNullPointerException8() { try { @@ -881,9 +881,9 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10),f,new NoOpREHandler()); shouldThrow(); } - catch (NullPointerException successdn8){} + catch (NullPointerException successdn8){} } - + /** * execute throws RejectedExecutionException @@ -892,12 +892,12 @@ public class ThreadPoolExecutorSubclassT public void testSaturatedExecute() { ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.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); } @@ -908,21 +908,21 @@ public class ThreadPoolExecutorSubclassT RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.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) { + for (int i = 1; i < 5; ++i) { assertTrue(tasks[i].done); } - try { p.shutdownNow(); } catch(SecurityException ok) { return; } - } catch(RejectedExecutionException ex){ + try { p.shutdownNow(); } catch (SecurityException ok) { return; } + } catch (RejectedExecutionException ex){ unexpectedException(); } finally { joinPool(p); @@ -936,20 +936,20 @@ public class ThreadPoolExecutorSubclassT RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.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){ + try { p.shutdownNow(); } catch (SecurityException ok) { return; } + } catch (RejectedExecutionException ex){ unexpectedException(); } finally { joinPool(p); @@ -971,8 +971,8 @@ public class ThreadPoolExecutorSubclassT p.execute(r3); assertFalse(p.getQueue().contains(r2)); assertTrue(p.getQueue().contains(r3)); - try { p.shutdownNow(); } catch(SecurityException ok) { return; } - } catch(RejectedExecutionException ex){ + try { p.shutdownNow(); } catch (SecurityException ok) { return; } + } catch (RejectedExecutionException ex){ unexpectedException(); } finally { joinPool(p); @@ -983,14 +983,14 @@ public class ThreadPoolExecutorSubclassT * execute throws RejectedExecutionException if shutdown */ public void testRejectedExecutionExceptionOnShutdown() { - ThreadPoolExecutor tpe = + ThreadPoolExecutor tpe = new CustomTPE(1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(1)); - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } try { tpe.execute(new NoOpRunnable()); shouldThrow(); - } catch(RejectedExecutionException success){} - + } catch (RejectedExecutionException success){} + joinPool(tpe); } @@ -1001,12 +1001,12 @@ public class ThreadPoolExecutorSubclassT RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); - try { p.shutdown(); } catch(SecurityException ok) { return; } + try { p.shutdown(); } catch (SecurityException ok) { return; } try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch(RejectedExecutionException success){ + } catch (RejectedExecutionException success){ unexpectedException(); } finally { joinPool(p); @@ -1020,12 +1020,12 @@ public class ThreadPoolExecutorSubclassT RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); - try { p.shutdown(); } catch(SecurityException ok) { return; } + try { p.shutdown(); } catch (SecurityException ok) { return; } try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch(RejectedExecutionException success){ + } catch (RejectedExecutionException success){ unexpectedException(); } finally { joinPool(p); @@ -1040,12 +1040,12 @@ public class ThreadPoolExecutorSubclassT RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(1), h); - try { p.shutdown(); } catch(SecurityException ok) { return; } + try { p.shutdown(); } catch (SecurityException ok) { return; } try { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); - } catch(RejectedExecutionException success){ + } catch (RejectedExecutionException success){ unexpectedException(); } finally { joinPool(p); @@ -1062,11 +1062,11 @@ public class ThreadPoolExecutorSubclassT tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); tpe.execute(null); shouldThrow(); - } catch(NullPointerException success){} - + } catch (NullPointerException success){} + joinPool(tpe); } - + /** * setCorePoolSize of negative value throws IllegalArgumentException */ @@ -1074,36 +1074,36 @@ public class ThreadPoolExecutorSubclassT ThreadPoolExecutor tpe = null; try { tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch(Exception e){} + } catch (Exception e){} try { tpe.setCorePoolSize(-1); shouldThrow(); - } catch(IllegalArgumentException success){ + } catch (IllegalArgumentException success){ } finally { - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } } joinPool(tpe); - } + } /** * setMaximumPoolSize(int) throws IllegalArgumentException if * 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){} + } catch (Exception e){} try { tpe.setMaximumPoolSize(1); shouldThrow(); - } catch(IllegalArgumentException success){ + } catch (IllegalArgumentException success){ } finally { - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } } joinPool(tpe); } - + /** * setMaximumPoolSize throws IllegalArgumentException * if given a negative value @@ -1112,17 +1112,17 @@ public class ThreadPoolExecutorSubclassT ThreadPoolExecutor tpe = null; try { tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch(Exception e){} + } catch (Exception e){} try { tpe.setMaximumPoolSize(-1); shouldThrow(); - } catch(IllegalArgumentException success){ + } catch (IllegalArgumentException success){ } finally { - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } } joinPool(tpe); } - + /** * setKeepAliveTime throws IllegalArgumentException @@ -1132,14 +1132,14 @@ public class ThreadPoolExecutorSubclassT ThreadPoolExecutor tpe = null; try { tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue(10)); - } catch(Exception e){} - + } catch (Exception e){} + try { tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS); shouldThrow(); - } catch(IllegalArgumentException success){ + } catch (IllegalArgumentException success){ } finally { - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } } joinPool(tpe); } @@ -1149,7 +1149,7 @@ public class ThreadPoolExecutorSubclassT */ public void testTerminated() { CustomTPE tpe = new CustomTPE(); - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } assertTrue(tpe.terminatedCalled); joinPool(tpe); } @@ -1166,9 +1166,9 @@ public class ThreadPoolExecutorSubclassT assertTrue(r.done); assertTrue(tpe.beforeCalled); assertTrue(tpe.afterCalled); - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } } - catch(Exception ex) { + catch (Exception ex) { unexpectedException(); } finally { joinPool(tpe); @@ -1247,7 +1247,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAny(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1262,7 +1262,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAny(new ArrayList>()); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1280,7 +1280,7 @@ public class ThreadPoolExecutorSubclassT l.add(null); e.invokeAny(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1297,7 +1297,7 @@ public class ThreadPoolExecutorSubclassT l.add(new NPETask()); e.invokeAny(l); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1316,7 +1316,7 @@ public class ThreadPoolExecutorSubclassT String result = e.invokeAny(l); assertSame(TEST_STRING, result); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1331,7 +1331,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAll(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1346,7 +1346,7 @@ public class ThreadPoolExecutorSubclassT try { List> r = e.invokeAll(new ArrayList>()); assertTrue(r.isEmpty()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1364,7 +1364,7 @@ public class ThreadPoolExecutorSubclassT l.add(null); e.invokeAll(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1381,10 +1381,10 @@ public class ThreadPoolExecutorSubclassT l.add(new NPETask()); List> result = e.invokeAll(l); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) + for (Iterator> it = result.iterator(); it.hasNext();) it.next().get(); - } catch(ExecutionException success) { - } catch(Exception ex) { + } catch (ExecutionException success) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1402,10 +1402,10 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); List> result = e.invokeAll(l); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) + for (Iterator> it = result.iterator(); it.hasNext();) assertSame(TEST_STRING, it.next().get()); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1422,7 +1422,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1439,7 +1439,7 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1454,7 +1454,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1472,7 +1472,7 @@ public class ThreadPoolExecutorSubclassT l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); unexpectedException(); } finally { @@ -1489,8 +1489,8 @@ public class ThreadPoolExecutorSubclassT ArrayList> l = new ArrayList>(); l.add(new NPETask()); e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); - } catch(ExecutionException success) { - } catch(Exception ex) { + } catch (ExecutionException success) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1509,7 +1509,7 @@ public class ThreadPoolExecutorSubclassT String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertSame(TEST_STRING, result); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1524,7 +1524,7 @@ public class ThreadPoolExecutorSubclassT try { e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1541,7 +1541,7 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1556,7 +1556,7 @@ public class ThreadPoolExecutorSubclassT try { List> r = e.invokeAll(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertTrue(r.isEmpty()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1574,7 +1574,7 @@ public class ThreadPoolExecutorSubclassT l.add(null); e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1591,10 +1591,10 @@ public class ThreadPoolExecutorSubclassT l.add(new NPETask()); List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(1, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) + for (Iterator> it = result.iterator(); it.hasNext();) it.next().get(); - } catch(ExecutionException success) { - } catch(Exception ex) { + } catch (ExecutionException success) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1612,10 +1612,10 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); List> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(2, result.size()); - for (Iterator> it = result.iterator(); it.hasNext();) + for (Iterator> it = result.iterator(); it.hasNext();) assertSame(TEST_STRING, it.next().get()); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1634,7 +1634,7 @@ public class ThreadPoolExecutorSubclassT l.add(new StringTask()); List> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(3, result.size()); - Iterator> it = result.iterator(); + Iterator> it = result.iterator(); Future f1 = it.next(); Future f2 = it.next(); Future f3 = it.next(); @@ -1643,7 +1643,7 @@ public class ThreadPoolExecutorSubclassT assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1662,7 +1662,7 @@ public class ThreadPoolExecutorSubclassT e.execute(new NoOpRunnable()); } Thread.sleep(LONG_DELAY_MS); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1688,7 +1688,7 @@ public class ThreadPoolExecutorSubclassT try { Thread.sleep(MEDIUM_DELAY_MS); assertEquals(0, tpe.getPoolSize()); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); } finally { joinPool(tpe); @@ -1705,7 +1705,7 @@ public class ThreadPoolExecutorSubclassT try { Thread.sleep(MEDIUM_DELAY_MS); assertTrue(tpe.getPoolSize() >= 1); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); } finally { joinPool(tpe);