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

# Line 7 | Line 7
7   */
8  
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 + import static java.util.concurrent.TimeUnit.SECONDS;
11  
12   import java.util.ArrayList;
13 + import java.util.HashSet;
14   import java.util.List;
15   import java.util.concurrent.BlockingQueue;
16   import java.util.concurrent.Callable;
# Line 654 | 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() {
659 >    public void testShutdownNow_delayedTasks() throws InterruptedException {
660          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
661 <        for (int i = 0; i < 5; i++)
662 <            p.schedule(new SmallPossiblyInterruptedRunnable(),
663 <                       LONG_DELAY_MS, MILLISECONDS);
664 <        try {
665 <            List<Runnable> l = p.shutdownNow();
666 <            assertTrue(p.isShutdown());
667 <            assertTrue(p.getQueue().isEmpty());
668 <            assertEquals(5, l.size());
661 >        List<ScheduledFuture> tasks = new ArrayList<>();
662 >        for (int i = 0; i < 3; i++) {
663 >            Runnable r = new NoOpRunnable();
664 >            tasks.add(p.schedule(r, 9, SECONDS));
665 >            tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS));
666 >            tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS));
667 >        }
668 >        if (testImplementationDetails)
669 >            assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
670 >        final List<Runnable> queuedTasks;
671 >        try {
672 >            queuedTasks = p.shutdownNow();
673          } catch (SecurityException ok) {
674 <            // Allowed in case test doesn't have privs
669 <        } finally {
670 <            joinPool(p);
674 >            return; // Allowed in case test doesn't have privs
675          }
676 +        assertTrue(p.isShutdown());
677 +        assertTrue(p.getQueue().isEmpty());
678 +        if (testImplementationDetails)
679 +            assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
680 +        assertEquals(tasks.size(), queuedTasks.size());
681 +        for (ScheduledFuture task : tasks) {
682 +            assertFalse(task.isDone());
683 +            assertFalse(task.isCancelled());
684 +        }
685 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
686 +        assertTrue(p.isTerminated());
687      }
688  
689      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines