--- jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2015/09/27 20:17:39 1.38 +++ jsr166/src/test/tck/ScheduledExecutorSubclassTest.java 2015/09/28 02:41:29 1.40 @@ -710,6 +710,40 @@ public class ScheduledExecutorSubclassTe * shutdownNow returns a list containing tasks that were not run, * and those tasks are drained from the queue */ + public void testShutdownNow() throws InterruptedException { + final int poolSize = 2; + final int count = 5; + final AtomicInteger ran = new AtomicInteger(0); + final CustomExecutor p = new CustomExecutor(poolSize); + CountDownLatch threadsStarted = new CountDownLatch(poolSize); + CheckedRunnable waiter = new CheckedRunnable() { public void realRun() { + threadsStarted.countDown(); + try { + MILLISECONDS.sleep(2 * LONG_DELAY_MS); + } catch (InterruptedException success) {} + ran.getAndIncrement(); + }}; + for (int i = 0; i < count; i++) + p.execute(waiter); + assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); + final List queuedTasks; + try { + queuedTasks = p.shutdownNow(); + } catch (SecurityException ok) { + return; // Allowed in case test doesn't have privs + } + assertTrue(p.isShutdown()); + assertTrue(p.getQueue().isEmpty()); + assertEquals(count - poolSize, queuedTasks.size()); + assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(p.isTerminated()); + assertEquals(poolSize, ran.get()); + } + + /** + * shutdownNow returns a list containing tasks that were not run, + * and those tasks are drained from the queue + */ public void testShutdownNow_delayedTasks() throws InterruptedException { CustomExecutor p = new CustomExecutor(1); List tasks = new ArrayList<>(); @@ -719,7 +753,8 @@ public class ScheduledExecutorSubclassTe tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS)); tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS)); } - assertEquals(new HashSet(tasks), new HashSet(p.getQueue())); + if (testImplementationDetails) + assertEquals(new HashSet(tasks), new HashSet(p.getQueue())); final List queuedTasks; try { queuedTasks = p.shutdownNow(); @@ -728,7 +763,8 @@ public class ScheduledExecutorSubclassTe } assertTrue(p.isShutdown()); assertTrue(p.getQueue().isEmpty()); - assertEquals(new HashSet(tasks), new HashSet(queuedTasks)); + if (testImplementationDetails) + assertEquals(new HashSet(tasks), new HashSet(queuedTasks)); assertEquals(tasks.size(), queuedTasks.size()); for (ScheduledFuture task : tasks) { assertFalse(((CustomTask)task).ran);