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; |
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 |
|
/** |
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 |
|
/** |