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.54 by jsr166, Sun Sep 27 20:17:39 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 >        assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
669 >        final List<Runnable> queuedTasks;
670 >        try {
671 >            queuedTasks = p.shutdownNow();
672          } catch (SecurityException ok) {
673 <            // Allowed in case test doesn't have privs
669 <        } finally {
670 <            joinPool(p);
673 >            return; // Allowed in case test doesn't have privs
674          }
675 +        assertTrue(p.isShutdown());
676 +        assertTrue(p.getQueue().isEmpty());
677 +        assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
678 +        assertEquals(tasks.size(), queuedTasks.size());
679 +        for (ScheduledFuture task : tasks) {
680 +            assertFalse(task.isDone());
681 +            assertFalse(task.isCancelled());
682 +        }
683 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
684 +        assertTrue(p.isTerminated());
685      }
686  
687      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines