--- jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2010/10/11 15:46:40 1.16 +++ jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2011/05/06 11:22:07 1.21 @@ -1,7 +1,7 @@ /* * 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 + * http://creativecommons.org/publicdomain/zero/1.0/ */ import junit.framework.*; @@ -203,7 +203,7 @@ public class ScheduledExecutorSubclassTe RunnableCounter counter = new RunnableCounter(); ScheduledFuture h = p.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS); - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); h.cancel(true); int c = counter.count.get(); // By time scaling conventions, we must have at least @@ -221,7 +221,7 @@ public class ScheduledExecutorSubclassTe RunnableCounter counter = new RunnableCounter(); ScheduledFuture h = p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS); - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); h.cancel(true); int c = counter.count.get(); assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS); @@ -291,17 +291,17 @@ public class ScheduledExecutorSubclassTe /** * schedule callable throws RejectedExecutionException if shutdown */ - public void testSchedule3_RejectedExecutionException() { - CustomExecutor se = new CustomExecutor(1); - try { - se.shutdown(); - se.schedule(new NoOpCallable(), - MEDIUM_DELAY_MS, MILLISECONDS); - shouldThrow(); - } catch (RejectedExecutionException success) { - } catch (SecurityException ok) { - } - joinPool(se); + public void testSchedule3_RejectedExecutionException() { + CustomExecutor se = new CustomExecutor(1); + try { + se.shutdown(); + se.schedule(new NoOpCallable(), + MEDIUM_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (RejectedExecutionException success) { + } catch (SecurityException ok) { + } + joinPool(se); } /** @@ -382,7 +382,7 @@ public class ScheduledExecutorSubclassTe assertEquals(0, p.getCompletedTaskCount()); threadProceed.countDown(); threadDone.await(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(1, p.getCompletedTaskCount()); } finally { joinPool(p); @@ -535,11 +535,12 @@ public class ScheduledExecutorSubclassTe try { p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadStarted.countDown(); assertFalse(p.isTerminated()); + threadStarted.countDown(); done.await(); }}); assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); + assertFalse(p.isTerminating()); done.countDown(); } finally { try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -559,8 +560,8 @@ public class ScheduledExecutorSubclassTe assertFalse(p.isTerminating()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadStarted.countDown(); assertFalse(p.isTerminating()); + threadStarted.countDown(); done.await(); }}); assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); @@ -656,7 +657,7 @@ public class ScheduledExecutorSubclassTe long count = p.getTaskCount(); if (count >= 0 && count <= max) break; - Thread.sleep(1); + delay(1); } assertTrue(k < SMALL_DELAY_MS); } finally {