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.36 by jsr166, Mon Sep 14 03:27:11 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 705 | Line 707 | public class ScheduledExecutorSubclassTe
707      }
708  
709      /**
710 <     * shutdownNow returns a list containing tasks that were not run
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);
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 <            List<Runnable> l = p.shutdownNow();
717 <            assertTrue(p.isShutdown());
718 <            assertEquals(5, l.size());
725 >            queuedTasks = p.shutdownNow();
726          } catch (SecurityException ok) {
727 <            // Allowed in case test doesn't have privs
721 <        } finally {
722 <            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