251 |
|
} |
252 |
|
|
253 |
|
/** |
254 |
< |
* After invoking a single task, isQuiescent is true, |
255 |
< |
* queues are empty, threads are not active, and |
256 |
< |
* construction parameters continue to hold |
254 |
> |
* After invoking a single task, isQuiescent eventually becomes |
255 |
> |
* true, at which time queues are empty, threads are not active, |
256 |
> |
* the task has completed successfully, and construction |
257 |
> |
* parameters continue to hold |
258 |
|
*/ |
259 |
< |
public void testisQuiescent() throws InterruptedException { |
259 |
> |
public void testisQuiescent() throws Exception { |
260 |
|
ForkJoinPool p = new ForkJoinPool(2); |
261 |
|
try { |
262 |
|
assertTrue(p.isQuiescent()); |
263 |
< |
p.invoke(new FibTask(20)); |
263 |
> |
long startTime = System.nanoTime(); |
264 |
> |
FibTask f = new FibTask(20); |
265 |
> |
p.invoke(f); |
266 |
|
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
267 |
|
p.getFactory()); |
268 |
< |
delay(SMALL_DELAY_MS); |
268 |
> |
while (! p.isQuiescent()) { |
269 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
270 |
> |
throw new AssertionFailedError("timed out"); |
271 |
> |
assertFalse(p.getAsyncMode()); |
272 |
> |
assertFalse(p.isShutdown()); |
273 |
> |
assertFalse(p.isTerminating()); |
274 |
> |
assertFalse(p.isTerminated()); |
275 |
> |
Thread.yield(); |
276 |
> |
} |
277 |
> |
|
278 |
|
assertTrue(p.isQuiescent()); |
279 |
|
assertFalse(p.getAsyncMode()); |
280 |
|
assertEquals(0, p.getActiveThreadCount()); |
284 |
|
assertFalse(p.isShutdown()); |
285 |
|
assertFalse(p.isTerminating()); |
286 |
|
assertFalse(p.isTerminated()); |
287 |
+ |
assertTrue(f.isDone()); |
288 |
+ |
assertEquals(6765, (int) f.get()); |
289 |
|
} finally { |
290 |
|
joinPool(p); |
291 |
|
} |