ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.54 by jsr166, Sun Sep 27 20:17:39 2015 UTC vs.
Revision 1.56 by jsr166, Mon Sep 28 02:41:29 2015 UTC

# Line 656 | Line 656 | public class ScheduledExecutorTest exten
656       * shutdownNow returns a list containing tasks that were not run,
657       * and those tasks are drained from the queue
658       */
659 +    public void testShutdownNow() throws InterruptedException {
660 +        final int poolSize = 2;
661 +        final int count = 5;
662 +        final AtomicInteger ran = new AtomicInteger(0);
663 +        final ScheduledThreadPoolExecutor p =
664 +            new ScheduledThreadPoolExecutor(poolSize);
665 +        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
666 +        CheckedRunnable waiter = new CheckedRunnable() { public void realRun() {
667 +            threadsStarted.countDown();
668 +            try {
669 +                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
670 +            } catch (InterruptedException success) {}
671 +            ran.getAndIncrement();
672 +        }};
673 +        for (int i = 0; i < count; i++)
674 +            p.execute(waiter);
675 +        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
676 +        final List<Runnable> queuedTasks;
677 +        try {
678 +            queuedTasks = p.shutdownNow();
679 +        } catch (SecurityException ok) {
680 +            return; // Allowed in case test doesn't have privs
681 +        }
682 +        assertTrue(p.isShutdown());
683 +        assertTrue(p.getQueue().isEmpty());
684 +        assertEquals(count - poolSize, queuedTasks.size());
685 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
686 +        assertTrue(p.isTerminated());
687 +        assertEquals(poolSize, ran.get());
688 +    }
689 +
690 +    /**
691 +     * shutdownNow returns a list containing tasks that were not run,
692 +     * and those tasks are drained from the queue
693 +     */
694      public void testShutdownNow_delayedTasks() throws InterruptedException {
695          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
696          List<ScheduledFuture> tasks = new ArrayList<>();
# Line 665 | Line 700 | public class ScheduledExecutorTest exten
700              tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS));
701              tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS));
702          }
703 <        assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
703 >        if (testImplementationDetails)
704 >            assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
705          final List<Runnable> queuedTasks;
706          try {
707              queuedTasks = p.shutdownNow();
# Line 674 | Line 710 | public class ScheduledExecutorTest exten
710          }
711          assertTrue(p.isShutdown());
712          assertTrue(p.getQueue().isEmpty());
713 <        assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
713 >        if (testImplementationDetails)
714 >            assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
715          assertEquals(tasks.size(), queuedTasks.size());
716          for (ScheduledFuture task : tasks) {
717              assertFalse(task.isDone());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines