--- jsr166/src/test/tck/ScheduledExecutorTest.java 2015/10/05 21:42:48 1.65 +++ jsr166/src/test/tck/ScheduledExecutorTest.java 2015/10/06 00:41:47 1.69 @@ -48,7 +48,7 @@ public class ScheduledExecutorTest exten final Runnable task = new CheckedRunnable() { public void realRun() { done.countDown(); }}; p.execute(task); - assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS)); + assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); } } @@ -317,7 +317,7 @@ public class ScheduledExecutorTest exten assertEquals(1, p.getActiveCount()); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getActiveCount()); done.countDown(); } @@ -382,7 +382,7 @@ public class ScheduledExecutorTest exten done.await(); assertEquals(THREADS, p.getLargestPoolSize()); }}); - assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(THREADS, p.getLargestPoolSize()); done.countDown(); } @@ -405,7 +405,7 @@ public class ScheduledExecutorTest exten assertEquals(1, p.getPoolSize()); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getPoolSize()); done.countDown(); } @@ -514,7 +514,7 @@ public class ScheduledExecutorTest exten threadStarted.countDown(); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -538,7 +538,7 @@ public class ScheduledExecutorTest exten threadStarted.countDown(); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -565,7 +565,7 @@ public class ScheduledExecutorTest exten }}; tasks[i] = p.schedule(r, 1, MILLISECONDS); } - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); BlockingQueue q = p.getQueue(); assertTrue(q.contains(tasks[tasks.length - 1])); assertFalse(q.contains(tasks[0])); @@ -590,7 +590,7 @@ public class ScheduledExecutorTest exten }}; tasks[i] = p.schedule(r, 1, MILLISECONDS); } - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); BlockingQueue q = p.getQueue(); assertFalse(p.remove((Runnable)tasks[0])); assertTrue(q.contains((Runnable)tasks[4])); @@ -609,12 +609,15 @@ public class ScheduledExecutorTest exten * purge eventually removes cancelled tasks from the queue */ public void testPurge() throws InterruptedException { - ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); - ScheduledFuture[] tasks = new ScheduledFuture[5]; - for (int i = 0; i < tasks.length; i++) - tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), - LONG_DELAY_MS, MILLISECONDS); - try { + final ScheduledFuture[] tasks = new ScheduledFuture[5]; + final Runnable releaser = new Runnable() { public void run() { + for (ScheduledFuture task : tasks) + if (task != null) task.cancel(true); }}; + final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); + try (PoolCleaner cleaner = cleaner(p, releaser)) { + for (int i = 0; i < tasks.length; i++) + tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), + LONG_DELAY_MS, MILLISECONDS); int max = tasks.length; if (tasks[4].cancel(true)) --max; if (tasks[3].cancel(true)) --max; @@ -626,12 +629,8 @@ public class ScheduledExecutorTest exten long count = p.getTaskCount(); if (count == max) return; - } while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS); + } while (millisElapsedSince(startTime) < LONG_DELAY_MS); fail("Purge failed to remove cancelled tasks"); - } finally { - for (ScheduledFuture task : tasks) - task.cancel(true); - joinPool(p); } } @@ -1142,7 +1141,7 @@ public class ScheduledExecutorTest exten List> l = new ArrayList>(); l.add(new NPETask()); List> futures = - e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); assertEquals(1, futures.size()); try { futures.get(0).get();