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.38 by jsr166, Sun Sep 27 20:17:39 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 >        assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
723 >        final List<Runnable> queuedTasks;
724 >        try {
725 >            queuedTasks = p.shutdownNow();
726          } catch (SecurityException ok) {
727 <            // Allowed in case test doesn't have privs
723 <        } finally {
724 <            joinPool(p);
727 >            return; // Allowed in case test doesn't have privs
728          }
729 +        assertTrue(p.isShutdown());
730 +        assertTrue(p.getQueue().isEmpty());
731 +        assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
732 +        assertEquals(tasks.size(), queuedTasks.size());
733 +        for (ScheduledFuture task : tasks) {
734 +            assertFalse(((CustomTask)task).ran);
735 +            assertFalse(task.isDone());
736 +            assertFalse(task.isCancelled());
737 +        }
738 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
739 +        assertTrue(p.isTerminated());
740      }
741  
742      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines