ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorSubclassTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.30 by jsr166, Mon Dec 5 04:08:46 2011 UTC vs.
Revision 1.31 by jsr166, Tue Sep 24 18:35:21 2013 UTC

# Line 193 | Line 193 | public class ScheduledExecutorSubclassTe
193       */
194      public void testFixedRateSequence() throws InterruptedException {
195          CustomExecutor p = new CustomExecutor(1);
196 <        RunnableCounter counter = new RunnableCounter();
197 <        ScheduledFuture h =
198 <            p.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
199 <        delay(SMALL_DELAY_MS);
200 <        h.cancel(true);
201 <        int c = counter.count.get();
202 <        // By time scaling conventions, we must have at least
203 <        // an execution per SHORT delay, but no more than one SHORT more
204 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
205 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
206 <        joinPool(p);
196 >        try {
197 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
198 >                long startTime = System.nanoTime();
199 >                int cycles = 10;
200 >                final CountDownLatch done = new CountDownLatch(cycles);
201 >                CheckedRunnable task = new CheckedRunnable() {
202 >                    public void realRun() { done.countDown(); }};
203 >                
204 >                ScheduledFuture h =
205 >                    p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
206 >                done.await();
207 >                h.cancel(true);
208 >                double normalizedTime =
209 >                    (double) millisElapsedSince(startTime) / delay;
210 >                if (normalizedTime >= cycles - 1 &&
211 >                    normalizedTime <= cycles)
212 >                    return;
213 >            }
214 >            throw new AssertionError("unexpected execution rate");
215 >        } finally {
216 >            joinPool(p);
217 >        }
218      }
219  
220      /**
# Line 211 | Line 222 | public class ScheduledExecutorSubclassTe
222       */
223      public void testFixedDelaySequence() throws InterruptedException {
224          CustomExecutor p = new CustomExecutor(1);
225 <        RunnableCounter counter = new RunnableCounter();
226 <        ScheduledFuture h =
227 <            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
228 <        delay(SMALL_DELAY_MS);
229 <        h.cancel(true);
230 <        int c = counter.count.get();
231 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
232 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
233 <        joinPool(p);
225 >        try {
226 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
227 >                long startTime = System.nanoTime();
228 >                int cycles = 10;
229 >                final CountDownLatch done = new CountDownLatch(cycles);
230 >                CheckedRunnable task = new CheckedRunnable() {
231 >                    public void realRun() { done.countDown(); }};
232 >                
233 >                ScheduledFuture h =
234 >                    p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
235 >                done.await();
236 >                h.cancel(true);
237 >                double normalizedTime =
238 >                    (double) millisElapsedSince(startTime) / delay;
239 >                if (normalizedTime >= cycles - 1 &&
240 >                    normalizedTime <= cycles)
241 >                    return;
242 >            }
243 >            throw new AssertionError("unexpected execution rate");
244 >        } finally {
245 >            joinPool(p);
246 >        }
247      }
248  
249      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines