--- jsr166/src/test/tck/ScheduledExecutorTest.java 2004/01/22 14:07:50 1.19 +++ jsr166/src/test/tck/ScheduledExecutorTest.java 2009/11/02 20:28:32 1.22 @@ -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 junit.framework.*; @@ -13,7 +13,7 @@ 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); @@ -43,7 +43,7 @@ public class ScheduledExecutorTest exten catch(Exception e){ unexpectedException(); } - + } @@ -86,7 +86,7 @@ public class ScheduledExecutorTest exten unexpectedException(); } } - + /** * scheduleAtFixedRate executes runnable after given initial delay */ @@ -127,7 +127,7 @@ public class ScheduledExecutorTest exten unexpectedException(); } } - + /** * scheduleAtFixedRate executes series of tasks at given rate */ @@ -135,7 +135,7 @@ public class ScheduledExecutorTest exten try { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); RunnableCounter counter = new RunnableCounter(); - ScheduledFuture h = + ScheduledFuture h = p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS); Thread.sleep(SMALL_DELAY_MS); h.cancel(true); @@ -144,7 +144,6 @@ public class ScheduledExecutorTest exten // 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); - assertTrue(h.isDone()); joinPool(p1); } catch(Exception e){ unexpectedException(); @@ -158,14 +157,13 @@ public class ScheduledExecutorTest exten try { ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); RunnableCounter counter = new RunnableCounter(); - ScheduledFuture h = + 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); - assertTrue(h.isDone()); joinPool(p1); } catch(Exception e){ unexpectedException(); @@ -186,7 +184,7 @@ public class ScheduledExecutorTest exten catch(Exception e){ unexpectedException(); } - + joinPool(se); } @@ -205,7 +203,7 @@ public class ScheduledExecutorTest exten } joinPool(se); } - + /** * execute throws RejectedExecutionException if shutdown */ @@ -219,7 +217,7 @@ public class ScheduledExecutorTest exten } catch(RejectedExecutionException success){ } catch (SecurityException ok) { } - + joinPool(se); } @@ -268,10 +266,10 @@ public class ScheduledExecutorTest exten shouldThrow(); } catch(RejectedExecutionException success){ } catch (SecurityException ok) { - } + } joinPool(se); } - + /** * scheduleWithFixedDelay throws RejectedExecutionException if shutdown */ @@ -284,7 +282,7 @@ public class ScheduledExecutorTest exten shouldThrow(); } catch(RejectedExecutionException success){ } catch (SecurityException ok) { - } + } joinPool(se); } @@ -304,7 +302,7 @@ public class ScheduledExecutorTest exten assertEquals(1, p2.getActiveCount()); joinPool(p2); } - + /** * getCompletedTaskCount increases, but doesn't overestimate, * when tasks complete @@ -321,16 +319,16 @@ public class ScheduledExecutorTest exten 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 @@ -348,7 +346,7 @@ public class ScheduledExecutorTest exten assertEquals(2, p2.getLargestPoolSize()); joinPool(p2); } - + /** * getPoolSize increases, but doesn't overestimate, when threads * become active @@ -360,7 +358,7 @@ public class ScheduledExecutorTest exten assertEquals(1, p1.getPoolSize()); joinPool(p1); } - + /** * getTaskCount increases, but doesn't overestimate, when tasks * submitted @@ -379,7 +377,7 @@ public class ScheduledExecutorTest exten joinPool(p1); } - /** + /** * getThreadFactory returns factory in constructor if not set */ public void testGetThreadFactory() { @@ -389,7 +387,7 @@ public class ScheduledExecutorTest exten joinPool(p); } - /** + /** * setThreadFactory sets the thread factory returned by getThreadFactory */ public void testSetThreadFactory() { @@ -400,7 +398,7 @@ public class ScheduledExecutorTest exten joinPool(p); } - /** + /** * setThreadFactory(null) throws NPE */ public void testSetThreadFactoryNull() { @@ -413,12 +411,12 @@ 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()); @@ -429,7 +427,7 @@ public class ScheduledExecutorTest exten assertTrue(p1.isShutdown()); } - + /** * isTerminated is false before termination, true after */ @@ -445,7 +443,7 @@ public class ScheduledExecutorTest exten assertTrue(p1.isTerminated()); } catch(Exception e){ unexpectedException(); - } + } } /** @@ -466,7 +464,7 @@ public class ScheduledExecutorTest exten assertFalse(p1.isTerminating()); } catch(Exception e){ unexpectedException(); - } + } } /** @@ -497,7 +495,7 @@ public class ScheduledExecutorTest exten ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); ScheduledFuture[] tasks = new ScheduledFuture[5]; for(int i = 0; i < 5; i++){ - tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); } try { Thread.sleep(SHORT_DELAY_MS); @@ -559,7 +557,7 @@ public class ScheduledExecutorTest exten List l; try { l = p1.shutdownNow(); - } catch (SecurityException ok) { + } catch (SecurityException ok) { return; } assertTrue(p1.isShutdown()); @@ -592,7 +590,7 @@ public class ScheduledExecutorTest exten assertTrue(tasks[i].isDone()); assertFalse(tasks[i].isCancelled()); } - + } catch(Exception ex) { unexpectedException(); @@ -671,7 +669,7 @@ public class ScheduledExecutorTest exten catch(Exception ex) { unexpectedException(); } - finally { + finally { joinPool(p1); } } @@ -878,7 +876,7 @@ 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) { @@ -899,7 +897,7 @@ 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) { @@ -1086,7 +1084,7 @@ 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) { @@ -1107,7 +1105,7 @@ 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) { @@ -1129,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();