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.91 by jsr166, Wed Mar 29 16:53:20 2017 UTC vs.
Revision 1.92 by jsr166, Wed Mar 29 17:47:16 2017 UTC

# Line 746 | Line 746 | public class ScheduledExecutorTest exten
746       * - setContinueExistingPeriodicTasksAfterShutdownPolicy
747       */
748      public void testShutdown_cancellation() throws Exception {
749 <        final int poolSize = 6;
749 >        final int poolSize = 4;
750          final ScheduledThreadPoolExecutor p
751              = new ScheduledThreadPoolExecutor(poolSize);
752          final BlockingQueue<Runnable> q = p.getQueue();
753          final ThreadLocalRandom rnd = ThreadLocalRandom.current();
754 +        final long delay = rnd.nextInt(2);
755 +        final int rounds = rnd.nextInt(1, 3);
756          final boolean effectiveDelayedPolicy;
757          final boolean effectivePeriodicPolicy;
758          final boolean effectiveRemovePolicy;
# Line 816 | Line 818 | public class ScheduledExecutorTest exten
818          List<Future<?>> periodics  = new ArrayList<>();
819  
820          immediates.add(p.submit(task));
821 <        delayeds.add(p.schedule(task, 1, MILLISECONDS));
822 <        for (int rounds : new int[] { 1, 2 }) {
823 <            periodics.add(p.scheduleAtFixedRate(
824 <                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
825 <            periodics.add(p.scheduleWithFixedDelay(
824 <                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
825 <        }
821 >        delayeds.add(p.schedule(task, delay, MILLISECONDS));
822 >        periodics.add(p.scheduleAtFixedRate(
823 >                          new PeriodicTask(rounds), delay, 1, MILLISECONDS));
824 >        periodics.add(p.scheduleWithFixedDelay(
825 >                          new PeriodicTask(rounds), delay, 1, MILLISECONDS));
826  
827          await(poolBlocked);
828  
# Line 832 | Line 832 | public class ScheduledExecutorTest exten
832  
833          // Add second wave of tasks.
834          immediates.add(p.submit(task));
835 <        long delay_ms = effectiveDelayedPolicy ? 1 : LONG_DELAY_MS;
836 <        delayeds.add(p.schedule(task, delay_ms, MILLISECONDS));
837 <        for (int rounds : new int[] { 1, 2 }) {
838 <            periodics.add(p.scheduleAtFixedRate(
839 <                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
840 <            periodics.add(p.scheduleWithFixedDelay(
841 <                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
842 <        }
835 >        delayeds.add(p.schedule(task, effectiveDelayedPolicy ? delay : LONG_DELAY_MS, MILLISECONDS));
836 >        periodics.add(p.scheduleAtFixedRate(
837 >                          new PeriodicTask(rounds), delay, 1, MILLISECONDS));
838 >        periodics.add(p.scheduleWithFixedDelay(
839 >                          new PeriodicTask(rounds), delay, 1, MILLISECONDS));
840  
841          assertEquals(poolSize, q.size());
842          assertEquals(poolSize, ran.get());
# Line 869 | Line 866 | public class ScheduledExecutorTest exten
866          assertTrue(!effectiveDelayedPolicy
867                     ^ q.contains(delayeds.get(1)));
868          assertTrue(!effectivePeriodicPolicy
869 <                   ^ q.containsAll(periodics.subList(4, 8)));
869 >                   ^ q.containsAll(periodics.subList(2, 4)));
870  
871          immediates.forEach(f -> assertFalse(f.isDone()));
872  
# Line 889 | Line 886 | public class ScheduledExecutorTest exten
886                      }
887                  });
888          else {
889 <            periodics.subList(0, 4).forEach(f -> assertFalse(f.isDone()));
890 <            periodics.subList(4, 8).forEach(f -> assertTrue(f.isCancelled()));
889 >            periodics.subList(0, 2).forEach(f -> assertFalse(f.isDone()));
890 >            periodics.subList(2, 4).forEach(f -> assertTrue(f.isCancelled()));
891          }
892  
893          unblock.countDown();    // Release all pool threads
# Line 926 | Line 923 | public class ScheduledExecutorTest exten
923  
924          assertEquals(poolSize + 1
925                       + (effectiveDelayedPolicy ? 1 : 0)
926 <                     + (periodicTasksContinue ? 4 : 0),
926 >                     + (periodicTasksContinue ? 2 : 0),
927                       ran.get());
928      }
929  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines