--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2009/11/02 20:28:32 1.24 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2009/11/16 04:57:10 1.25 @@ -56,13 +56,13 @@ public class ThreadPoolExecutorTest exte 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); @@ -78,7 +78,7 @@ public class ThreadPoolExecutorTest exte p2.execute(new MediumRunnable()); try { Thread.sleep(SHORT_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(1, p2.getActiveCount()); @@ -123,11 +123,11 @@ public class ThreadPoolExecutorTest exte 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); } @@ -236,7 +236,7 @@ public class ThreadPoolExecutorTest exte p2.execute(new MediumRunnable()); Thread.sleep(SHORT_DELAY_MS); assertEquals(2, p2.getLargestPoolSize()); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } joinPool(p2); @@ -274,7 +274,7 @@ public class ThreadPoolExecutorTest exte p1.execute(new MediumRunnable()); Thread.sleep(SHORT_DELAY_MS); assertEquals(1, p1.getTaskCount()); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } joinPool(p1); @@ -287,7 +287,7 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor p1 = new ThreadPoolExecutor(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); } @@ -302,12 +302,12 @@ public class ThreadPoolExecutorTest exte 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(); } } @@ -322,13 +322,13 @@ public class ThreadPoolExecutorTest exte 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(); } } @@ -340,7 +340,7 @@ public class ThreadPoolExecutorTest exte BlockingQueue q = new ArrayBlockingQueue(10); ThreadPoolExecutor p1 = new ThreadPoolExecutor(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]); } @@ -353,7 +353,7 @@ public class ThreadPoolExecutorTest exte for (int i = 1; i < 5; ++i) tasks[i].cancel(true); p1.shutdownNow(); - } catch(Exception e) { + } catch (Exception e) { unexpectedException(); } finally { joinPool(p1); @@ -367,7 +367,7 @@ public class ThreadPoolExecutorTest exte BlockingQueue q = new ArrayBlockingQueue(10); ThreadPoolExecutor p1 = new ThreadPoolExecutor(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]); } @@ -382,7 +382,7 @@ public class ThreadPoolExecutorTest exte 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); @@ -395,7 +395,7 @@ public class ThreadPoolExecutorTest exte public void testPurge() { ThreadPoolExecutor p1 = new ThreadPoolExecutor(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]); } @@ -414,7 +414,7 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor p1 = new ThreadPoolExecutor(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 { @@ -754,11 +754,11 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor p = new ThreadPoolExecutor(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); } @@ -771,19 +771,19 @@ public class ThreadPoolExecutorTest exte 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); @@ -799,18 +799,18 @@ public class ThreadPoolExecutorTest exte 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); @@ -832,8 +832,8 @@ public class ThreadPoolExecutorTest exte 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); @@ -846,11 +846,11 @@ public class ThreadPoolExecutorTest exte public void testRejectedExecutionExceptionOnShutdown() { ThreadPoolExecutor tpe = new ThreadPoolExecutor(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); } @@ -862,12 +862,12 @@ public class ThreadPoolExecutorTest exte RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); ThreadPoolExecutor p = new ThreadPoolExecutor(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); @@ -881,12 +881,12 @@ public class ThreadPoolExecutorTest exte RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); ThreadPoolExecutor p = new ThreadPoolExecutor(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); @@ -901,12 +901,12 @@ public class ThreadPoolExecutorTest exte RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy(); ThreadPoolExecutor p = new ThreadPoolExecutor(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); @@ -923,7 +923,7 @@ public class ThreadPoolExecutorTest exte 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); } @@ -935,13 +935,13 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor tpe = null; try { tpe = new ThreadPoolExecutor(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); } @@ -954,13 +954,13 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor tpe = null; try { tpe = new ThreadPoolExecutor(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); } @@ -973,13 +973,13 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor tpe = null; try { tpe = new ThreadPoolExecutor(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); } @@ -993,14 +993,14 @@ public class ThreadPoolExecutorTest exte ThreadPoolExecutor tpe = null; try { tpe = new ThreadPoolExecutor(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); } @@ -1010,7 +1010,7 @@ public class ThreadPoolExecutorTest exte */ public void testTerminated() { ExtendedTPE tpe = new ExtendedTPE(); - try { tpe.shutdown(); } catch(SecurityException ok) { return; } + try { tpe.shutdown(); } catch (SecurityException ok) { return; } assertTrue(tpe.terminatedCalled); joinPool(tpe); } @@ -1027,9 +1027,9 @@ public class ThreadPoolExecutorTest exte 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); @@ -1108,7 +1108,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAny(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1123,7 +1123,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAny(new ArrayList>()); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1141,7 +1141,7 @@ public class ThreadPoolExecutorTest exte l.add(null); e.invokeAny(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1158,7 +1158,7 @@ public class ThreadPoolExecutorTest exte l.add(new NPETask()); e.invokeAny(l); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1177,7 +1177,7 @@ public class ThreadPoolExecutorTest exte String result = e.invokeAny(l); assertSame(TEST_STRING, result); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1192,7 +1192,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAll(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1207,7 +1207,7 @@ public class ThreadPoolExecutorTest exte try { List> r = e.invokeAll(new ArrayList>()); assertTrue(r.isEmpty()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1225,7 +1225,7 @@ public class ThreadPoolExecutorTest exte l.add(null); e.invokeAll(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1244,8 +1244,8 @@ public class ThreadPoolExecutorTest exte assertEquals(1, result.size()); 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); @@ -1266,7 +1266,7 @@ public class ThreadPoolExecutorTest exte 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); @@ -1283,7 +1283,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1300,7 +1300,7 @@ public class ThreadPoolExecutorTest exte l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1315,7 +1315,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1333,7 +1333,7 @@ public class ThreadPoolExecutorTest exte l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); unexpectedException(); } finally { @@ -1350,8 +1350,8 @@ public class ThreadPoolExecutorTest exte 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); @@ -1370,7 +1370,7 @@ public class ThreadPoolExecutorTest exte 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); @@ -1385,7 +1385,7 @@ public class ThreadPoolExecutorTest exte try { e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1402,7 +1402,7 @@ public class ThreadPoolExecutorTest exte l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1417,7 +1417,7 @@ public class ThreadPoolExecutorTest exte 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); @@ -1435,7 +1435,7 @@ public class ThreadPoolExecutorTest exte l.add(null); e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1454,8 +1454,8 @@ public class ThreadPoolExecutorTest exte assertEquals(1, result.size()); 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); @@ -1476,7 +1476,7 @@ public class ThreadPoolExecutorTest exte 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); @@ -1504,7 +1504,7 @@ public class ThreadPoolExecutorTest exte assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1523,7 +1523,7 @@ public class ThreadPoolExecutorTest exte e.execute(new NoOpRunnable()); } Thread.sleep(LONG_DELAY_MS); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1549,7 +1549,7 @@ public class ThreadPoolExecutorTest exte try { Thread.sleep(MEDIUM_DELAY_MS); assertEquals(0, tpe.getPoolSize()); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); } finally { joinPool(tpe); @@ -1566,7 +1566,7 @@ public class ThreadPoolExecutorTest exte try { Thread.sleep(MEDIUM_DELAY_MS); assertTrue(tpe.getPoolSize() >= 1); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); } finally { joinPool(tpe); @@ -1600,7 +1600,7 @@ public class ThreadPoolExecutorTest exte } Thread.sleep(5000); // enough time to run all tasks assertEquals(nRun.get(), nTasks); - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); unexpectedException(); } finally {