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.83 by jsr166, Wed Jan 4 06:09:58 2017 UTC vs.
Revision 1.87 by jsr166, Sat Mar 25 23:35:15 2017 UTC

# Line 50 | Line 50 | public class ScheduledExecutorTest exten
50              final Runnable task = new CheckedRunnable() {
51                  public void realRun() { done.countDown(); }};
52              p.execute(task);
53 <            assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
53 >            await(done);
54          }
55      }
56  
# Line 362 | Line 362 | public class ScheduledExecutorTest exten
362                  public void realRun() throws InterruptedException {
363                      threadStarted.countDown();
364                      assertEquals(0, p.getCompletedTaskCount());
365 <                    threadProceed.await();
365 >                    await(threadProceed);
366                      threadDone.countDown();
367                  }});
368              await(threadStarted);
369              assertEquals(0, p.getCompletedTaskCount());
370              threadProceed.countDown();
371 <            threadDone.await();
371 >            await(threadDone);
372              long startTime = System.nanoTime();
373              while (p.getCompletedTaskCount() != 1) {
374                  if (millisElapsedSince(startTime) > LONG_DELAY_MS)
# Line 507 | Line 507 | public class ScheduledExecutorTest exten
507      }
508  
509      /**
510 +     * The default rejected execution handler is AbortPolicy.
511 +     */
512 +    public void testDefaultRejectedExecutionHandler() {
513 +        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
514 +        try (PoolCleaner cleaner = cleaner(p)) {
515 +            assertTrue(p.getRejectedExecutionHandler()
516 +                       instanceof ThreadPoolExecutor.AbortPolicy);
517 +        }
518 +    }
519 +
520 +    /**
521       * isShutdown is false before shutdown, true after
522       */
523      public void testIsShutdown() {
# Line 733 | Line 744 | public class ScheduledExecutorTest exten
744       * - setContinueExistingPeriodicTasksAfterShutdownPolicy
745       */
746      public void testShutdown_cancellation() throws Exception {
747 <        Boolean[] allBooleans = { null, Boolean.FALSE, Boolean.TRUE };
748 <        for (Boolean policy : allBooleans)
747 >        final int UNSPECIFIED = 0, YES = 1, NO = 2;
748 >        for (int maybe : new int[] { UNSPECIFIED, YES, NO })
749      {
750          final int poolSize = 2;
751          final ScheduledThreadPoolExecutor p
752              = new ScheduledThreadPoolExecutor(poolSize);
753 <        final boolean effectiveDelayedPolicy = (policy != Boolean.FALSE);
754 <        final boolean effectivePeriodicPolicy = (policy == Boolean.TRUE);
755 <        final boolean effectiveRemovePolicy = (policy == Boolean.TRUE);
756 <        if (policy != null) {
757 <            p.setExecuteExistingDelayedTasksAfterShutdownPolicy(policy);
758 <            p.setContinueExistingPeriodicTasksAfterShutdownPolicy(policy);
759 <            p.setRemoveOnCancelPolicy(policy);
753 >        final boolean effectiveDelayedPolicy  = (maybe != NO);
754 >        final boolean effectivePeriodicPolicy = (maybe == YES);
755 >        final boolean effectiveRemovePolicy   = (maybe == YES);
756 >        if (maybe != UNSPECIFIED) {
757 >            p.setExecuteExistingDelayedTasksAfterShutdownPolicy(maybe == YES);
758 >            p.setContinueExistingPeriodicTasksAfterShutdownPolicy(maybe == YES);
759 >            p.setRemoveOnCancelPolicy(maybe == YES);
760          }
761          assertEquals(effectiveDelayedPolicy,
762                       p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
# Line 762 | Line 773 | public class ScheduledExecutorTest exten
773          Runnable task = new CheckedRunnable() { public void realRun()
774                                                      throws InterruptedException {
775              poolBlocked.countDown();
776 <            assertTrue(unblock.await(LONG_DELAY_MS, MILLISECONDS));
776 >            await(unblock);
777              ran.getAndIncrement();
778          }};
779          List<Future<?>> blockers = new ArrayList<>();
# Line 770 | Line 781 | public class ScheduledExecutorTest exten
781          List<Future<?>> delayeds = new ArrayList<>();
782          for (int i = 0; i < poolSize; i++)
783              blockers.add(p.submit(task));
784 <        assertTrue(poolBlocked.await(LONG_DELAY_MS, MILLISECONDS));
784 >        await(poolBlocked);
785  
786 <        periodics.add(p.scheduleAtFixedRate(countDowner(periodicLatch1),
787 <                                            1, 1, MILLISECONDS));
788 <        periodics.add(p.scheduleWithFixedDelay(countDowner(periodicLatch2),
789 <                                               1, 1, MILLISECONDS));
786 >        periodics.add(p.scheduleAtFixedRate(
787 >                          countDowner(periodicLatch1), 1, 1, MILLISECONDS));
788 >        periodics.add(p.scheduleWithFixedDelay(
789 >                          countDowner(periodicLatch2), 1, 1, MILLISECONDS));
790          delayeds.add(p.schedule(task, 1, MILLISECONDS));
791  
792          assertTrue(p.getQueue().containsAll(periodics));
# Line 797 | Line 808 | public class ScheduledExecutorTest exten
808              assertEquals(effectiveDelayedPolicy,
809                           p.getQueue().containsAll(delayeds));
810          }
811 <        // Release all pool threads
801 <        unblock.countDown();
811 >        unblock.countDown();    // Release all pool threads
812  
813 <        for (Future<?> delayed : delayeds) {
814 <            if (effectiveDelayedPolicy) {
805 <                assertNull(delayed.get());
806 <            }
807 <        }
813 >        if (effectiveDelayedPolicy)
814 >            for (Future<?> delayed : delayeds) assertNull(delayed.get());
815          if (effectivePeriodicPolicy) {
816 <            assertTrue(periodicLatch1.await(LONG_DELAY_MS, MILLISECONDS));
817 <            assertTrue(periodicLatch2.await(LONG_DELAY_MS, MILLISECONDS));
816 >            await(periodicLatch1);
817 >            await(periodicLatch2);
818              for (Future<?> periodic : periodics) {
819                  assertTrue(periodic.cancel(false));
820                  assertTrue(periodic.isCancelled());
821                  assertTrue(periodic.isDone());
822              }
823          }
824 +        for (Future<?> blocker : blockers) assertNull(blocker.get());
825          assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
826          assertTrue(p.isTerminated());
827 +
828 +        for (Future<?> future : delayeds) {
829 +            assertTrue(effectiveDelayedPolicy ^ future.isCancelled());
830 +            assertTrue(future.isDone());
831 +        }
832 +        for (Future<?> future : periodics)
833 +            assertTrue(future.isCancelled());
834 +        for (Future<?> future : blockers)
835 +            assertNull(future.get());
836          assertEquals(2 + (effectiveDelayedPolicy ? 1 : 0), ran.get());
837      }}
838  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines