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

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

# Line 710 | Line 710 | public class ScheduledExecutorSubclassTe
710       * shutdownNow returns a list containing tasks that were not run,
711       * and those tasks are drained from the queue
712       */
713 +    public void testShutdownNow() throws InterruptedException {
714 +        final int poolSize = 2;
715 +        final int count = 5;
716 +        final AtomicInteger ran = new AtomicInteger(0);
717 +        final CustomExecutor p = new CustomExecutor(poolSize);
718 +        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
719 +        CheckedRunnable waiter = new CheckedRunnable() { public void realRun() {
720 +            threadsStarted.countDown();
721 +            try {
722 +                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
723 +            } catch (InterruptedException success) {}
724 +            ran.getAndIncrement();
725 +        }};
726 +        for (int i = 0; i < count; i++)
727 +            p.execute(waiter);
728 +        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
729 +        final List<Runnable> queuedTasks;
730 +        try {
731 +            queuedTasks = p.shutdownNow();
732 +        } catch (SecurityException ok) {
733 +            return; // Allowed in case test doesn't have privs
734 +        }
735 +        assertTrue(p.isShutdown());
736 +        assertTrue(p.getQueue().isEmpty());
737 +        assertEquals(count - poolSize, queuedTasks.size());
738 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
739 +        assertTrue(p.isTerminated());
740 +        assertEquals(poolSize, ran.get());
741 +    }
742 +
743 +    /**
744 +     * shutdownNow returns a list containing tasks that were not run,
745 +     * and those tasks are drained from the queue
746 +     */
747      public void testShutdownNow_delayedTasks() throws InterruptedException {
748          CustomExecutor p = new CustomExecutor(1);
749          List<ScheduledFuture> tasks = new ArrayList<>();
# Line 719 | Line 753 | public class ScheduledExecutorSubclassTe
753              tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS));
754              tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS));
755          }
756 <        assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
756 >        if (testImplementationDetails)
757 >            assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
758          final List<Runnable> queuedTasks;
759          try {
760              queuedTasks = p.shutdownNow();
# Line 728 | Line 763 | public class ScheduledExecutorSubclassTe
763          }
764          assertTrue(p.isShutdown());
765          assertTrue(p.getQueue().isEmpty());
766 <        assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
766 >        if (testImplementationDetails)
767 >            assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
768          assertEquals(tasks.size(), queuedTasks.size());
769          for (ScheduledFuture task : tasks) {
770              assertFalse(((CustomTask)task).ran);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines