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.54 by jsr166, Sun Sep 27 20:17:39 2015 UTC vs.
Revision 1.57 by jsr166, Mon Sep 28 03:05:23 2015 UTC

# Line 656 | 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() throws InterruptedException {
660 +        final int poolSize = 2;
661 +        final int count = 5;
662 +        final AtomicInteger ran = new AtomicInteger(0);
663 +        final ScheduledThreadPoolExecutor p =
664 +            new ScheduledThreadPoolExecutor(poolSize);
665 +        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
666 +        CheckedRunnable waiter = new CheckedRunnable() { public void realRun() {
667 +            threadsStarted.countDown();
668 +            try {
669 +                MILLISECONDS.sleep(2 * LONG_DELAY_MS);
670 +            } catch (InterruptedException success) {}
671 +            ran.getAndIncrement();
672 +        }};
673 +        for (int i = 0; i < count; i++)
674 +            p.execute(waiter);
675 +        assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
676 +        assertEquals(poolSize, p.getActiveCount());
677 +        assertEquals(0, p.getCompletedTaskCount());
678 +        final List<Runnable> queuedTasks;
679 +        try {
680 +            queuedTasks = p.shutdownNow();
681 +        } catch (SecurityException ok) {
682 +            return; // Allowed in case test doesn't have privs
683 +        }
684 +        assertTrue(p.isShutdown());
685 +        assertTrue(p.getQueue().isEmpty());
686 +        assertEquals(count - poolSize, queuedTasks.size());
687 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
688 +        assertTrue(p.isTerminated());
689 +        assertEquals(poolSize, ran.get());
690 +        assertEquals(poolSize, p.getCompletedTaskCount());
691 +    }
692 +
693 +    /**
694 +     * shutdownNow returns a list containing tasks that were not run,
695 +     * and those tasks are drained from the queue
696 +     */
697      public void testShutdownNow_delayedTasks() throws InterruptedException {
698          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
699          List<ScheduledFuture> tasks = new ArrayList<>();
# Line 665 | Line 703 | public class ScheduledExecutorTest exten
703              tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS));
704              tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS));
705          }
706 <        assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
706 >        if (testImplementationDetails)
707 >            assertEquals(new HashSet(tasks), new HashSet(p.getQueue()));
708          final List<Runnable> queuedTasks;
709          try {
710              queuedTasks = p.shutdownNow();
# Line 674 | Line 713 | public class ScheduledExecutorTest exten
713          }
714          assertTrue(p.isShutdown());
715          assertTrue(p.getQueue().isEmpty());
716 <        assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
716 >        if (testImplementationDetails)
717 >            assertEquals(new HashSet(tasks), new HashSet(queuedTasks));
718          assertEquals(tasks.size(), queuedTasks.size());
719          for (ScheduledFuture task : tasks) {
720              assertFalse(task.isDone());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines