1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
164 |
|
try { |
165 |
|
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
166 |
|
p.getFactory()); |
167 |
– |
assertTrue(p.isQuiescent()); |
167 |
|
assertFalse(p.getAsyncMode()); |
168 |
|
assertEquals(0, p.getActiveThreadCount()); |
169 |
|
assertEquals(0, p.getStealCount()); |
198 |
|
} catch (NullPointerException success) {} |
199 |
|
} |
200 |
|
|
202 |
– |
|
201 |
|
/** |
202 |
|
* getParallelism returns size set in constructor |
203 |
|
*/ |
250 |
|
} |
251 |
|
|
252 |
|
/** |
253 |
< |
* After invoking a single task, isQuiescent is true, |
254 |
< |
* queues are empty, threads are not active, and |
255 |
< |
* construction parameters continue to hold |
253 |
> |
* After invoking a single task, isQuiescent eventually becomes |
254 |
> |
* true, at which time queues are empty, threads are not active, |
255 |
> |
* the task has completed successfully, and construction |
256 |
> |
* parameters continue to hold |
257 |
|
*/ |
258 |
< |
public void testisQuiescent() throws InterruptedException { |
258 |
> |
public void testisQuiescent() throws Exception { |
259 |
|
ForkJoinPool p = new ForkJoinPool(2); |
260 |
|
try { |
261 |
|
assertTrue(p.isQuiescent()); |
262 |
< |
p.invoke(new FibTask(20)); |
262 |
> |
long startTime = System.nanoTime(); |
263 |
> |
FibTask f = new FibTask(20); |
264 |
> |
p.invoke(f); |
265 |
|
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
266 |
|
p.getFactory()); |
267 |
< |
Thread.sleep(SMALL_DELAY_MS); |
267 |
> |
while (! p.isQuiescent()) { |
268 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
269 |
> |
throw new AssertionFailedError("timed out"); |
270 |
> |
assertFalse(p.getAsyncMode()); |
271 |
> |
assertFalse(p.isShutdown()); |
272 |
> |
assertFalse(p.isTerminating()); |
273 |
> |
assertFalse(p.isTerminated()); |
274 |
> |
Thread.yield(); |
275 |
> |
} |
276 |
> |
|
277 |
|
assertTrue(p.isQuiescent()); |
278 |
|
assertFalse(p.getAsyncMode()); |
279 |
|
assertEquals(0, p.getActiveThreadCount()); |
283 |
|
assertFalse(p.isShutdown()); |
284 |
|
assertFalse(p.isTerminating()); |
285 |
|
assertFalse(p.isTerminated()); |
286 |
+ |
assertTrue(f.isDone()); |
287 |
+ |
assertEquals(6765, (int) f.get()); |
288 |
|
} finally { |
289 |
|
joinPool(p); |
290 |
|
} |
378 |
|
} |
379 |
|
} |
380 |
|
|
369 |
– |
|
381 |
|
// FJ Versions of AbstractExecutorService tests |
382 |
|
|
383 |
|
/** |
399 |
|
} |
400 |
|
} |
401 |
|
|
391 |
– |
|
402 |
|
/** |
403 |
|
* Completed submit(callable) returns result |
404 |
|
*/ |
517 |
|
} |
518 |
|
} |
519 |
|
|
510 |
– |
|
520 |
|
/** |
521 |
|
* submit(null callable) throws NullPointerException |
522 |
|
*/ |
531 |
|
} |
532 |
|
} |
533 |
|
|
525 |
– |
|
534 |
|
/** |
535 |
|
* submit(callable).get() throws InterruptedException if interrupted |
536 |
|
*/ |
759 |
|
} |
760 |
|
} |
761 |
|
|
754 |
– |
|
762 |
|
/** |
763 |
|
* timed invokeAny(null) throws NullPointerException |
764 |
|
*/ |