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.79 by jsr166, Mon Feb 22 20:40:12 2016 UTC

# Line 154 | Line 154 | public class ScheduledExecutorTest exten
154                  final CountDownLatch done = new CountDownLatch(cycles);
155                  Runnable task = new CheckedRunnable() {
156                      public void realRun() { done.countDown(); }};
157 <                ScheduledFuture h =
157 >                ScheduledFuture periodicTask =
158                      p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
159                  await(done);
160 <                h.cancel(true);
161 <                double normalizedTime =
160 >                periodicTask.cancel(true);
161 >                double elapsedDelays =
162                      (double) millisElapsedSince(startTime) / delay;
163 <                if (normalizedTime >= cycles - 1 &&
164 <                    normalizedTime <= cycles)
163 >                if (elapsedDelays >= cycles - 1 &&
164 >                    elapsedDelays <= cycles)
165                      return;
166              }
167 <            throw new AssertionError("unexpected execution rate");
167 >            fail("unexpected execution rate");
168          }
169      }
170  
# Line 180 | Line 180 | public class ScheduledExecutorTest exten
180                  final CountDownLatch done = new CountDownLatch(cycles);
181                  Runnable task = new CheckedRunnable() {
182                      public void realRun() { done.countDown(); }};
183 <                ScheduledFuture h =
183 >                ScheduledFuture periodicTask =
184                      p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
185                  await(done);
186 <                h.cancel(true);
187 <                double normalizedTime =
186 >                periodicTask.cancel(true);
187 >                double elapsedDelays =
188                      (double) millisElapsedSince(startTime) / delay;
189 <                if (normalizedTime >= cycles - 1 &&
190 <                    normalizedTime <= cycles)
189 >                if (elapsedDelays >= cycles - 1 &&
190 >                    elapsedDelays <= cycles)
191                      return;
192              }
193 <            throw new AssertionError("unexpected execution rate");
193 >            fail("unexpected execution rate");
194          }
195      }
196  
# Line 1206 | Line 1206 | public class ScheduledExecutorTest exten
1206          }
1207      }
1208  
1209 +    /**
1210 +     * A fixed delay task with overflowing period should not prevent a
1211 +     * one-shot task from executing.
1212 +     * https://bugs.openjdk.java.net/browse/JDK-8051859
1213 +     */
1214 +    public void testScheduleWithFixedDelay_overflow() throws Exception {
1215 +        final CountDownLatch delayedDone = new CountDownLatch(1);
1216 +        final CountDownLatch immediateDone = new CountDownLatch(1);
1217 +        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
1218 +        try (PoolCleaner cleaner = cleaner(p)) {
1219 +            final Runnable immediate = new Runnable() { public void run() {
1220 +                immediateDone.countDown();
1221 +            }};
1222 +            final Runnable delayed = new Runnable() { public void run() {
1223 +                delayedDone.countDown();
1224 +                p.submit(immediate);
1225 +            }};
1226 +            p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS);
1227 +            await(delayedDone);
1228 +            await(immediateDone);
1229 +        }
1230 +    }
1231 +
1232   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines