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.29 by jsr166, Fri Jun 10 19:45:01 2011 UTC vs.
Revision 1.33 by jsr166, Wed Sep 25 07:39:17 2013 UTC

# Line 36 | Line 36 | public class ScheduledExecutorSubclassTe
36          }
37          public boolean isCancelled() { return task.isCancelled(); }
38          public boolean isDone() { return task.isDone(); }
39 <        public V get() throws InterruptedException,  ExecutionException {
39 >        public V get() throws InterruptedException, ExecutionException {
40              V v = task.get();
41              assertTrue(ran);
42              return v;
43          }
44 <        public V get(long time, TimeUnit unit) throws InterruptedException,  ExecutionException, TimeoutException {
44 >        public V get(long time, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
45              V v = task.get(time, unit);
46              assertTrue(ran);
47              return v;
# 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 >                Runnable task = new CheckedRunnable() {
202 >                    public void realRun() { done.countDown(); }};
203 >                ScheduledFuture h =
204 >                    p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
205 >                done.await();
206 >                h.cancel(true);
207 >                double normalizedTime =
208 >                    (double) millisElapsedSince(startTime) / delay;
209 >                if (normalizedTime >= cycles - 1 &&
210 >                    normalizedTime <= cycles)
211 >                    return;
212 >            }
213 >            throw new AssertionError("unexpected execution rate");
214 >        } finally {
215 >            joinPool(p);
216 >        }
217      }
218  
219      /**
# Line 211 | Line 221 | public class ScheduledExecutorSubclassTe
221       */
222      public void testFixedDelaySequence() throws InterruptedException {
223          CustomExecutor p = new CustomExecutor(1);
224 <        RunnableCounter counter = new RunnableCounter();
225 <        ScheduledFuture h =
226 <            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
227 <        delay(SMALL_DELAY_MS);
228 <        h.cancel(true);
229 <        int c = counter.count.get();
230 <        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
231 <        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
232 <        joinPool(p);
224 >        try {
225 >            for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
226 >                long startTime = System.nanoTime();
227 >                int cycles = 10;
228 >                final CountDownLatch done = new CountDownLatch(cycles);
229 >                Runnable task = new CheckedRunnable() {
230 >                    public void realRun() { done.countDown(); }};
231 >                ScheduledFuture h =
232 >                    p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
233 >                done.await();
234 >                h.cancel(true);
235 >                double normalizedTime =
236 >                    (double) millisElapsedSince(startTime) / delay;
237 >                if (normalizedTime >= cycles - 1 &&
238 >                    normalizedTime <= cycles)
239 >                    return;
240 >            }
241 >            throw new AssertionError("unexpected execution rate");
242 >        } finally {
243 >            joinPool(p);
244 >        }
245      }
246  
247      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines