3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
|
*/ |
6 |
+ |
import java.util.*; |
7 |
+ |
import java.util.concurrent.Executor; |
8 |
+ |
import java.util.concurrent.Executors; |
9 |
+ |
import java.util.concurrent.ExecutorService; |
10 |
+ |
import java.util.concurrent.AbstractExecutorService; |
11 |
+ |
import java.util.concurrent.CountDownLatch; |
12 |
+ |
import java.util.concurrent.Callable; |
13 |
+ |
import java.util.concurrent.Future; |
14 |
+ |
import java.util.concurrent.ExecutionException; |
15 |
+ |
import java.util.concurrent.CancellationException; |
16 |
+ |
import java.util.concurrent.RejectedExecutionException; |
17 |
+ |
import java.util.concurrent.ForkJoinPool; |
18 |
+ |
import java.util.concurrent.ForkJoinTask; |
19 |
+ |
import java.util.concurrent.ForkJoinWorkerThread; |
20 |
+ |
import java.util.concurrent.RecursiveAction; |
21 |
+ |
import java.util.concurrent.RecursiveTask; |
22 |
+ |
import java.util.concurrent.TimeUnit; |
23 |
|
import junit.framework.*; |
24 |
< |
import java.util.concurrent.*; |
24 |
> |
import java.util.concurrent.TimeUnit; |
25 |
|
import java.util.concurrent.atomic.*; |
26 |
|
import java.util.*; |
27 |
|
|
28 |
|
public class ForkJoinTaskTest extends JSR166TestCase { |
29 |
|
|
30 |
|
public static void main(String[] args) { |
31 |
< |
junit.textui.TestRunner.run (suite()); |
31 |
> |
junit.textui.TestRunner.run(suite()); |
32 |
|
} |
33 |
+ |
|
34 |
|
public static Test suite() { |
35 |
|
return new TestSuite(ForkJoinTaskTest.class); |
36 |
|
} |
45 |
|
|
46 |
|
static final ForkJoinPool mainPool = new ForkJoinPool(); |
47 |
|
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
48 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
49 |
< |
static { |
50 |
< |
asyncSingletonPool.setAsyncMode(true); |
33 |
< |
} |
34 |
< |
|
48 |
> |
static final ForkJoinPool asyncSingletonPool = |
49 |
> |
new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
50 |
> |
null, true); |
51 |
|
static final class FJException extends RuntimeException { |
52 |
|
FJException() { super(); } |
53 |
|
} |
164 |
|
|
165 |
|
} |
166 |
|
|
167 |
< |
static final class AsyncFib extends BinaryAsyncAction { |
167 |
> |
static final class AsyncFib extends BinaryAsyncAction { |
168 |
|
int number; |
169 |
|
public AsyncFib(int n) { |
170 |
|
this.number = n; |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
< |
static final class FailingAsyncFib extends BinaryAsyncAction { |
196 |
> |
static final class FailingAsyncFib extends BinaryAsyncAction { |
197 |
|
int number; |
198 |
|
public FailingAsyncFib(int n) { |
199 |
|
this.number = n; |
225 |
|
* invoke returns when task completes normally. |
226 |
|
* isCompletedAbnormally and isCancelled return false for normally |
227 |
|
* completed tasks. getRawResult of a RecursiveAction returns null; |
212 |
– |
* |
228 |
|
*/ |
229 |
|
public void testInvoke() { |
230 |
|
RecursiveAction a = new RecursiveAction() { |
231 |
< |
public void compute() { |
232 |
< |
AsyncFib f = new AsyncFib(8); |
233 |
< |
f.invoke(); |
234 |
< |
threadAssertTrue(f.number == 21); |
235 |
< |
threadAssertTrue(f.isDone()); |
236 |
< |
threadAssertFalse(f.isCancelled()); |
237 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
238 |
< |
threadAssertTrue(f.getRawResult() == null); |
239 |
< |
} |
225 |
< |
}; |
231 |
> |
public void compute() { |
232 |
> |
AsyncFib f = new AsyncFib(8); |
233 |
> |
f.invoke(); |
234 |
> |
threadAssertTrue(f.number == 21); |
235 |
> |
threadAssertTrue(f.isDone()); |
236 |
> |
threadAssertFalse(f.isCancelled()); |
237 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
238 |
> |
threadAssertTrue(f.getRawResult() == null); |
239 |
> |
}}; |
240 |
|
mainPool.invoke(a); |
241 |
|
} |
242 |
|
|
247 |
|
*/ |
248 |
|
public void testQuietlyInvoke() { |
249 |
|
RecursiveAction a = new RecursiveAction() { |
250 |
< |
public void compute() { |
251 |
< |
AsyncFib f = new AsyncFib(8); |
252 |
< |
f.quietlyInvoke(); |
253 |
< |
threadAssertTrue(f.number == 21); |
254 |
< |
threadAssertTrue(f.isDone()); |
255 |
< |
threadAssertFalse(f.isCancelled()); |
256 |
< |
threadAssertFalse(f.isCompletedAbnormally()); |
257 |
< |
threadAssertTrue(f.getRawResult() == null); |
258 |
< |
} |
245 |
< |
}; |
250 |
> |
public void compute() { |
251 |
> |
AsyncFib f = new AsyncFib(8); |
252 |
> |
f.quietlyInvoke(); |
253 |
> |
threadAssertTrue(f.number == 21); |
254 |
> |
threadAssertTrue(f.isDone()); |
255 |
> |
threadAssertFalse(f.isCancelled()); |
256 |
> |
threadAssertFalse(f.isCompletedAbnormally()); |
257 |
> |
threadAssertTrue(f.getRawResult() == null); |
258 |
> |
}}; |
259 |
|
mainPool.invoke(a); |
260 |
|
} |
261 |
|
|
264 |
|
*/ |
265 |
|
public void testForkJoin() { |
266 |
|
RecursiveAction a = new RecursiveAction() { |
267 |
< |
public void compute() { |
268 |
< |
AsyncFib f = new AsyncFib(8); |
269 |
< |
f.fork(); |
270 |
< |
f.join(); |
271 |
< |
threadAssertTrue(f.number == 21); |
272 |
< |
threadAssertTrue(f.isDone()); |
273 |
< |
threadAssertTrue(f.getRawResult() == null); |
274 |
< |
} |
262 |
< |
}; |
267 |
> |
public void compute() { |
268 |
> |
AsyncFib f = new AsyncFib(8); |
269 |
> |
f.fork(); |
270 |
> |
f.join(); |
271 |
> |
threadAssertTrue(f.number == 21); |
272 |
> |
threadAssertTrue(f.isDone()); |
273 |
> |
threadAssertTrue(f.getRawResult() == null); |
274 |
> |
}}; |
275 |
|
mainPool.invoke(a); |
276 |
|
} |
277 |
|
|
280 |
|
*/ |
281 |
|
public void testForkGet() { |
282 |
|
RecursiveAction a = new RecursiveAction() { |
283 |
< |
public void compute() { |
284 |
< |
try { |
285 |
< |
AsyncFib f = new AsyncFib(8); |
286 |
< |
f.fork(); |
287 |
< |
f.get(); |
288 |
< |
threadAssertTrue(f.number == 21); |
289 |
< |
threadAssertTrue(f.isDone()); |
290 |
< |
} catch (Exception ex) { |
291 |
< |
unexpectedException(ex); |
280 |
< |
} |
283 |
> |
public void compute() { |
284 |
> |
try { |
285 |
> |
AsyncFib f = new AsyncFib(8); |
286 |
> |
f.fork(); |
287 |
> |
f.get(); |
288 |
> |
threadAssertTrue(f.number == 21); |
289 |
> |
threadAssertTrue(f.isDone()); |
290 |
> |
} catch (Exception ex) { |
291 |
> |
unexpectedException(ex); |
292 |
|
} |
293 |
< |
}; |
293 |
> |
}}; |
294 |
|
mainPool.invoke(a); |
295 |
|
} |
296 |
|
|
299 |
|
*/ |
300 |
|
public void testForkTimedGet() { |
301 |
|
RecursiveAction a = new RecursiveAction() { |
302 |
< |
public void compute() { |
303 |
< |
try { |
293 |
< |
AsyncFib f = new AsyncFib(8); |
294 |
< |
f.fork(); |
295 |
< |
f.get(5L, TimeUnit.SECONDS); |
296 |
< |
threadAssertTrue(f.number == 21); |
297 |
< |
threadAssertTrue(f.isDone()); |
298 |
< |
} catch (Exception ex) { |
299 |
< |
unexpectedException(ex); |
300 |
< |
} |
301 |
< |
} |
302 |
< |
}; |
303 |
< |
mainPool.invoke(a); |
304 |
< |
} |
305 |
< |
|
306 |
< |
/** |
307 |
< |
* timed get with null time unit throws NPE |
308 |
< |
*/ |
309 |
< |
public void testForkTimedGetNPE() { |
310 |
< |
RecursiveAction a = new RecursiveAction() { |
311 |
< |
public void compute() { |
312 |
< |
try { |
313 |
< |
AsyncFib f = new AsyncFib(8); |
314 |
< |
f.fork(); |
315 |
< |
f.get(5L, null); |
316 |
< |
shouldThrow(); |
317 |
< |
} catch (NullPointerException success) { |
318 |
< |
} catch (Exception ex) { |
319 |
< |
unexpectedException(ex); |
320 |
< |
} |
321 |
< |
} |
322 |
< |
}; |
323 |
< |
mainPool.invoke(a); |
324 |
< |
} |
325 |
< |
|
326 |
< |
/** |
327 |
< |
* helpJoin of a forked task returns when task completes |
328 |
< |
*/ |
329 |
< |
public void testForkHelpJoin() { |
330 |
< |
RecursiveAction a = new RecursiveAction() { |
331 |
< |
public void compute() { |
302 |
> |
public void compute() { |
303 |
> |
try { |
304 |
|
AsyncFib f = new AsyncFib(8); |
305 |
|
f.fork(); |
306 |
< |
f.helpJoin(); |
306 |
> |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
307 |
|
threadAssertTrue(f.number == 21); |
308 |
|
threadAssertTrue(f.isDone()); |
309 |
+ |
} catch (Exception ex) { |
310 |
+ |
unexpectedException(ex); |
311 |
|
} |
312 |
< |
}; |
312 |
> |
}}; |
313 |
|
mainPool.invoke(a); |
314 |
|
} |
315 |
|
|
316 |
|
/** |
317 |
< |
* quietlyJoin of a forked task returns when task completes |
317 |
> |
* timed get with null time unit throws NPE |
318 |
|
*/ |
319 |
< |
public void testForkQuietlyJoin() { |
319 |
> |
public void testForkTimedGetNPE() { |
320 |
|
RecursiveAction a = new RecursiveAction() { |
321 |
< |
public void compute() { |
321 |
> |
public void compute() { |
322 |
> |
try { |
323 |
|
AsyncFib f = new AsyncFib(8); |
324 |
|
f.fork(); |
325 |
< |
f.quietlyJoin(); |
326 |
< |
threadAssertTrue(f.number == 21); |
327 |
< |
threadAssertTrue(f.isDone()); |
325 |
> |
f.get(5L, null); |
326 |
> |
shouldThrow(); |
327 |
> |
} catch (NullPointerException success) { |
328 |
> |
} catch (Exception ex) { |
329 |
> |
unexpectedException(ex); |
330 |
|
} |
331 |
< |
}; |
331 |
> |
}}; |
332 |
|
mainPool.invoke(a); |
333 |
|
} |
334 |
|
|
358 |
– |
|
335 |
|
/** |
336 |
< |
* quietlyHelpJoin of a forked task returns when task completes |
336 |
> |
* quietlyJoin of a forked task returns when task completes |
337 |
|
*/ |
338 |
< |
public void testForkQuietlyHelpJoin() { |
338 |
> |
public void testForkQuietlyJoin() { |
339 |
|
RecursiveAction a = new RecursiveAction() { |
340 |
< |
public void compute() { |
341 |
< |
AsyncFib f = new AsyncFib(8); |
342 |
< |
f.fork(); |
343 |
< |
f.quietlyHelpJoin(); |
344 |
< |
threadAssertTrue(f.number == 21); |
345 |
< |
threadAssertTrue(f.isDone()); |
346 |
< |
} |
371 |
< |
}; |
340 |
> |
public void compute() { |
341 |
> |
AsyncFib f = new AsyncFib(8); |
342 |
> |
f.fork(); |
343 |
> |
f.quietlyJoin(); |
344 |
> |
threadAssertTrue(f.number == 21); |
345 |
> |
threadAssertTrue(f.isDone()); |
346 |
> |
}}; |
347 |
|
mainPool.invoke(a); |
348 |
|
} |
349 |
|
|
354 |
|
*/ |
355 |
|
public void testForkHelpQuiesce() { |
356 |
|
RecursiveAction a = new RecursiveAction() { |
357 |
< |
public void compute() { |
358 |
< |
AsyncFib f = new AsyncFib(8); |
359 |
< |
f.fork(); |
360 |
< |
f.helpQuiesce(); |
361 |
< |
threadAssertTrue(f.number == 21); |
362 |
< |
threadAssertTrue(f.isDone()); |
363 |
< |
threadAssertTrue(getQueuedTaskCount() == 0); |
364 |
< |
} |
390 |
< |
}; |
357 |
> |
public void compute() { |
358 |
> |
AsyncFib f = new AsyncFib(8); |
359 |
> |
f.fork(); |
360 |
> |
f.helpQuiesce(); |
361 |
> |
threadAssertTrue(f.number == 21); |
362 |
> |
threadAssertTrue(f.isDone()); |
363 |
> |
threadAssertTrue(getQueuedTaskCount() == 0); |
364 |
> |
}}; |
365 |
|
mainPool.invoke(a); |
366 |
|
} |
367 |
|
|
371 |
|
*/ |
372 |
|
public void testAbnormalInvoke() { |
373 |
|
RecursiveAction a = new RecursiveAction() { |
374 |
< |
public void compute() { |
375 |
< |
try { |
376 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
377 |
< |
f.invoke(); |
378 |
< |
shouldThrow(); |
379 |
< |
} catch (FJException success) { |
406 |
< |
} |
374 |
> |
public void compute() { |
375 |
> |
try { |
376 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
377 |
> |
f.invoke(); |
378 |
> |
shouldThrow(); |
379 |
> |
} catch (FJException success) { |
380 |
|
} |
381 |
< |
}; |
381 |
> |
}}; |
382 |
|
mainPool.invoke(a); |
383 |
|
} |
384 |
|
|
387 |
|
*/ |
388 |
|
public void testAbnormalQuietlyInvoke() { |
389 |
|
RecursiveAction a = new RecursiveAction() { |
390 |
< |
public void compute() { |
391 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
392 |
< |
f.quietlyInvoke(); |
393 |
< |
threadAssertTrue(f.isDone()); |
394 |
< |
} |
422 |
< |
}; |
390 |
> |
public void compute() { |
391 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
392 |
> |
f.quietlyInvoke(); |
393 |
> |
threadAssertTrue(f.isDone()); |
394 |
> |
}}; |
395 |
|
mainPool.invoke(a); |
396 |
|
} |
397 |
|
|
400 |
|
*/ |
401 |
|
public void testAbnormalForkJoin() { |
402 |
|
RecursiveAction a = new RecursiveAction() { |
403 |
< |
public void compute() { |
404 |
< |
try { |
405 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
406 |
< |
f.fork(); |
407 |
< |
f.join(); |
408 |
< |
shouldThrow(); |
409 |
< |
} catch (FJException success) { |
438 |
< |
} |
403 |
> |
public void compute() { |
404 |
> |
try { |
405 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
406 |
> |
f.fork(); |
407 |
> |
f.join(); |
408 |
> |
shouldThrow(); |
409 |
> |
} catch (FJException success) { |
410 |
|
} |
411 |
< |
}; |
411 |
> |
}}; |
412 |
|
mainPool.invoke(a); |
413 |
|
} |
414 |
|
|
417 |
|
*/ |
418 |
|
public void testAbnormalForkGet() { |
419 |
|
RecursiveAction a = new RecursiveAction() { |
420 |
< |
public void compute() { |
421 |
< |
try { |
422 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
423 |
< |
f.fork(); |
424 |
< |
f.get(); |
425 |
< |
shouldThrow(); |
426 |
< |
} catch (ExecutionException success) { |
427 |
< |
} catch (Exception ex) { |
428 |
< |
unexpectedException(ex); |
458 |
< |
} |
420 |
> |
public void compute() { |
421 |
> |
try { |
422 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
423 |
> |
f.fork(); |
424 |
> |
f.get(); |
425 |
> |
shouldThrow(); |
426 |
> |
} catch (ExecutionException success) { |
427 |
> |
} catch (Exception ex) { |
428 |
> |
unexpectedException(ex); |
429 |
|
} |
430 |
< |
}; |
430 |
> |
}}; |
431 |
|
mainPool.invoke(a); |
432 |
|
} |
433 |
|
|
436 |
|
*/ |
437 |
|
public void testAbnormalForkTimedGet() { |
438 |
|
RecursiveAction a = new RecursiveAction() { |
439 |
< |
public void compute() { |
440 |
< |
try { |
471 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
472 |
< |
f.fork(); |
473 |
< |
f.get(5L, TimeUnit.SECONDS); |
474 |
< |
shouldThrow(); |
475 |
< |
} catch (ExecutionException success) { |
476 |
< |
} catch (Exception ex) { |
477 |
< |
unexpectedException(ex); |
478 |
< |
} |
479 |
< |
} |
480 |
< |
}; |
481 |
< |
mainPool.invoke(a); |
482 |
< |
} |
483 |
< |
|
484 |
< |
/** |
485 |
< |
* join of a forked task throws exception when task completes abnormally |
486 |
< |
*/ |
487 |
< |
public void testAbnormalForkHelpJoin() { |
488 |
< |
RecursiveAction a = new RecursiveAction() { |
489 |
< |
public void compute() { |
490 |
< |
try { |
491 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
492 |
< |
f.fork(); |
493 |
< |
f.helpJoin(); |
494 |
< |
shouldThrow(); |
495 |
< |
} catch (FJException success) { |
496 |
< |
} |
497 |
< |
} |
498 |
< |
}; |
499 |
< |
mainPool.invoke(a); |
500 |
< |
} |
501 |
< |
|
502 |
< |
/** |
503 |
< |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
504 |
< |
* getException of failed task returns its exception. |
505 |
< |
* isCompletedAbnormally of a failed task returns true. |
506 |
< |
* isCancelled of a failed uncancelled task returns false |
507 |
< |
*/ |
508 |
< |
public void testAbnormalForkQuietlyHelpJoin() { |
509 |
< |
RecursiveAction a = new RecursiveAction() { |
510 |
< |
public void compute() { |
439 |
> |
public void compute() { |
440 |
> |
try { |
441 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
442 |
|
f.fork(); |
443 |
< |
f.quietlyHelpJoin(); |
444 |
< |
threadAssertTrue(f.isDone()); |
445 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
446 |
< |
threadAssertFalse(f.isCancelled()); |
447 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
443 |
> |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
444 |
> |
shouldThrow(); |
445 |
> |
} catch (ExecutionException success) { |
446 |
> |
} catch (Exception ex) { |
447 |
> |
unexpectedException(ex); |
448 |
|
} |
449 |
< |
}; |
449 |
> |
}}; |
450 |
|
mainPool.invoke(a); |
451 |
|
} |
452 |
|
|
455 |
|
*/ |
456 |
|
public void testAbnormalForkQuietlyJoin() { |
457 |
|
RecursiveAction a = new RecursiveAction() { |
458 |
< |
public void compute() { |
459 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
460 |
< |
f.fork(); |
461 |
< |
f.quietlyJoin(); |
462 |
< |
threadAssertTrue(f.isDone()); |
463 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
464 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
465 |
< |
} |
536 |
< |
}; |
458 |
> |
public void compute() { |
459 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
460 |
> |
f.fork(); |
461 |
> |
f.quietlyJoin(); |
462 |
> |
threadAssertTrue(f.isDone()); |
463 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
464 |
> |
threadAssertTrue(f.getException() instanceof FJException); |
465 |
> |
}}; |
466 |
|
mainPool.invoke(a); |
467 |
|
} |
468 |
|
|
471 |
|
*/ |
472 |
|
public void testCancelledInvoke() { |
473 |
|
RecursiveAction a = new RecursiveAction() { |
474 |
< |
public void compute() { |
475 |
< |
try { |
476 |
< |
AsyncFib f = new AsyncFib(8); |
477 |
< |
f.cancel(true); |
478 |
< |
f.invoke(); |
479 |
< |
shouldThrow(); |
480 |
< |
} catch (CancellationException success) { |
552 |
< |
} |
474 |
> |
public void compute() { |
475 |
> |
try { |
476 |
> |
AsyncFib f = new AsyncFib(8); |
477 |
> |
f.cancel(true); |
478 |
> |
f.invoke(); |
479 |
> |
shouldThrow(); |
480 |
> |
} catch (CancellationException success) { |
481 |
|
} |
482 |
< |
}; |
482 |
> |
}}; |
483 |
|
mainPool.invoke(a); |
484 |
|
} |
485 |
|
|
488 |
|
*/ |
489 |
|
public void testCancelledForkJoin() { |
490 |
|
RecursiveAction a = new RecursiveAction() { |
491 |
< |
public void compute() { |
492 |
< |
try { |
493 |
< |
AsyncFib f = new AsyncFib(8); |
494 |
< |
f.cancel(true); |
495 |
< |
f.fork(); |
496 |
< |
f.join(); |
497 |
< |
shouldThrow(); |
498 |
< |
} catch (CancellationException success) { |
571 |
< |
} |
491 |
> |
public void compute() { |
492 |
> |
try { |
493 |
> |
AsyncFib f = new AsyncFib(8); |
494 |
> |
f.cancel(true); |
495 |
> |
f.fork(); |
496 |
> |
f.join(); |
497 |
> |
shouldThrow(); |
498 |
> |
} catch (CancellationException success) { |
499 |
|
} |
500 |
< |
}; |
500 |
> |
}}; |
501 |
|
mainPool.invoke(a); |
502 |
|
} |
503 |
|
|
506 |
|
*/ |
507 |
|
public void testCancelledForkGet() { |
508 |
|
RecursiveAction a = new RecursiveAction() { |
509 |
< |
public void compute() { |
510 |
< |
try { |
511 |
< |
AsyncFib f = new AsyncFib(8); |
512 |
< |
f.cancel(true); |
513 |
< |
f.fork(); |
514 |
< |
f.get(); |
515 |
< |
shouldThrow(); |
516 |
< |
} catch (CancellationException success) { |
517 |
< |
} catch (Exception ex) { |
518 |
< |
unexpectedException(ex); |
592 |
< |
} |
509 |
> |
public void compute() { |
510 |
> |
try { |
511 |
> |
AsyncFib f = new AsyncFib(8); |
512 |
> |
f.cancel(true); |
513 |
> |
f.fork(); |
514 |
> |
f.get(); |
515 |
> |
shouldThrow(); |
516 |
> |
} catch (CancellationException success) { |
517 |
> |
} catch (Exception ex) { |
518 |
> |
unexpectedException(ex); |
519 |
|
} |
520 |
< |
}; |
520 |
> |
}}; |
521 |
|
mainPool.invoke(a); |
522 |
|
} |
523 |
|
|
526 |
|
*/ |
527 |
|
public void testCancelledForkTimedGet() { |
528 |
|
RecursiveAction a = new RecursiveAction() { |
529 |
< |
public void compute() { |
530 |
< |
try { |
605 |
< |
AsyncFib f = new AsyncFib(8); |
606 |
< |
f.cancel(true); |
607 |
< |
f.fork(); |
608 |
< |
f.get(5L, TimeUnit.SECONDS); |
609 |
< |
shouldThrow(); |
610 |
< |
} catch (CancellationException success) { |
611 |
< |
} catch (Exception ex) { |
612 |
< |
unexpectedException(ex); |
613 |
< |
} |
614 |
< |
} |
615 |
< |
}; |
616 |
< |
mainPool.invoke(a); |
617 |
< |
} |
618 |
< |
|
619 |
< |
/** |
620 |
< |
* join of a forked task throws exception when task cancelled |
621 |
< |
*/ |
622 |
< |
public void testCancelledForkHelpJoin() { |
623 |
< |
RecursiveAction a = new RecursiveAction() { |
624 |
< |
public void compute() { |
625 |
< |
try { |
626 |
< |
AsyncFib f = new AsyncFib(8); |
627 |
< |
f.cancel(true); |
628 |
< |
f.fork(); |
629 |
< |
f.helpJoin(); |
630 |
< |
shouldThrow(); |
631 |
< |
} catch (CancellationException success) { |
632 |
< |
} |
633 |
< |
} |
634 |
< |
}; |
635 |
< |
mainPool.invoke(a); |
636 |
< |
} |
637 |
< |
|
638 |
< |
/** |
639 |
< |
* quietlyHelpJoin of a forked task returns when task cancelled. |
640 |
< |
* getException of cancelled task returns its exception. |
641 |
< |
* isCompletedAbnormally of a cancelled task returns true. |
642 |
< |
* isCancelled of a cancelled task returns true |
643 |
< |
*/ |
644 |
< |
public void testCancelledForkQuietlyHelpJoin() { |
645 |
< |
RecursiveAction a = new RecursiveAction() { |
646 |
< |
public void compute() { |
529 |
> |
public void compute() { |
530 |
> |
try { |
531 |
|
AsyncFib f = new AsyncFib(8); |
532 |
|
f.cancel(true); |
533 |
|
f.fork(); |
534 |
< |
f.quietlyHelpJoin(); |
535 |
< |
threadAssertTrue(f.isDone()); |
536 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
537 |
< |
threadAssertTrue(f.isCancelled()); |
538 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
534 |
> |
f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
535 |
> |
shouldThrow(); |
536 |
> |
} catch (CancellationException success) { |
537 |
> |
} catch (Exception ex) { |
538 |
> |
unexpectedException(ex); |
539 |
|
} |
540 |
< |
}; |
540 |
> |
}}; |
541 |
|
mainPool.invoke(a); |
542 |
|
} |
543 |
|
|
546 |
|
*/ |
547 |
|
public void testCancelledForkQuietlyJoin() { |
548 |
|
RecursiveAction a = new RecursiveAction() { |
549 |
< |
public void compute() { |
550 |
< |
AsyncFib f = new AsyncFib(8); |
551 |
< |
f.cancel(true); |
552 |
< |
f.fork(); |
553 |
< |
f.quietlyJoin(); |
554 |
< |
threadAssertTrue(f.isDone()); |
555 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
556 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
557 |
< |
} |
674 |
< |
}; |
549 |
> |
public void compute() { |
550 |
> |
AsyncFib f = new AsyncFib(8); |
551 |
> |
f.cancel(true); |
552 |
> |
f.fork(); |
553 |
> |
f.quietlyJoin(); |
554 |
> |
threadAssertTrue(f.isDone()); |
555 |
> |
threadAssertTrue(f.isCompletedAbnormally()); |
556 |
> |
threadAssertTrue(f.getException() instanceof CancellationException); |
557 |
> |
}}; |
558 |
|
mainPool.invoke(a); |
559 |
|
} |
560 |
|
|
563 |
|
*/ |
564 |
|
public void testGetPool() { |
565 |
|
RecursiveAction a = new RecursiveAction() { |
566 |
< |
public void compute() { |
567 |
< |
threadAssertTrue(getPool() == mainPool); |
568 |
< |
} |
686 |
< |
}; |
566 |
> |
public void compute() { |
567 |
> |
threadAssertTrue(getPool() == mainPool); |
568 |
> |
}}; |
569 |
|
mainPool.invoke(a); |
570 |
|
} |
571 |
|
|
574 |
|
*/ |
575 |
|
public void testGetPool2() { |
576 |
|
RecursiveAction a = new RecursiveAction() { |
577 |
< |
public void compute() { |
578 |
< |
threadAssertTrue(getPool() == null); |
579 |
< |
} |
698 |
< |
}; |
577 |
> |
public void compute() { |
578 |
> |
threadAssertTrue(getPool() == null); |
579 |
> |
}}; |
580 |
|
a.invoke(); |
581 |
|
} |
582 |
|
|
585 |
|
*/ |
586 |
|
public void testInForkJoinPool() { |
587 |
|
RecursiveAction a = new RecursiveAction() { |
588 |
< |
public void compute() { |
589 |
< |
threadAssertTrue(inForkJoinPool()); |
590 |
< |
} |
710 |
< |
}; |
588 |
> |
public void compute() { |
589 |
> |
threadAssertTrue(inForkJoinPool()); |
590 |
> |
}}; |
591 |
|
mainPool.invoke(a); |
592 |
|
} |
593 |
|
|
596 |
|
*/ |
597 |
|
public void testInForkJoinPool2() { |
598 |
|
RecursiveAction a = new RecursiveAction() { |
599 |
< |
public void compute() { |
600 |
< |
threadAssertTrue(!inForkJoinPool()); |
601 |
< |
} |
722 |
< |
}; |
599 |
> |
public void compute() { |
600 |
> |
threadAssertTrue(!inForkJoinPool()); |
601 |
> |
}}; |
602 |
|
a.invoke(); |
603 |
|
} |
604 |
|
|
607 |
|
*/ |
608 |
|
public void testSetRawResult() { |
609 |
|
RecursiveAction a = new RecursiveAction() { |
610 |
< |
public void compute() { |
611 |
< |
setRawResult(null); |
612 |
< |
} |
734 |
< |
}; |
610 |
> |
public void compute() { |
611 |
> |
setRawResult(null); |
612 |
> |
}}; |
613 |
|
a.invoke(); |
614 |
|
} |
615 |
|
|
618 |
|
*/ |
619 |
|
public void testCompleteExceptionally() { |
620 |
|
RecursiveAction a = new RecursiveAction() { |
621 |
< |
public void compute() { |
622 |
< |
try { |
623 |
< |
AsyncFib f = new AsyncFib(8); |
624 |
< |
f.completeExceptionally(new FJException()); |
625 |
< |
f.invoke(); |
626 |
< |
shouldThrow(); |
627 |
< |
} catch (FJException success) { |
750 |
< |
} |
621 |
> |
public void compute() { |
622 |
> |
try { |
623 |
> |
AsyncFib f = new AsyncFib(8); |
624 |
> |
f.completeExceptionally(new FJException()); |
625 |
> |
f.invoke(); |
626 |
> |
shouldThrow(); |
627 |
> |
} catch (FJException success) { |
628 |
|
} |
629 |
< |
}; |
629 |
> |
}}; |
630 |
|
mainPool.invoke(a); |
631 |
|
} |
632 |
|
|
635 |
|
*/ |
636 |
|
public void testInvokeAll2() { |
637 |
|
RecursiveAction a = new RecursiveAction() { |
638 |
< |
public void compute() { |
639 |
< |
AsyncFib f = new AsyncFib(8); |
640 |
< |
AsyncFib g = new AsyncFib(9); |
641 |
< |
invokeAll(f, g); |
642 |
< |
threadAssertTrue(f.isDone()); |
643 |
< |
threadAssertTrue(f.number == 21); |
644 |
< |
threadAssertTrue(g.isDone()); |
645 |
< |
threadAssertTrue(g.number == 34); |
646 |
< |
} |
770 |
< |
}; |
638 |
> |
public void compute() { |
639 |
> |
AsyncFib f = new AsyncFib(8); |
640 |
> |
AsyncFib g = new AsyncFib(9); |
641 |
> |
invokeAll(f, g); |
642 |
> |
threadAssertTrue(f.isDone()); |
643 |
> |
threadAssertTrue(f.number == 21); |
644 |
> |
threadAssertTrue(g.isDone()); |
645 |
> |
threadAssertTrue(g.number == 34); |
646 |
> |
}}; |
647 |
|
mainPool.invoke(a); |
648 |
|
} |
649 |
|
|
652 |
|
*/ |
653 |
|
public void testInvokeAll1() { |
654 |
|
RecursiveAction a = new RecursiveAction() { |
655 |
< |
public void compute() { |
656 |
< |
AsyncFib f = new AsyncFib(8); |
657 |
< |
invokeAll(f); |
658 |
< |
threadAssertTrue(f.isDone()); |
659 |
< |
threadAssertTrue(f.number == 21); |
660 |
< |
} |
785 |
< |
}; |
655 |
> |
public void compute() { |
656 |
> |
AsyncFib f = new AsyncFib(8); |
657 |
> |
invokeAll(f); |
658 |
> |
threadAssertTrue(f.isDone()); |
659 |
> |
threadAssertTrue(f.number == 21); |
660 |
> |
}}; |
661 |
|
mainPool.invoke(a); |
662 |
|
} |
663 |
|
|
666 |
|
*/ |
667 |
|
public void testInvokeAll3() { |
668 |
|
RecursiveAction a = new RecursiveAction() { |
669 |
< |
public void compute() { |
670 |
< |
AsyncFib f = new AsyncFib(8); |
671 |
< |
AsyncFib g = new AsyncFib(9); |
672 |
< |
AsyncFib h = new AsyncFib(7); |
673 |
< |
invokeAll(f, g, h); |
674 |
< |
threadAssertTrue(f.isDone()); |
675 |
< |
threadAssertTrue(f.number == 21); |
676 |
< |
threadAssertTrue(g.isDone()); |
677 |
< |
threadAssertTrue(g.number == 34); |
678 |
< |
threadAssertTrue(h.isDone()); |
679 |
< |
threadAssertTrue(h.number == 13); |
680 |
< |
} |
806 |
< |
}; |
669 |
> |
public void compute() { |
670 |
> |
AsyncFib f = new AsyncFib(8); |
671 |
> |
AsyncFib g = new AsyncFib(9); |
672 |
> |
AsyncFib h = new AsyncFib(7); |
673 |
> |
invokeAll(f, g, h); |
674 |
> |
threadAssertTrue(f.isDone()); |
675 |
> |
threadAssertTrue(f.number == 21); |
676 |
> |
threadAssertTrue(g.isDone()); |
677 |
> |
threadAssertTrue(g.number == 34); |
678 |
> |
threadAssertTrue(h.isDone()); |
679 |
> |
threadAssertTrue(h.number == 13); |
680 |
> |
}}; |
681 |
|
mainPool.invoke(a); |
682 |
|
} |
683 |
|
|
686 |
|
*/ |
687 |
|
public void testInvokeAllCollection() { |
688 |
|
RecursiveAction a = new RecursiveAction() { |
689 |
< |
public void compute() { |
690 |
< |
AsyncFib f = new AsyncFib(8); |
691 |
< |
AsyncFib g = new AsyncFib(9); |
692 |
< |
AsyncFib h = new AsyncFib(7); |
693 |
< |
HashSet set = new HashSet(); |
694 |
< |
set.add(f); |
695 |
< |
set.add(g); |
696 |
< |
set.add(h); |
697 |
< |
invokeAll(set); |
698 |
< |
threadAssertTrue(f.isDone()); |
699 |
< |
threadAssertTrue(f.number == 21); |
700 |
< |
threadAssertTrue(g.isDone()); |
701 |
< |
threadAssertTrue(g.number == 34); |
702 |
< |
threadAssertTrue(h.isDone()); |
703 |
< |
threadAssertTrue(h.number == 13); |
704 |
< |
} |
831 |
< |
}; |
689 |
> |
public void compute() { |
690 |
> |
AsyncFib f = new AsyncFib(8); |
691 |
> |
AsyncFib g = new AsyncFib(9); |
692 |
> |
AsyncFib h = new AsyncFib(7); |
693 |
> |
HashSet set = new HashSet(); |
694 |
> |
set.add(f); |
695 |
> |
set.add(g); |
696 |
> |
set.add(h); |
697 |
> |
invokeAll(set); |
698 |
> |
threadAssertTrue(f.isDone()); |
699 |
> |
threadAssertTrue(f.number == 21); |
700 |
> |
threadAssertTrue(g.isDone()); |
701 |
> |
threadAssertTrue(g.number == 34); |
702 |
> |
threadAssertTrue(h.isDone()); |
703 |
> |
threadAssertTrue(h.number == 13); |
704 |
> |
}}; |
705 |
|
mainPool.invoke(a); |
706 |
|
} |
707 |
|
|
711 |
|
*/ |
712 |
|
public void testInvokeAllNPE() { |
713 |
|
RecursiveAction a = new RecursiveAction() { |
714 |
< |
public void compute() { |
715 |
< |
try { |
716 |
< |
AsyncFib f = new AsyncFib(8); |
717 |
< |
AsyncFib g = new AsyncFib(9); |
718 |
< |
AsyncFib h = null; |
719 |
< |
invokeAll(f, g, h); |
720 |
< |
shouldThrow(); |
721 |
< |
} catch (NullPointerException success) { |
849 |
< |
} |
714 |
> |
public void compute() { |
715 |
> |
try { |
716 |
> |
AsyncFib f = new AsyncFib(8); |
717 |
> |
AsyncFib g = new AsyncFib(9); |
718 |
> |
AsyncFib h = null; |
719 |
> |
invokeAll(f, g, h); |
720 |
> |
shouldThrow(); |
721 |
> |
} catch (NullPointerException success) { |
722 |
|
} |
723 |
< |
}; |
723 |
> |
}}; |
724 |
|
mainPool.invoke(a); |
725 |
|
} |
726 |
|
|
729 |
|
*/ |
730 |
|
public void testAbnormalInvokeAll2() { |
731 |
|
RecursiveAction a = new RecursiveAction() { |
732 |
< |
public void compute() { |
733 |
< |
try { |
734 |
< |
AsyncFib f = new AsyncFib(8); |
735 |
< |
FailingAsyncFib g = new FailingAsyncFib(9); |
736 |
< |
invokeAll(f, g); |
737 |
< |
shouldThrow(); |
738 |
< |
} catch (FJException success) { |
867 |
< |
} |
732 |
> |
public void compute() { |
733 |
> |
try { |
734 |
> |
AsyncFib f = new AsyncFib(8); |
735 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
736 |
> |
invokeAll(f, g); |
737 |
> |
shouldThrow(); |
738 |
> |
} catch (FJException success) { |
739 |
|
} |
740 |
< |
}; |
740 |
> |
}}; |
741 |
|
mainPool.invoke(a); |
742 |
|
} |
743 |
|
|
746 |
|
*/ |
747 |
|
public void testAbnormalInvokeAll1() { |
748 |
|
RecursiveAction a = new RecursiveAction() { |
749 |
< |
public void compute() { |
750 |
< |
try { |
751 |
< |
FailingAsyncFib g = new FailingAsyncFib(9); |
752 |
< |
invokeAll(g); |
753 |
< |
shouldThrow(); |
754 |
< |
} catch (FJException success) { |
884 |
< |
} |
749 |
> |
public void compute() { |
750 |
> |
try { |
751 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
752 |
> |
invokeAll(g); |
753 |
> |
shouldThrow(); |
754 |
> |
} catch (FJException success) { |
755 |
|
} |
756 |
< |
}; |
756 |
> |
}}; |
757 |
|
mainPool.invoke(a); |
758 |
|
} |
759 |
|
|
762 |
|
*/ |
763 |
|
public void testAbnormalInvokeAll3() { |
764 |
|
RecursiveAction a = new RecursiveAction() { |
765 |
< |
public void compute() { |
766 |
< |
try { |
767 |
< |
AsyncFib f = new AsyncFib(8); |
768 |
< |
FailingAsyncFib g = new FailingAsyncFib(9); |
769 |
< |
AsyncFib h = new AsyncFib(7); |
770 |
< |
invokeAll(f, g, h); |
771 |
< |
shouldThrow(); |
772 |
< |
} catch (FJException success) { |
903 |
< |
} |
765 |
> |
public void compute() { |
766 |
> |
try { |
767 |
> |
AsyncFib f = new AsyncFib(8); |
768 |
> |
FailingAsyncFib g = new FailingAsyncFib(9); |
769 |
> |
AsyncFib h = new AsyncFib(7); |
770 |
> |
invokeAll(f, g, h); |
771 |
> |
shouldThrow(); |
772 |
> |
} catch (FJException success) { |
773 |
|
} |
774 |
< |
}; |
774 |
> |
}}; |
775 |
|
mainPool.invoke(a); |
776 |
|
} |
777 |
|
|
780 |
|
*/ |
781 |
|
public void testAbnormalInvokeAllCollection() { |
782 |
|
RecursiveAction a = new RecursiveAction() { |
783 |
< |
public void compute() { |
784 |
< |
try { |
785 |
< |
FailingAsyncFib f = new FailingAsyncFib(8); |
786 |
< |
AsyncFib g = new AsyncFib(9); |
787 |
< |
AsyncFib h = new AsyncFib(7); |
788 |
< |
HashSet set = new HashSet(); |
789 |
< |
set.add(f); |
790 |
< |
set.add(g); |
791 |
< |
set.add(h); |
792 |
< |
invokeAll(set); |
793 |
< |
shouldThrow(); |
794 |
< |
} catch (FJException success) { |
926 |
< |
} |
783 |
> |
public void compute() { |
784 |
> |
try { |
785 |
> |
FailingAsyncFib f = new FailingAsyncFib(8); |
786 |
> |
AsyncFib g = new AsyncFib(9); |
787 |
> |
AsyncFib h = new AsyncFib(7); |
788 |
> |
HashSet set = new HashSet(); |
789 |
> |
set.add(f); |
790 |
> |
set.add(g); |
791 |
> |
set.add(h); |
792 |
> |
invokeAll(set); |
793 |
> |
shouldThrow(); |
794 |
> |
} catch (FJException success) { |
795 |
|
} |
796 |
< |
}; |
796 |
> |
}}; |
797 |
|
mainPool.invoke(a); |
798 |
|
} |
799 |
|
|
803 |
|
*/ |
804 |
|
public void testTryUnfork() { |
805 |
|
RecursiveAction a = new RecursiveAction() { |
806 |
< |
public void compute() { |
807 |
< |
AsyncFib g = new AsyncFib(9); |
808 |
< |
g.fork(); |
809 |
< |
AsyncFib f = new AsyncFib(8); |
810 |
< |
f.fork(); |
811 |
< |
threadAssertTrue(f.tryUnfork()); |
812 |
< |
helpQuiesce(); |
813 |
< |
threadAssertFalse(f.isDone()); |
814 |
< |
threadAssertTrue(g.isDone()); |
815 |
< |
} |
948 |
< |
}; |
806 |
> |
public void compute() { |
807 |
> |
AsyncFib g = new AsyncFib(9); |
808 |
> |
g.fork(); |
809 |
> |
AsyncFib f = new AsyncFib(8); |
810 |
> |
f.fork(); |
811 |
> |
threadAssertTrue(f.tryUnfork()); |
812 |
> |
helpQuiesce(); |
813 |
> |
threadAssertFalse(f.isDone()); |
814 |
> |
threadAssertTrue(g.isDone()); |
815 |
> |
}}; |
816 |
|
singletonPool.invoke(a); |
817 |
|
} |
818 |
|
|
822 |
|
*/ |
823 |
|
public void testGetSurplusQueuedTaskCount() { |
824 |
|
RecursiveAction a = new RecursiveAction() { |
825 |
< |
public void compute() { |
826 |
< |
AsyncFib h = new AsyncFib(7); |
827 |
< |
h.fork(); |
828 |
< |
AsyncFib g = new AsyncFib(9); |
829 |
< |
g.fork(); |
830 |
< |
AsyncFib f = new AsyncFib(8); |
831 |
< |
f.fork(); |
832 |
< |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
833 |
< |
helpQuiesce(); |
834 |
< |
} |
968 |
< |
}; |
825 |
> |
public void compute() { |
826 |
> |
AsyncFib h = new AsyncFib(7); |
827 |
> |
h.fork(); |
828 |
> |
AsyncFib g = new AsyncFib(9); |
829 |
> |
g.fork(); |
830 |
> |
AsyncFib f = new AsyncFib(8); |
831 |
> |
f.fork(); |
832 |
> |
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
833 |
> |
helpQuiesce(); |
834 |
> |
}}; |
835 |
|
singletonPool.invoke(a); |
836 |
|
} |
837 |
|
|
840 |
|
*/ |
841 |
|
public void testPeekNextLocalTask() { |
842 |
|
RecursiveAction a = new RecursiveAction() { |
843 |
< |
public void compute() { |
844 |
< |
AsyncFib g = new AsyncFib(9); |
845 |
< |
g.fork(); |
846 |
< |
AsyncFib f = new AsyncFib(8); |
847 |
< |
f.fork(); |
848 |
< |
threadAssertTrue(peekNextLocalTask() == f); |
849 |
< |
f.join(); |
850 |
< |
threadAssertTrue(f.isDone()); |
851 |
< |
helpQuiesce(); |
852 |
< |
} |
987 |
< |
}; |
843 |
> |
public void compute() { |
844 |
> |
AsyncFib g = new AsyncFib(9); |
845 |
> |
g.fork(); |
846 |
> |
AsyncFib f = new AsyncFib(8); |
847 |
> |
f.fork(); |
848 |
> |
threadAssertTrue(peekNextLocalTask() == f); |
849 |
> |
f.join(); |
850 |
> |
threadAssertTrue(f.isDone()); |
851 |
> |
helpQuiesce(); |
852 |
> |
}}; |
853 |
|
singletonPool.invoke(a); |
854 |
|
} |
855 |
|
|
859 |
|
*/ |
860 |
|
public void testPollNextLocalTask() { |
861 |
|
RecursiveAction a = new RecursiveAction() { |
862 |
< |
public void compute() { |
863 |
< |
AsyncFib g = new AsyncFib(9); |
864 |
< |
g.fork(); |
865 |
< |
AsyncFib f = new AsyncFib(8); |
866 |
< |
f.fork(); |
867 |
< |
threadAssertTrue(pollNextLocalTask() == f); |
868 |
< |
helpQuiesce(); |
869 |
< |
threadAssertFalse(f.isDone()); |
870 |
< |
} |
1006 |
< |
}; |
862 |
> |
public void compute() { |
863 |
> |
AsyncFib g = new AsyncFib(9); |
864 |
> |
g.fork(); |
865 |
> |
AsyncFib f = new AsyncFib(8); |
866 |
> |
f.fork(); |
867 |
> |
threadAssertTrue(pollNextLocalTask() == f); |
868 |
> |
helpQuiesce(); |
869 |
> |
threadAssertFalse(f.isDone()); |
870 |
> |
}}; |
871 |
|
singletonPool.invoke(a); |
872 |
|
} |
873 |
|
|
877 |
|
*/ |
878 |
|
public void testPollTask() { |
879 |
|
RecursiveAction a = new RecursiveAction() { |
880 |
< |
public void compute() { |
881 |
< |
AsyncFib g = new AsyncFib(9); |
882 |
< |
g.fork(); |
883 |
< |
AsyncFib f = new AsyncFib(8); |
884 |
< |
f.fork(); |
885 |
< |
threadAssertTrue(pollTask() == f); |
886 |
< |
helpQuiesce(); |
887 |
< |
threadAssertFalse(f.isDone()); |
888 |
< |
threadAssertTrue(g.isDone()); |
889 |
< |
} |
1026 |
< |
}; |
880 |
> |
public void compute() { |
881 |
> |
AsyncFib g = new AsyncFib(9); |
882 |
> |
g.fork(); |
883 |
> |
AsyncFib f = new AsyncFib(8); |
884 |
> |
f.fork(); |
885 |
> |
threadAssertTrue(pollTask() == f); |
886 |
> |
helpQuiesce(); |
887 |
> |
threadAssertFalse(f.isDone()); |
888 |
> |
threadAssertTrue(g.isDone()); |
889 |
> |
}}; |
890 |
|
singletonPool.invoke(a); |
891 |
|
} |
892 |
|
|
895 |
|
*/ |
896 |
|
public void testPeekNextLocalTaskAsync() { |
897 |
|
RecursiveAction a = new RecursiveAction() { |
898 |
< |
public void compute() { |
899 |
< |
AsyncFib g = new AsyncFib(9); |
900 |
< |
g.fork(); |
901 |
< |
AsyncFib f = new AsyncFib(8); |
902 |
< |
f.fork(); |
903 |
< |
threadAssertTrue(peekNextLocalTask() == g); |
904 |
< |
f.join(); |
905 |
< |
helpQuiesce(); |
906 |
< |
threadAssertTrue(f.isDone()); |
907 |
< |
} |
1045 |
< |
}; |
898 |
> |
public void compute() { |
899 |
> |
AsyncFib g = new AsyncFib(9); |
900 |
> |
g.fork(); |
901 |
> |
AsyncFib f = new AsyncFib(8); |
902 |
> |
f.fork(); |
903 |
> |
threadAssertTrue(peekNextLocalTask() == g); |
904 |
> |
f.join(); |
905 |
> |
helpQuiesce(); |
906 |
> |
threadAssertTrue(f.isDone()); |
907 |
> |
}}; |
908 |
|
asyncSingletonPool.invoke(a); |
909 |
|
} |
910 |
|
|
914 |
|
*/ |
915 |
|
public void testPollNextLocalTaskAsync() { |
916 |
|
RecursiveAction a = new RecursiveAction() { |
917 |
< |
public void compute() { |
918 |
< |
AsyncFib g = new AsyncFib(9); |
919 |
< |
g.fork(); |
920 |
< |
AsyncFib f = new AsyncFib(8); |
921 |
< |
f.fork(); |
922 |
< |
threadAssertTrue(pollNextLocalTask() == g); |
923 |
< |
helpQuiesce(); |
924 |
< |
threadAssertTrue(f.isDone()); |
925 |
< |
threadAssertFalse(g.isDone()); |
926 |
< |
} |
1065 |
< |
}; |
917 |
> |
public void compute() { |
918 |
> |
AsyncFib g = new AsyncFib(9); |
919 |
> |
g.fork(); |
920 |
> |
AsyncFib f = new AsyncFib(8); |
921 |
> |
f.fork(); |
922 |
> |
threadAssertTrue(pollNextLocalTask() == g); |
923 |
> |
helpQuiesce(); |
924 |
> |
threadAssertTrue(f.isDone()); |
925 |
> |
threadAssertFalse(g.isDone()); |
926 |
> |
}}; |
927 |
|
asyncSingletonPool.invoke(a); |
928 |
|
} |
929 |
|
|
933 |
|
*/ |
934 |
|
public void testPollTaskAsync() { |
935 |
|
RecursiveAction a = new RecursiveAction() { |
936 |
< |
public void compute() { |
937 |
< |
AsyncFib g = new AsyncFib(9); |
938 |
< |
g.fork(); |
939 |
< |
AsyncFib f = new AsyncFib(8); |
940 |
< |
f.fork(); |
941 |
< |
threadAssertTrue(pollTask() == g); |
942 |
< |
helpQuiesce(); |
943 |
< |
threadAssertTrue(f.isDone()); |
944 |
< |
threadAssertFalse(g.isDone()); |
945 |
< |
} |
1085 |
< |
}; |
936 |
> |
public void compute() { |
937 |
> |
AsyncFib g = new AsyncFib(9); |
938 |
> |
g.fork(); |
939 |
> |
AsyncFib f = new AsyncFib(8); |
940 |
> |
f.fork(); |
941 |
> |
threadAssertTrue(pollTask() == g); |
942 |
> |
helpQuiesce(); |
943 |
> |
threadAssertTrue(f.isDone()); |
944 |
> |
threadAssertFalse(g.isDone()); |
945 |
> |
}}; |
946 |
|
asyncSingletonPool.invoke(a); |
947 |
|
} |
948 |
|
} |