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.37 by jsr166, Sun Sep 27 18:50:50 2015 UTC vs.
Revision 1.39 by jsr166, Mon Sep 28 02:32:57 2015 UTC

# Line 5 | Line 5
5   */
6  
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 + import static java.util.concurrent.TimeUnit.SECONDS;
9  
10   import java.util.ArrayList;
11 + import java.util.HashSet;
12   import java.util.List;
13   import java.util.concurrent.BlockingQueue;
14   import java.util.concurrent.Callable;
# Line 708 | 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() {
713 >    public void testShutdownNow_delayedTasks() throws InterruptedException {
714          CustomExecutor p = new CustomExecutor(1);
715 <        for (int i = 0; i < 5; i++)
716 <            p.schedule(new SmallPossiblyInterruptedRunnable(),
717 <                       LONG_DELAY_MS, MILLISECONDS);
718 <        try {
719 <            List<Runnable> l = p.shutdownNow();
720 <            assertTrue(p.isShutdown());
721 <            assertTrue(p.getQueue().isEmpty());
722 <            assertEquals(5, l.size());
715 >        List<ScheduledFuture> tasks = new ArrayList<>();
716 >        for (int i = 0; i < 3; i++) {
717 >            Runnable r = new NoOpRunnable();
718 >            tasks.add(p.schedule(r, 9, SECONDS));
719 >            tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS));
720 >            tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS));
721 >        }
722 >        if (testImplementationDetails)
723 >            assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
724 >        final List<Runnable> queuedTasks;
725 >        try {
726 >            queuedTasks = p.shutdownNow();
727          } catch (SecurityException ok) {
728 <            // Allowed in case test doesn't have privs
723 <        } finally {
724 <            joinPool(p);
728 >            return; // Allowed in case test doesn't have privs
729          }
730 +        assertTrue(p.isShutdown());
731 +        assertTrue(p.getQueue().isEmpty());
732 +        if (testImplementationDetails)
733 +            assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
734 +        assertEquals(tasks.size(), queuedTasks.size());
735 +        for (ScheduledFuture task : tasks) {
736 +            assertFalse(((CustomTask)task).ran);
737 +            assertFalse(task.isDone());
738 +            assertFalse(task.isCancelled());
739 +        }
740 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
741 +        assertTrue(p.isTerminated());
742      }
743  
744      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines