--- jsr166/src/test/tck/ScheduledExecutorTest.java 2003/12/28 21:56:18 1.14 +++ jsr166/src/test/tck/ScheduledExecutorTest.java 2009/11/16 04:57:10 1.23 @@ -2,17 +2,18 @@ * 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 junit.framework.*; import java.util.*; import java.util.concurrent.*; +import java.util.concurrent.atomic.*; public class ScheduledExecutorTest 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(ScheduledExecutorTest.class); @@ -29,20 +30,20 @@ public class ScheduledExecutorTest exten p1.execute(runnable); assertFalse(runnable.done); Thread.sleep(SHORT_DELAY_MS); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } try { Thread.sleep(MEDIUM_DELAY_MS); - } catch(InterruptedException e){ + } catch (InterruptedException e){ unexpectedException(); } assertTrue(runnable.done); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } joinPool(p1); } - catch(Exception e){ + catch (Exception e){ unexpectedException(); } - + } @@ -58,10 +59,10 @@ public class ScheduledExecutorTest exten Thread.sleep(MEDIUM_DELAY_MS); assertTrue(callable.done); assertEquals(Boolean.TRUE, f.get()); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } joinPool(p1); - } catch(RejectedExecutionException e){} - catch(Exception e){ + } catch (RejectedExecutionException e){} + catch (Exception e){ e.printStackTrace(); unexpectedException(); } @@ -79,13 +80,13 @@ public class ScheduledExecutorTest exten assertFalse(runnable.done); Thread.sleep(MEDIUM_DELAY_MS); assertTrue(runnable.done); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } joinPool(p1); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } } - + /** * scheduleAtFixedRate executes runnable after given initial delay */ @@ -98,13 +99,17 @@ public class ScheduledExecutorTest exten Thread.sleep(MEDIUM_DELAY_MS); assertTrue(runnable.done); h.cancel(true); - p1.shutdown(); joinPool(p1); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } } + static class RunnableCounter implements Runnable { + AtomicInteger count = new AtomicInteger(0); + public void run() { count.getAndIncrement(); } + } + /** * scheduleWithFixedDelay executes runnable after given initial delay */ @@ -117,13 +122,55 @@ public class ScheduledExecutorTest exten Thread.sleep(MEDIUM_DELAY_MS); assertTrue(runnable.done); h.cancel(true); - p1.shutdown(); joinPool(p1); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } } - + + /** + * scheduleAtFixedRate executes series of tasks at given rate + */ + public void testFixedRateSequence() { + try { + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + RunnableCounter counter = new RunnableCounter(); + ScheduledFuture h = + p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS); + Thread.sleep(SMALL_DELAY_MS); + h.cancel(true); + int c = counter.count.get(); + // By time scaling conventions, we must have at least + // an execution per SHORT delay, but no more than one SHORT more + assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); + assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); + joinPool(p1); + } catch (Exception e){ + unexpectedException(); + } + } + + /** + * scheduleWithFixedDelay executes series of tasks with given period + */ + public void testFixedDelaySequence() { + try { + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); + RunnableCounter counter = new RunnableCounter(); + ScheduledFuture h = + p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS); + Thread.sleep(SMALL_DELAY_MS); + h.cancel(true); + int c = counter.count.get(); + assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); + assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS); + joinPool(p1); + } catch (Exception e){ + unexpectedException(); + } + } + + /** * execute (null) throws NPE */ @@ -133,11 +180,11 @@ public class ScheduledExecutorTest exten se = new ScheduledThreadPoolExecutor(1); se.execute(null); shouldThrow(); - } catch(NullPointerException success){} - catch(Exception e){ + } catch (NullPointerException success){} + catch (Exception e){ unexpectedException(); } - + joinPool(se); } @@ -150,13 +197,13 @@ public class ScheduledExecutorTest exten TrackedCallable callable = null; Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(NullPointerException success){} - catch(Exception e){ + } catch (NullPointerException success){} + catch (Exception e){ unexpectedException(); } joinPool(se); } - + /** * execute throws RejectedExecutionException if shutdown */ @@ -167,8 +214,10 @@ public class ScheduledExecutorTest exten se.schedule(new NoOpRunnable(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(RejectedExecutionException success){ + } catch (RejectedExecutionException success){ + } catch (SecurityException ok) { } + joinPool(se); } @@ -183,7 +232,8 @@ public class ScheduledExecutorTest exten se.schedule(new NoOpCallable(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(RejectedExecutionException success){ + } catch (RejectedExecutionException success){ + } catch (SecurityException ok) { } joinPool(se); } @@ -198,8 +248,9 @@ public class ScheduledExecutorTest exten se.schedule(new NoOpCallable(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(RejectedExecutionException success){ - } + } catch (RejectedExecutionException success){ + } catch (SecurityException ok) { + } joinPool(se); } @@ -213,11 +264,12 @@ public class ScheduledExecutorTest exten se.scheduleAtFixedRate(new NoOpRunnable(), MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(RejectedExecutionException success){ - } + } catch (RejectedExecutionException success){ + } catch (SecurityException ok) { + } joinPool(se); } - + /** * scheduleWithFixedDelay throws RejectedExecutionException if shutdown */ @@ -228,8 +280,9 @@ public class ScheduledExecutorTest exten se.scheduleWithFixedDelay(new NoOpRunnable(), MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); shouldThrow(); - } catch(RejectedExecutionException success){ - } + } catch (RejectedExecutionException success){ + } catch (SecurityException ok) { + } joinPool(se); } @@ -243,13 +296,13 @@ public class ScheduledExecutorTest exten p2.execute(new SmallRunnable()); try { Thread.sleep(SHORT_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(1, p2.getActiveCount()); joinPool(p2); } - + /** * getCompletedTaskCount increases, but doesn't overestimate, * when tasks complete @@ -260,22 +313,22 @@ public class ScheduledExecutorTest exten p2.execute(new SmallRunnable()); try { Thread.sleep(MEDIUM_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(1, p2.getCompletedTaskCount()); joinPool(p2); } - + /** - * getCorePoolSize returns size given in constructor if not otherwise set + * getCorePoolSize returns size given in constructor if not otherwise set */ public void testGetCorePoolSize() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); assertEquals(1, p1.getCorePoolSize()); joinPool(p1); } - + /** * getLargestPoolSize increases, but doesn't overestimate, when * multiple threads active @@ -287,13 +340,13 @@ public class ScheduledExecutorTest exten p2.execute(new SmallRunnable()); try { Thread.sleep(SHORT_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(2, p2.getLargestPoolSize()); joinPool(p2); } - + /** * getPoolSize increases, but doesn't overestimate, when threads * become active @@ -305,7 +358,7 @@ public class ScheduledExecutorTest exten assertEquals(1, p1.getPoolSize()); joinPool(p1); } - + /** * getTaskCount increases, but doesn't overestimate, when tasks * submitted @@ -313,29 +366,28 @@ public class ScheduledExecutorTest exten public void testGetTaskCount() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); assertEquals(0, p1.getTaskCount()); - for(int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) p1.execute(new SmallRunnable()); try { Thread.sleep(SHORT_DELAY_MS); - } catch(Exception e){ + } catch (Exception e){ unexpectedException(); } assertEquals(5, p1.getTaskCount()); joinPool(p1); } - /** + /** * getThreadFactory returns factory in constructor if not set */ public void testGetThreadFactory() { ThreadFactory tf = new SimpleThreadFactory(); ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf); assertSame(tf, p.getThreadFactory()); - p.shutdown(); joinPool(p); } - /** + /** * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() { @@ -343,11 +395,10 @@ public class ScheduledExecutorTest exten ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); p.setThreadFactory(tf); assertSame(tf, p.getThreadFactory()); - p.shutdown(); joinPool(p); } - /** + /** * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() { @@ -360,23 +411,23 @@ public class ScheduledExecutorTest exten joinPool(p); } } - + /** * is isShutDown is false before shutdown, true after */ public void testIsShutdown() { - + ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); try { assertFalse(p1.isShutdown()); } finally { - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } } assertTrue(p1.isShutdown()); } - + /** * isTerminated is false before termination, true after */ @@ -385,14 +436,14 @@ public class ScheduledExecutorTest exten try { p1.execute(new SmallRunnable()); } finally { - p1.shutdown(); + 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(); - } + } } /** @@ -405,15 +456,15 @@ public class ScheduledExecutorTest exten p1.execute(new SmallRunnable()); assertFalse(p1.isTerminating()); } finally { - p1.shutdown(); + 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(); - } + } } /** @@ -422,7 +473,7 @@ public class ScheduledExecutorTest exten public void testGetQueue() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); ScheduledFuture[] tasks = new ScheduledFuture[5]; - for(int i = 0; i < 5; i++){ + for (int i = 0; i < 5; i++){ tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); } try { @@ -430,8 +481,7 @@ public class ScheduledExecutorTest exten BlockingQueue q = p1.getQueue(); assertTrue(q.contains(tasks[4])); assertFalse(q.contains(tasks[0])); - p1.shutdownNow(); - } catch(Exception e) { + } catch (Exception e) { unexpectedException(); } finally { joinPool(p1); @@ -444,7 +494,7 @@ public class ScheduledExecutorTest exten public void testRemove() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); ScheduledFuture[] tasks = new ScheduledFuture[5]; - for(int i = 0; i < 5; i++){ + for (int i = 0; i < 5; i++){ tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); } try { @@ -459,8 +509,7 @@ public class ScheduledExecutorTest exten assertTrue(q.contains((Runnable)tasks[3])); assertTrue(p1.remove((Runnable)tasks[3])); assertFalse(q.contains((Runnable)tasks[3])); - p1.shutdownNow(); - } catch(Exception e) { + } catch (Exception e) { unexpectedException(); } finally { joinPool(p1); @@ -473,16 +522,29 @@ public class ScheduledExecutorTest exten public void testPurge() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); ScheduledFuture[] tasks = new ScheduledFuture[5]; - for(int i = 0; i < 5; i++){ - tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); + for (int i = 0; i < 5; i++){ + tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + } + try { + int max = 5; + if (tasks[4].cancel(true)) --max; + if (tasks[3].cancel(true)) --max; + // There must eventually be an interference-free point at + // which purge will not fail. (At worst, when queue is empty.) + int k; + for (k = 0; k < SMALL_DELAY_MS; ++k) { + p1.purge(); + long count = p1.getTaskCount(); + if (count >= 0 && count <= max) + break; + Thread.sleep(1); + } + assertTrue(k < SMALL_DELAY_MS); + } catch (Exception e) { + unexpectedException(); + } finally { + joinPool(p1); } - int max = 5; - if (tasks[4].cancel(true)) --max; - if (tasks[3].cancel(true)) --max; - p1.purge(); - long count = p1.getTaskCount(); - assertTrue(count > 0 && count <= max); - joinPool(p1); } /** @@ -490,9 +552,14 @@ public class ScheduledExecutorTest exten */ public void testShutDownNow() { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); - for(int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); - List l = p1.shutdownNow(); + List l; + try { + l = p1.shutdownNow(); + } catch (SecurityException ok) { + return; + } assertTrue(p1.isShutdown()); assertTrue(l.size() > 0 && l.size() <= 5); joinPool(p1); @@ -509,9 +576,9 @@ public class ScheduledExecutorTest exten assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy()); ScheduledFuture[] tasks = new ScheduledFuture[5]; - for(int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } BlockingQueue q = p1.getQueue(); for (Iterator it = q.iterator(); it.hasNext();) { ScheduledFuture t = (ScheduledFuture)it.next(); @@ -523,9 +590,9 @@ public class ScheduledExecutorTest exten assertTrue(tasks[i].isDone()); assertFalse(tasks[i].isCancelled()); } - + } - catch(Exception ex) { + catch (Exception ex) { unexpectedException(); } } @@ -540,16 +607,16 @@ public class ScheduledExecutorTest exten ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); ScheduledFuture[] tasks = new ScheduledFuture[5]; - for(int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p1.isShutdown()); BlockingQueue q = p1.getQueue(); assertTrue(q.isEmpty()); Thread.sleep(SMALL_DELAY_MS); assertTrue(p1.isTerminated()); } - catch(Exception ex) { + catch (Exception ex) { unexpectedException(); } } @@ -565,14 +632,14 @@ public class ScheduledExecutorTest exten p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); ScheduledFuture task = p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p1.isShutdown()); BlockingQueue q = p1.getQueue(); assertTrue(q.isEmpty()); Thread.sleep(SHORT_DELAY_MS); assertTrue(p1.isTerminated()); } - catch(Exception ex) { + catch (Exception ex) { unexpectedException(); } } @@ -586,24 +653,24 @@ public class ScheduledExecutorTest exten try { p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true); ScheduledFuture task = - p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS); + p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS); assertFalse(task.isCancelled()); - p1.shutdown(); + try { p1.shutdown(); } catch (SecurityException ok) { return; } assertFalse(task.isCancelled()); assertFalse(p1.isTerminated()); assertTrue(p1.isShutdown()); Thread.sleep(SHORT_DELAY_MS); assertFalse(task.isCancelled()); - task.cancel(true); - assertTrue(task.isCancelled()); + assertTrue(task.cancel(true)); + assertTrue(task.isDone()); Thread.sleep(SHORT_DELAY_MS); assertTrue(p1.isTerminated()); } - catch(Exception ex) { + catch (Exception ex) { unexpectedException(); } finally { - p1.shutdownNow(); + joinPool(p1); } } @@ -667,10 +734,6 @@ public class ScheduledExecutorTest exten } } - - - - /** * invokeAny(null) throws NPE */ @@ -679,7 +742,7 @@ public class ScheduledExecutorTest exten try { e.invokeAny(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -694,7 +757,7 @@ public class ScheduledExecutorTest exten try { e.invokeAny(new ArrayList>()); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -712,7 +775,7 @@ public class ScheduledExecutorTest exten l.add(null); e.invokeAny(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -729,7 +792,7 @@ public class ScheduledExecutorTest exten l.add(new NPETask()); e.invokeAny(l); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -748,7 +811,7 @@ public class ScheduledExecutorTest exten String result = e.invokeAny(l); assertSame(TEST_STRING, result); } catch (ExecutionException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -763,7 +826,7 @@ public class ScheduledExecutorTest exten try { e.invokeAll(null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -778,7 +841,7 @@ public class ScheduledExecutorTest exten try { List> r = e.invokeAll(new ArrayList>()); assertTrue(r.isEmpty()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -796,7 +859,7 @@ public class ScheduledExecutorTest exten l.add(null); e.invokeAll(l); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -813,10 +876,10 @@ public class ScheduledExecutorTest exten 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); @@ -834,10 +897,10 @@ public class ScheduledExecutorTest exten 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); @@ -852,7 +915,7 @@ public class ScheduledExecutorTest exten try { e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -869,7 +932,7 @@ public class ScheduledExecutorTest exten l.add(new StringTask()); e.invokeAny(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -884,7 +947,7 @@ public class ScheduledExecutorTest exten try { e.invokeAny(new ArrayList>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (IllegalArgumentException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -902,7 +965,7 @@ public class ScheduledExecutorTest exten l.add(null); e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); unexpectedException(); } finally { @@ -919,8 +982,8 @@ public class ScheduledExecutorTest exten 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); @@ -939,7 +1002,7 @@ public class ScheduledExecutorTest exten 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); @@ -954,7 +1017,7 @@ public class ScheduledExecutorTest exten try { e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -971,7 +1034,7 @@ public class ScheduledExecutorTest exten l.add(new StringTask()); e.invokeAll(l, MEDIUM_DELAY_MS, null); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -986,7 +1049,7 @@ public class ScheduledExecutorTest exten 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); @@ -1004,7 +1067,7 @@ public class ScheduledExecutorTest exten l.add(null); e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); } catch (NullPointerException success) { - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e); @@ -1021,10 +1084,10 @@ public class ScheduledExecutorTest exten 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); @@ -1042,10 +1105,10 @@ public class ScheduledExecutorTest exten 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); @@ -1064,7 +1127,7 @@ public class ScheduledExecutorTest exten 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(); @@ -1073,7 +1136,7 @@ public class ScheduledExecutorTest exten assertTrue(f3.isDone()); assertFalse(f1.isCancelled()); assertTrue(f2.isCancelled()); - } catch(Exception ex) { + } catch (Exception ex) { unexpectedException(); } finally { joinPool(e);