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.76 by jsr166, Thu Oct 8 03:08:37 2015 UTC vs.
Revision 1.91 by jsr166, Wed Mar 29 16:53:20 2017 UTC

# Line 7 | Line 7
7   */
8  
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 + import static java.util.concurrent.TimeUnit.NANOSECONDS;
11   import static java.util.concurrent.TimeUnit.SECONDS;
12  
13   import java.util.ArrayList;
# Line 17 | Line 18 | import java.util.concurrent.Callable;
18   import java.util.concurrent.CancellationException;
19   import java.util.concurrent.CountDownLatch;
20   import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Executors;
21   import java.util.concurrent.ExecutorService;
22   import java.util.concurrent.Future;
23   import java.util.concurrent.RejectedExecutionException;
24   import java.util.concurrent.ScheduledFuture;
25   import java.util.concurrent.ScheduledThreadPoolExecutor;
26   import java.util.concurrent.ThreadFactory;
27 + import java.util.concurrent.ThreadLocalRandom;
28   import java.util.concurrent.ThreadPoolExecutor;
29 + import java.util.concurrent.atomic.AtomicBoolean;
30   import java.util.concurrent.atomic.AtomicInteger;
31 + import java.util.concurrent.atomic.AtomicLong;
32 + import java.util.stream.Stream;
33  
34   import junit.framework.Test;
35   import junit.framework.TestSuite;
# Line 48 | Line 52 | public class ScheduledExecutorTest exten
52              final Runnable task = new CheckedRunnable() {
53                  public void realRun() { done.countDown(); }};
54              p.execute(task);
55 <            assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
55 >            await(done);
56          }
57      }
58  
# Line 143 | Line 147 | public class ScheduledExecutorTest exten
147      }
148  
149      /**
150 <     * scheduleAtFixedRate executes series of tasks at given rate
150 >     * scheduleAtFixedRate executes series of tasks at given rate.
151 >     * Eventually, it must hold that:
152 >     *   cycles - 1 <= elapsedMillis/delay < cycles
153       */
154      public void testFixedRateSequence() throws InterruptedException {
155          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
156          try (PoolCleaner cleaner = cleaner(p)) {
157              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
158 <                long startTime = System.nanoTime();
159 <                int cycles = 10;
158 >                final long startTime = System.nanoTime();
159 >                final int cycles = 8;
160                  final CountDownLatch done = new CountDownLatch(cycles);
161 <                Runnable task = new CheckedRunnable() {
161 >                final Runnable task = new CheckedRunnable() {
162                      public void realRun() { done.countDown(); }};
163 <                ScheduledFuture h =
163 >                final ScheduledFuture periodicTask =
164                      p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
165 <                await(done);
166 <                h.cancel(true);
167 <                double normalizedTime =
168 <                    (double) millisElapsedSince(startTime) / delay;
169 <                if (normalizedTime >= cycles - 1 &&
170 <                    normalizedTime <= cycles)
165 >                final int totalDelayMillis = (cycles - 1) * delay;
166 >                await(done, totalDelayMillis + LONG_DELAY_MS);
167 >                periodicTask.cancel(true);
168 >                final long elapsedMillis = millisElapsedSince(startTime);
169 >                assertTrue(elapsedMillis >= totalDelayMillis);
170 >                if (elapsedMillis <= cycles * delay)
171                      return;
172 +                // else retry with longer delay
173              }
174 <            throw new AssertionError("unexpected execution rate");
174 >            fail("unexpected execution rate");
175          }
176      }
177  
178      /**
179 <     * scheduleWithFixedDelay executes series of tasks with given period
179 >     * scheduleWithFixedDelay executes series of tasks with given period.
180 >     * Eventually, it must hold that each task starts at least delay and at
181 >     * most 2 * delay after the termination of the previous task.
182       */
183      public void testFixedDelaySequence() throws InterruptedException {
184          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
185          try (PoolCleaner cleaner = cleaner(p)) {
186              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
187 <                long startTime = System.nanoTime();
188 <                int cycles = 10;
187 >                final long startTime = System.nanoTime();
188 >                final AtomicLong previous = new AtomicLong(startTime);
189 >                final AtomicBoolean tryLongerDelay = new AtomicBoolean(false);
190 >                final int cycles = 8;
191                  final CountDownLatch done = new CountDownLatch(cycles);
192 <                Runnable task = new CheckedRunnable() {
193 <                    public void realRun() { done.countDown(); }};
194 <                ScheduledFuture h =
192 >                final int d = delay;
193 >                final Runnable task = new CheckedRunnable() {
194 >                    public void realRun() {
195 >                        long now = System.nanoTime();
196 >                        long elapsedMillis
197 >                            = NANOSECONDS.toMillis(now - previous.get());
198 >                        if (done.getCount() == cycles) { // first execution
199 >                            if (elapsedMillis >= d)
200 >                                tryLongerDelay.set(true);
201 >                        } else {
202 >                            assertTrue(elapsedMillis >= d);
203 >                            if (elapsedMillis >= 2 * d)
204 >                                tryLongerDelay.set(true);
205 >                        }
206 >                        previous.set(now);
207 >                        done.countDown();
208 >                    }};
209 >                final ScheduledFuture periodicTask =
210                      p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
211 <                await(done);
212 <                h.cancel(true);
213 <                double normalizedTime =
214 <                    (double) millisElapsedSince(startTime) / delay;
215 <                if (normalizedTime >= cycles - 1 &&
216 <                    normalizedTime <= cycles)
211 >                final int totalDelayMillis = (cycles - 1) * delay;
212 >                await(done, totalDelayMillis + cycles * LONG_DELAY_MS);
213 >                periodicTask.cancel(true);
214 >                final long elapsedMillis = millisElapsedSince(startTime);
215 >                assertTrue(elapsedMillis >= totalDelayMillis);
216 >                if (!tryLongerDelay.get())
217                      return;
218 +                // else retry with longer delay
219              }
220 <            throw new AssertionError("unexpected execution rate");
220 >            fail("unexpected execution rate");
221          }
222      }
223  
# Line 337 | Line 364 | public class ScheduledExecutorTest exten
364                  public void realRun() throws InterruptedException {
365                      threadStarted.countDown();
366                      assertEquals(0, p.getCompletedTaskCount());
367 <                    threadProceed.await();
367 >                    await(threadProceed);
368                      threadDone.countDown();
369                  }});
370              await(threadStarted);
371              assertEquals(0, p.getCompletedTaskCount());
372              threadProceed.countDown();
373 <            threadDone.await();
373 >            await(threadDone);
374              long startTime = System.nanoTime();
375              while (p.getCompletedTaskCount() != 1) {
376                  if (millisElapsedSince(startTime) > LONG_DELAY_MS)
# Line 482 | Line 509 | public class ScheduledExecutorTest exten
509      }
510  
511      /**
512 +     * The default rejected execution handler is AbortPolicy.
513 +     */
514 +    public void testDefaultRejectedExecutionHandler() {
515 +        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
516 +        try (PoolCleaner cleaner = cleaner(p)) {
517 +            assertTrue(p.getRejectedExecutionHandler()
518 +                       instanceof ThreadPoolExecutor.AbortPolicy);
519 +        }
520 +    }
521 +
522 +    /**
523       * isShutdown is false before shutdown, true after
524       */
525      public void testIsShutdown() {
488
526          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
527 <        try {
528 <            assertFalse(p.isShutdown());
529 <        }
530 <        finally {
531 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
527 >        assertFalse(p.isShutdown());
528 >        try (PoolCleaner cleaner = cleaner(p)) {
529 >            try {
530 >                p.shutdown();
531 >                assertTrue(p.isShutdown());
532 >            } catch (SecurityException ok) {}
533          }
496        assertTrue(p.isShutdown());
534      }
535  
536      /**
# Line 709 | Line 746 | public class ScheduledExecutorTest exten
746       * - setContinueExistingPeriodicTasksAfterShutdownPolicy
747       */
748      public void testShutdown_cancellation() throws Exception {
749 <        Boolean[] allBooleans = { null, Boolean.FALSE, Boolean.TRUE };
713 <        for (Boolean policy : allBooleans)
714 <    {
715 <        final int poolSize = 2;
749 >        final int poolSize = 6;
750          final ScheduledThreadPoolExecutor p
751              = new ScheduledThreadPoolExecutor(poolSize);
752 <        final boolean effectiveDelayedPolicy = (policy != Boolean.FALSE);
753 <        final boolean effectivePeriodicPolicy = (policy == Boolean.TRUE);
754 <        final boolean effectiveRemovePolicy = (policy == Boolean.TRUE);
755 <        if (policy != null) {
756 <            p.setExecuteExistingDelayedTasksAfterShutdownPolicy(policy);
757 <            p.setContinueExistingPeriodicTasksAfterShutdownPolicy(policy);
758 <            p.setRemoveOnCancelPolicy(policy);
759 <        }
752 >        final BlockingQueue<Runnable> q = p.getQueue();
753 >        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
754 >        final boolean effectiveDelayedPolicy;
755 >        final boolean effectivePeriodicPolicy;
756 >        final boolean effectiveRemovePolicy;
757 >
758 >        if (rnd.nextBoolean())
759 >            p.setExecuteExistingDelayedTasksAfterShutdownPolicy(
760 >                effectiveDelayedPolicy = rnd.nextBoolean());
761 >        else
762 >            effectiveDelayedPolicy = true;
763          assertEquals(effectiveDelayedPolicy,
764                       p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
765 +
766 +        if (rnd.nextBoolean())
767 +            p.setContinueExistingPeriodicTasksAfterShutdownPolicy(
768 +                effectivePeriodicPolicy = rnd.nextBoolean());
769 +        else
770 +            effectivePeriodicPolicy = false;
771          assertEquals(effectivePeriodicPolicy,
772                       p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
773 +
774 +        if (rnd.nextBoolean())
775 +            p.setRemoveOnCancelPolicy(
776 +                effectiveRemovePolicy = rnd.nextBoolean());
777 +        else
778 +            effectiveRemovePolicy = false;
779          assertEquals(effectiveRemovePolicy,
780                       p.getRemoveOnCancelPolicy());
781 <        // Strategy: Wedge the pool with poolSize "blocker" threads
781 >
782 >        final boolean periodicTasksContinue = effectivePeriodicPolicy && rnd.nextBoolean();
783 >
784 >        // Strategy: Wedge the pool with one wave of "blocker" tasks,
785 >        // then add a second wave that waits in the queue until unblocked.
786          final AtomicInteger ran = new AtomicInteger(0);
787          final CountDownLatch poolBlocked = new CountDownLatch(poolSize);
788          final CountDownLatch unblock = new CountDownLatch(1);
789 <        final CountDownLatch periodicLatch1 = new CountDownLatch(2);
790 <        final CountDownLatch periodicLatch2 = new CountDownLatch(2);
791 <        Runnable task = new CheckedRunnable() { public void realRun()
792 <                                                    throws InterruptedException {
793 <            poolBlocked.countDown();
794 <            assertTrue(unblock.await(LONG_DELAY_MS, MILLISECONDS));
795 <            ran.getAndIncrement();
796 <        }};
797 <        List<Future<?>> blockers = new ArrayList<>();
798 <        List<Future<?>> periodics = new ArrayList<>();
799 <        List<Future<?>> delayeds = new ArrayList<>();
800 <        for (int i = 0; i < poolSize; i++)
801 <            blockers.add(p.submit(task));
802 <        assertTrue(poolBlocked.await(LONG_DELAY_MS, MILLISECONDS));
803 <
804 <        periodics.add(p.scheduleAtFixedRate(countDowner(periodicLatch1),
805 <                                            1, 1, MILLISECONDS));
806 <        periodics.add(p.scheduleWithFixedDelay(countDowner(periodicLatch2),
807 <                                               1, 1, MILLISECONDS));
789 >        final RuntimeException exception = new RuntimeException();
790 >
791 >        class Task implements Runnable {
792 >            public void run() {
793 >                try {
794 >                    ran.getAndIncrement();
795 >                    poolBlocked.countDown();
796 >                    await(unblock);
797 >                } catch (Throwable fail) { threadUnexpectedException(fail); }
798 >            }
799 >        }
800 >
801 >        class PeriodicTask extends Task {
802 >            PeriodicTask(int rounds) { this.rounds = rounds; }
803 >            int rounds;
804 >            public void run() {
805 >                if (--rounds == 0) super.run();
806 >                // throw exception to surely terminate this periodic task,
807 >                // but in a separate execution and in a detectable way.
808 >                if (rounds == -1) throw exception;
809 >            }
810 >        }
811 >
812 >        Runnable task = new Task();
813 >
814 >        List<Future<?>> immediates = new ArrayList<>();
815 >        List<Future<?>> delayeds   = new ArrayList<>();
816 >        List<Future<?>> periodics  = new ArrayList<>();
817 >
818 >        immediates.add(p.submit(task));
819          delayeds.add(p.schedule(task, 1, MILLISECONDS));
820 +        for (int rounds : new int[] { 1, 2 }) {
821 +            periodics.add(p.scheduleAtFixedRate(
822 +                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
823 +            periodics.add(p.scheduleWithFixedDelay(
824 +                              new PeriodicTask(rounds), 1, 1, MILLISECONDS));
825 +        }
826 +
827 +        await(poolBlocked);
828 +
829 +        assertEquals(poolSize, ran.get());
830 +        assertEquals(poolSize, p.getActiveCount());
831 +        assertTrue(q.isEmpty());
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 +        }
843 +
844 +        assertEquals(poolSize, q.size());
845 +        assertEquals(poolSize, ran.get());
846 +
847 +        immediates.forEach(
848 +            f -> assertTrue(((ScheduledFuture)f).getDelay(NANOSECONDS) <= 0L));
849 +
850 +        Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream())
851 +            .forEach(f -> assertFalse(f.isDone()));
852  
757        assertTrue(p.getQueue().containsAll(periodics));
758        assertTrue(p.getQueue().containsAll(delayeds));
853          try { p.shutdown(); } catch (SecurityException ok) { return; }
854          assertTrue(p.isShutdown());
855 +        assertTrue(p.isTerminating());
856          assertFalse(p.isTerminated());
857 <        for (Future<?> periodic : periodics) {
858 <            assertTrue(effectivePeriodicPolicy ^ periodic.isCancelled());
859 <            assertTrue(effectivePeriodicPolicy ^ periodic.isDone());
860 <        }
861 <        for (Future<?> delayed : delayeds) {
862 <            assertTrue(effectiveDelayedPolicy ^ delayed.isCancelled());
863 <            assertTrue(effectiveDelayedPolicy ^ delayed.isDone());
864 <        }
865 <        if (testImplementationDetails) {
866 <            assertEquals(effectivePeriodicPolicy,
867 <                         p.getQueue().containsAll(periodics));
868 <            assertEquals(effectiveDelayedPolicy,
869 <                         p.getQueue().containsAll(delayeds));
870 <        }
871 <        // Release all pool threads
872 <        unblock.countDown();
873 <
874 <        for (Future<?> delayed : delayeds) {
875 <            if (effectiveDelayedPolicy) {
876 <                assertNull(delayed.get());
877 <            }
878 <        }
879 <        if (effectivePeriodicPolicy) {
880 <            assertTrue(periodicLatch1.await(LONG_DELAY_MS, MILLISECONDS));
881 <            assertTrue(periodicLatch2.await(LONG_DELAY_MS, MILLISECONDS));
882 <            for (Future<?> periodic : periodics) {
883 <                assertTrue(periodic.cancel(false));
884 <                assertTrue(periodic.isCancelled());
885 <                assertTrue(periodic.isDone());
886 <            }
857 >
858 >        if (rnd.nextBoolean())
859 >            assertThrows(
860 >                RejectedExecutionException.class,
861 >                () -> p.submit(task),
862 >                () -> p.schedule(task, 1, SECONDS),
863 >                () -> p.scheduleAtFixedRate(
864 >                    new PeriodicTask(1), 1, 1, SECONDS),
865 >                () -> p.scheduleWithFixedDelay(
866 >                    new PeriodicTask(2), 1, 1, SECONDS));
867 >
868 >        assertTrue(q.contains(immediates.get(1)));
869 >        assertTrue(!effectiveDelayedPolicy
870 >                   ^ q.contains(delayeds.get(1)));
871 >        assertTrue(!effectivePeriodicPolicy
872 >                   ^ q.containsAll(periodics.subList(4, 8)));
873 >
874 >        immediates.forEach(f -> assertFalse(f.isDone()));
875 >
876 >        assertFalse(delayeds.get(0).isDone());
877 >        if (effectiveDelayedPolicy)
878 >            assertFalse(delayeds.get(1).isDone());
879 >        else
880 >            assertTrue(delayeds.get(1).isCancelled());
881 >
882 >        if (effectivePeriodicPolicy)
883 >            periodics.forEach(
884 >                f -> {
885 >                    assertFalse(f.isDone());
886 >                    if (!periodicTasksContinue) {
887 >                        assertTrue(f.cancel(false));
888 >                        assertTrue(f.isCancelled());
889 >                    }
890 >                });
891 >        else {
892 >            periodics.subList(0, 4).forEach(f -> assertFalse(f.isDone()));
893 >            periodics.subList(4, 8).forEach(f -> assertTrue(f.isCancelled()));
894          }
895 +
896 +        unblock.countDown();    // Release all pool threads
897 +
898          assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
899 +        assertFalse(p.isTerminating());
900          assertTrue(p.isTerminated());
901 <        assertEquals(2 + (effectiveDelayedPolicy ? 1 : 0), ran.get());
902 <    }}
901 >
902 >        assertTrue(q.isEmpty());
903 >
904 >        Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream())
905 >            .forEach(f -> assertTrue(f.isDone()));
906 >
907 >        for (Future<?> f : immediates) assertNull(f.get());
908 >
909 >        assertNull(delayeds.get(0).get());
910 >        if (effectiveDelayedPolicy)
911 >            assertNull(delayeds.get(1).get());
912 >        else
913 >            assertTrue(delayeds.get(1).isCancelled());
914 >
915 >        if (periodicTasksContinue)
916 >            periodics.forEach(
917 >                f -> {
918 >                    try { f.get(); }
919 >                    catch (ExecutionException success) {
920 >                        assertSame(exception, success.getCause());
921 >                    }
922 >                    catch (Throwable fail) { threadUnexpectedException(fail); }
923 >                });
924 >        else
925 >            periodics.forEach(f -> assertTrue(f.isCancelled()));
926 >
927 >        assertEquals(poolSize + 1
928 >                     + (effectiveDelayedPolicy ? 1 : 0)
929 >                     + (periodicTasksContinue ? 4 : 0),
930 >                     ran.get());
931 >    }
932  
933      /**
934       * completed submit of callable returns result
# Line 864 | Line 999 | public class ScheduledExecutorTest exten
999          CountDownLatch latch = new CountDownLatch(1);
1000          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1001          try (PoolCleaner cleaner = cleaner(e)) {
1002 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1002 >            List<Callable<String>> l = new ArrayList<>();
1003              l.add(latchAwaitingStringTask(latch));
1004              l.add(null);
1005              try {
# Line 881 | Line 1016 | public class ScheduledExecutorTest exten
1016      public void testInvokeAny4() throws Exception {
1017          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1018          try (PoolCleaner cleaner = cleaner(e)) {
1019 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1019 >            List<Callable<String>> l = new ArrayList<>();
1020              l.add(new NPETask());
1021              try {
1022                  e.invokeAny(l);
# Line 898 | Line 1033 | public class ScheduledExecutorTest exten
1033      public void testInvokeAny5() throws Exception {
1034          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1035          try (PoolCleaner cleaner = cleaner(e)) {
1036 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1036 >            List<Callable<String>> l = new ArrayList<>();
1037              l.add(new StringTask());
1038              l.add(new StringTask());
1039              String result = e.invokeAny(l);
# Line 936 | Line 1071 | public class ScheduledExecutorTest exten
1071      public void testInvokeAll3() throws Exception {
1072          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1073          try (PoolCleaner cleaner = cleaner(e)) {
1074 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1074 >            List<Callable<String>> l = new ArrayList<>();
1075              l.add(new StringTask());
1076              l.add(null);
1077              try {
# Line 952 | Line 1087 | public class ScheduledExecutorTest exten
1087      public void testInvokeAll4() throws Exception {
1088          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1089          try (PoolCleaner cleaner = cleaner(e)) {
1090 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1090 >            List<Callable<String>> l = new ArrayList<>();
1091              l.add(new NPETask());
1092              List<Future<String>> futures = e.invokeAll(l);
1093              assertEquals(1, futures.size());
# Line 971 | Line 1106 | public class ScheduledExecutorTest exten
1106      public void testInvokeAll5() throws Exception {
1107          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1108          try (PoolCleaner cleaner = cleaner(e)) {
1109 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1109 >            List<Callable<String>> l = new ArrayList<>();
1110              l.add(new StringTask());
1111              l.add(new StringTask());
1112              List<Future<String>> futures = e.invokeAll(l);
# Line 1000 | Line 1135 | public class ScheduledExecutorTest exten
1135      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1136          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1137          try (PoolCleaner cleaner = cleaner(e)) {
1138 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1138 >            List<Callable<String>> l = new ArrayList<>();
1139              l.add(new StringTask());
1140              try {
1141                  e.invokeAny(l, MEDIUM_DELAY_MS, null);
# Line 1029 | Line 1164 | public class ScheduledExecutorTest exten
1164          CountDownLatch latch = new CountDownLatch(1);
1165          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1166          try (PoolCleaner cleaner = cleaner(e)) {
1167 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1167 >            List<Callable<String>> l = new ArrayList<>();
1168              l.add(latchAwaitingStringTask(latch));
1169              l.add(null);
1170              try {
# Line 1047 | Line 1182 | public class ScheduledExecutorTest exten
1182          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1183          try (PoolCleaner cleaner = cleaner(e)) {
1184              long startTime = System.nanoTime();
1185 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1185 >            List<Callable<String>> l = new ArrayList<>();
1186              l.add(new NPETask());
1187              try {
1188                  e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 1066 | Line 1201 | public class ScheduledExecutorTest exten
1201          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1202          try (PoolCleaner cleaner = cleaner(e)) {
1203              long startTime = System.nanoTime();
1204 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1204 >            List<Callable<String>> l = new ArrayList<>();
1205              l.add(new StringTask());
1206              l.add(new StringTask());
1207              String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 1094 | Line 1229 | public class ScheduledExecutorTest exten
1229      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1230          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1231          try (PoolCleaner cleaner = cleaner(e)) {
1232 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1232 >            List<Callable<String>> l = new ArrayList<>();
1233              l.add(new StringTask());
1234              try {
1235                  e.invokeAll(l, MEDIUM_DELAY_MS, null);
# Line 1121 | Line 1256 | public class ScheduledExecutorTest exten
1256      public void testTimedInvokeAll3() throws Exception {
1257          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1258          try (PoolCleaner cleaner = cleaner(e)) {
1259 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1259 >            List<Callable<String>> l = new ArrayList<>();
1260              l.add(new StringTask());
1261              l.add(null);
1262              try {
# Line 1137 | Line 1272 | public class ScheduledExecutorTest exten
1272      public void testTimedInvokeAll4() throws Exception {
1273          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1274          try (PoolCleaner cleaner = cleaner(e)) {
1275 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1275 >            List<Callable<String>> l = new ArrayList<>();
1276              l.add(new NPETask());
1277              List<Future<String>> futures =
1278                  e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
# Line 1157 | Line 1292 | public class ScheduledExecutorTest exten
1292      public void testTimedInvokeAll5() throws Exception {
1293          final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1294          try (PoolCleaner cleaner = cleaner(e)) {
1295 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
1295 >            List<Callable<String>> l = new ArrayList<>();
1296              l.add(new StringTask());
1297              l.add(new StringTask());
1298              List<Future<String>> futures =
# Line 1206 | Line 1341 | public class ScheduledExecutorTest exten
1341          }
1342      }
1343  
1344 +    /**
1345 +     * A fixed delay task with overflowing period should not prevent a
1346 +     * one-shot task from executing.
1347 +     * https://bugs.openjdk.java.net/browse/JDK-8051859
1348 +     */
1349 +    public void testScheduleWithFixedDelay_overflow() throws Exception {
1350 +        final CountDownLatch delayedDone = new CountDownLatch(1);
1351 +        final CountDownLatch immediateDone = new CountDownLatch(1);
1352 +        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
1353 +        try (PoolCleaner cleaner = cleaner(p)) {
1354 +            final Runnable immediate = new Runnable() { public void run() {
1355 +                immediateDone.countDown();
1356 +            }};
1357 +            final Runnable delayed = new Runnable() { public void run() {
1358 +                delayedDone.countDown();
1359 +                p.submit(immediate);
1360 +            }};
1361 +            p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS);
1362 +            await(delayedDone);
1363 +            await(immediateDone);
1364 +        }
1365 +    }
1366 +
1367   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines