ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinTaskTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.7 by jsr166, Tue Dec 1 23:01:44 2009 UTC vs.
Revision 1.15 by jsr166, Mon Sep 13 20:48:58 2010 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5   */
6 + import java.util.concurrent.ExecutionException;
7 + import java.util.concurrent.CancellationException;
8 + import java.util.concurrent.ForkJoinPool;
9 + import java.util.concurrent.ForkJoinTask;
10 + import java.util.concurrent.ForkJoinWorkerThread;
11 + import java.util.concurrent.RecursiveAction;
12 + import java.util.concurrent.TimeUnit;
13 + import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
14 + import java.util.HashSet;
15   import junit.framework.*;
7 import java.util.concurrent.*;
8 import java.util.concurrent.atomic.*;
9 import java.util.*;
16  
17   public class ForkJoinTaskTest extends JSR166TestCase {
18  
19      public static void main(String[] args) {
20 <        junit.textui.TestRunner.run (suite());
20 >        junit.textui.TestRunner.run(suite());
21      }
22 +
23      public static Test suite() {
24          return new TestSuite(ForkJoinTaskTest.class);
25      }
26  
27 <    /**
27 >    private static ForkJoinPool mainPool() {
28 >        return new ForkJoinPool();
29 >    }
30 >
31 >    private static ForkJoinPool singletonPool() {
32 >        return new ForkJoinPool(1);
33 >    }
34 >
35 >    private static ForkJoinPool asyncSingletonPool() {
36 >        return new ForkJoinPool(1,
37 >                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
38 >                                null, true);
39 >    }
40 >
41 >    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
42 >        try {
43 >            assertTrue(pool.invoke(a) == null);
44 >        } finally {
45 >            joinPool(pool);
46 >        }
47 >    }
48 >
49 >    /*
50       * Testing coverage notes:
51       *
52       * To test extension methods and overrides, most tests use
# Line 25 | Line 54 | public class ForkJoinTaskTest extends JS
54       * differently than supplied Recursive forms.
55       */
56  
28    static final ForkJoinPool mainPool = new ForkJoinPool();
29    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
30    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
31    static {
32        asyncSingletonPool.setAsyncMode(true);
33    }
34
57      static final class FJException extends RuntimeException {
58          FJException() { super(); }
59      }
# Line 209 | Line 231 | public class ForkJoinTaskTest extends JS
231       * invoke returns when task completes normally.
232       * isCompletedAbnormally and isCancelled return false for normally
233       * completed tasks. getRawResult of a RecursiveAction returns null;
212     *
234       */
235      public void testInvoke() {
236          RecursiveAction a = new RecursiveAction() {
237 <                public void compute() {
238 <                    AsyncFib f = new AsyncFib(8);
239 <                    f.invoke();
240 <                    threadAssertTrue(f.number == 21);
241 <                    threadAssertTrue(f.isDone());
242 <                    threadAssertFalse(f.isCancelled());
243 <                    threadAssertFalse(f.isCompletedAbnormally());
244 <                    threadAssertTrue(f.getRawResult() == null);
245 <                }
246 <            };
226 <        mainPool.invoke(a);
237 >            public void compute() {
238 >                AsyncFib f = new AsyncFib(8);
239 >                f.invoke();
240 >                threadAssertTrue(f.number == 21);
241 >                threadAssertTrue(f.isDone());
242 >                threadAssertFalse(f.isCancelled());
243 >                threadAssertFalse(f.isCompletedAbnormally());
244 >                threadAssertTrue(f.getRawResult() == null);
245 >            }};
246 >        testInvokeOnPool(mainPool(), a);
247      }
248  
249      /**
# Line 233 | Line 253 | public class ForkJoinTaskTest extends JS
253       */
254      public void testQuietlyInvoke() {
255          RecursiveAction a = new RecursiveAction() {
256 <                public void compute() {
257 <                    AsyncFib f = new AsyncFib(8);
258 <                    f.quietlyInvoke();
259 <                    threadAssertTrue(f.number == 21);
260 <                    threadAssertTrue(f.isDone());
261 <                    threadAssertFalse(f.isCancelled());
262 <                    threadAssertFalse(f.isCompletedAbnormally());
263 <                    threadAssertTrue(f.getRawResult() == null);
264 <                }
265 <            };
246 <        mainPool.invoke(a);
256 >            public void compute() {
257 >                AsyncFib f = new AsyncFib(8);
258 >                f.quietlyInvoke();
259 >                threadAssertTrue(f.number == 21);
260 >                threadAssertTrue(f.isDone());
261 >                threadAssertFalse(f.isCancelled());
262 >                threadAssertFalse(f.isCompletedAbnormally());
263 >                threadAssertTrue(f.getRawResult() == null);
264 >            }};
265 >        testInvokeOnPool(mainPool(), a);
266      }
267  
268      /**
# Line 251 | Line 270 | public class ForkJoinTaskTest extends JS
270       */
271      public void testForkJoin() {
272          RecursiveAction a = new RecursiveAction() {
273 <                public void compute() {
274 <                    AsyncFib f = new AsyncFib(8);
275 <                    f.fork();
276 <                    f.join();
277 <                    threadAssertTrue(f.number == 21);
278 <                    threadAssertTrue(f.isDone());
279 <                    threadAssertTrue(f.getRawResult() == null);
280 <                }
281 <            };
263 <        mainPool.invoke(a);
273 >            public void compute() {
274 >                AsyncFib f = new AsyncFib(8);
275 >                f.fork();
276 >                f.join();
277 >                threadAssertTrue(f.number == 21);
278 >                threadAssertTrue(f.isDone());
279 >                threadAssertTrue(f.getRawResult() == null);
280 >            }};
281 >        testInvokeOnPool(mainPool(), a);
282      }
283  
284      /**
# Line 268 | Line 286 | public class ForkJoinTaskTest extends JS
286       */
287      public void testForkGet() {
288          RecursiveAction a = new RecursiveAction() {
289 <                public void compute() {
290 <                    try {
291 <                        AsyncFib f = new AsyncFib(8);
292 <                        f.fork();
293 <                        f.get();
294 <                        threadAssertTrue(f.number == 21);
295 <                        threadAssertTrue(f.isDone());
296 <                    } catch (Exception ex) {
297 <                        unexpectedException(ex);
280 <                    }
289 >            public void compute() {
290 >                try {
291 >                    AsyncFib f = new AsyncFib(8);
292 >                    f.fork();
293 >                    f.get();
294 >                    threadAssertTrue(f.number == 21);
295 >                    threadAssertTrue(f.isDone());
296 >                } catch (Exception ex) {
297 >                    unexpectedException(ex);
298                  }
299 <            };
300 <        mainPool.invoke(a);
299 >            }};
300 >        testInvokeOnPool(mainPool(), a);
301      }
302  
303      /**
# Line 288 | Line 305 | public class ForkJoinTaskTest extends JS
305       */
306      public void testForkTimedGet() {
307          RecursiveAction a = new RecursiveAction() {
308 <                public void compute() {
309 <                    try {
293 <                        AsyncFib f = new AsyncFib(8);
294 <                        f.fork();
295 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
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() {
308 >            public void compute() {
309 >                try {
310                      AsyncFib f = new AsyncFib(8);
311                      f.fork();
312 <                    f.helpJoin();
312 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
313                      threadAssertTrue(f.number == 21);
314                      threadAssertTrue(f.isDone());
315 +                } catch (Exception ex) {
316 +                    unexpectedException(ex);
317                  }
318 <            };
319 <        mainPool.invoke(a);
318 >            }};
319 >        testInvokeOnPool(mainPool(), a);
320      }
321  
322      /**
323 <     * quietlyJoin of a forked task returns when task completes
323 >     * timed get with null time unit throws NPE
324       */
325 <    public void testForkQuietlyJoin() {
325 >    public void testForkTimedGetNPE() {
326          RecursiveAction a = new RecursiveAction() {
327 <                public void compute() {
327 >            public void compute() {
328 >                try {
329                      AsyncFib f = new AsyncFib(8);
330                      f.fork();
331 <                    f.quietlyJoin();
332 <                    threadAssertTrue(f.number == 21);
333 <                    threadAssertTrue(f.isDone());
331 >                    f.get(5L, null);
332 >                    shouldThrow();
333 >                } catch (NullPointerException success) {
334 >                } catch (Exception ex) {
335 >                    unexpectedException(ex);
336                  }
337 <            };
338 <        mainPool.invoke(a);
337 >            }};
338 >        testInvokeOnPool(mainPool(), a);
339      }
340  
358
341      /**
342 <     * quietlyHelpJoin of a forked task returns when task completes
342 >     * quietlyJoin of a forked task returns when task completes
343       */
344 <    public void testForkQuietlyHelpJoin() {
344 >    public void testForkQuietlyJoin() {
345          RecursiveAction a = new RecursiveAction() {
346 <                public void compute() {
347 <                    AsyncFib f = new AsyncFib(8);
348 <                    f.fork();
349 <                    f.quietlyHelpJoin();
350 <                    threadAssertTrue(f.number == 21);
351 <                    threadAssertTrue(f.isDone());
352 <                }
353 <            };
372 <        mainPool.invoke(a);
346 >            public void compute() {
347 >                AsyncFib f = new AsyncFib(8);
348 >                f.fork();
349 >                f.quietlyJoin();
350 >                threadAssertTrue(f.number == 21);
351 >                threadAssertTrue(f.isDone());
352 >            }};
353 >        testInvokeOnPool(mainPool(), a);
354      }
355  
356  
# Line 379 | Line 360 | public class ForkJoinTaskTest extends JS
360       */
361      public void testForkHelpQuiesce() {
362          RecursiveAction a = new RecursiveAction() {
363 <                public void compute() {
364 <                    AsyncFib f = new AsyncFib(8);
365 <                    f.fork();
366 <                    f.helpQuiesce();
367 <                    threadAssertTrue(f.number == 21);
368 <                    threadAssertTrue(f.isDone());
369 <                    threadAssertTrue(getQueuedTaskCount() == 0);
370 <                }
371 <            };
391 <        mainPool.invoke(a);
363 >            public void compute() {
364 >                AsyncFib f = new AsyncFib(8);
365 >                f.fork();
366 >                f.helpQuiesce();
367 >                threadAssertTrue(f.number == 21);
368 >                threadAssertTrue(f.isDone());
369 >                threadAssertTrue(getQueuedTaskCount() == 0);
370 >            }};
371 >        testInvokeOnPool(mainPool(), a);
372      }
373  
374  
# Line 397 | Line 377 | public class ForkJoinTaskTest extends JS
377       */
378      public void testAbnormalInvoke() {
379          RecursiveAction a = new RecursiveAction() {
380 <                public void compute() {
381 <                    try {
382 <                        FailingAsyncFib f = new FailingAsyncFib(8);
383 <                        f.invoke();
384 <                        shouldThrow();
385 <                    } catch (FJException success) {
406 <                    }
380 >            public void compute() {
381 >                try {
382 >                    FailingAsyncFib f = new FailingAsyncFib(8);
383 >                    f.invoke();
384 >                    shouldThrow();
385 >                } catch (FJException success) {
386                  }
387 <            };
388 <        mainPool.invoke(a);
387 >            }};
388 >        testInvokeOnPool(mainPool(), a);
389      }
390  
391      /**
# Line 414 | Line 393 | public class ForkJoinTaskTest extends JS
393       */
394      public void testAbnormalQuietlyInvoke() {
395          RecursiveAction a = new RecursiveAction() {
396 <                public void compute() {
397 <                    FailingAsyncFib f = new FailingAsyncFib(8);
398 <                    f.quietlyInvoke();
399 <                    threadAssertTrue(f.isDone());
400 <                }
401 <            };
423 <        mainPool.invoke(a);
396 >            public void compute() {
397 >                FailingAsyncFib f = new FailingAsyncFib(8);
398 >                f.quietlyInvoke();
399 >                threadAssertTrue(f.isDone());
400 >            }};
401 >        testInvokeOnPool(mainPool(), a);
402      }
403  
404      /**
# Line 428 | Line 406 | public class ForkJoinTaskTest extends JS
406       */
407      public void testAbnormalForkJoin() {
408          RecursiveAction a = new RecursiveAction() {
409 <                public void compute() {
410 <                    try {
411 <                        FailingAsyncFib f = new FailingAsyncFib(8);
412 <                        f.fork();
413 <                        f.join();
414 <                        shouldThrow();
415 <                    } catch (FJException success) {
438 <                    }
409 >            public void compute() {
410 >                try {
411 >                    FailingAsyncFib f = new FailingAsyncFib(8);
412 >                    f.fork();
413 >                    f.join();
414 >                    shouldThrow();
415 >                } catch (FJException success) {
416                  }
417 <            };
418 <        mainPool.invoke(a);
417 >            }};
418 >        testInvokeOnPool(mainPool(), a);
419      }
420  
421      /**
# Line 446 | Line 423 | public class ForkJoinTaskTest extends JS
423       */
424      public void testAbnormalForkGet() {
425          RecursiveAction a = new RecursiveAction() {
426 <                public void compute() {
427 <                    try {
428 <                        FailingAsyncFib f = new FailingAsyncFib(8);
429 <                        f.fork();
430 <                        f.get();
431 <                        shouldThrow();
432 <                    } catch (ExecutionException success) {
433 <                    } catch (Exception ex) {
434 <                        unexpectedException(ex);
458 <                    }
426 >            public void compute() {
427 >                try {
428 >                    FailingAsyncFib f = new FailingAsyncFib(8);
429 >                    f.fork();
430 >                    f.get();
431 >                    shouldThrow();
432 >                } catch (ExecutionException success) {
433 >                } catch (Exception ex) {
434 >                    unexpectedException(ex);
435                  }
436 <            };
437 <        mainPool.invoke(a);
436 >            }};
437 >        testInvokeOnPool(mainPool(), a);
438      }
439  
440      /**
# Line 466 | Line 442 | public class ForkJoinTaskTest extends JS
442       */
443      public void testAbnormalForkTimedGet() {
444          RecursiveAction a = new RecursiveAction() {
445 <                public void compute() {
446 <                    try {
471 <                        FailingAsyncFib f = new FailingAsyncFib(8);
472 <                        f.fork();
473 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
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() {
445 >            public void compute() {
446 >                try {
447                      FailingAsyncFib f = new FailingAsyncFib(8);
448                      f.fork();
449 <                    f.quietlyHelpJoin();
450 <                    threadAssertTrue(f.isDone());
451 <                    threadAssertTrue(f.isCompletedAbnormally());
452 <                    threadAssertFalse(f.isCancelled());
453 <                    threadAssertTrue(f.getException() instanceof FJException);
449 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
450 >                    shouldThrow();
451 >                } catch (ExecutionException success) {
452 >                } catch (Exception ex) {
453 >                    unexpectedException(ex);
454                  }
455 <            };
456 <        mainPool.invoke(a);
455 >            }};
456 >        testInvokeOnPool(mainPool(), a);
457      }
458  
459      /**
# Line 525 | Line 461 | public class ForkJoinTaskTest extends JS
461       */
462      public void testAbnormalForkQuietlyJoin() {
463          RecursiveAction a = new RecursiveAction() {
464 <                public void compute() {
465 <                    FailingAsyncFib f = new FailingAsyncFib(8);
466 <                    f.fork();
467 <                    f.quietlyJoin();
468 <                    threadAssertTrue(f.isDone());
469 <                    threadAssertTrue(f.isCompletedAbnormally());
470 <                    threadAssertTrue(f.getException() instanceof FJException);
471 <                }
472 <            };
537 <        mainPool.invoke(a);
464 >            public void compute() {
465 >                FailingAsyncFib f = new FailingAsyncFib(8);
466 >                f.fork();
467 >                f.quietlyJoin();
468 >                threadAssertTrue(f.isDone());
469 >                threadAssertTrue(f.isCompletedAbnormally());
470 >                threadAssertTrue(f.getException() instanceof FJException);
471 >            }};
472 >        testInvokeOnPool(mainPool(), a);
473      }
474  
475      /**
# Line 542 | Line 477 | public class ForkJoinTaskTest extends JS
477       */
478      public void testCancelledInvoke() {
479          RecursiveAction a = new RecursiveAction() {
480 <                public void compute() {
481 <                    try {
482 <                        AsyncFib f = new AsyncFib(8);
483 <                        f.cancel(true);
484 <                        f.invoke();
485 <                        shouldThrow();
486 <                    } catch (CancellationException success) {
552 <                    }
480 >            public void compute() {
481 >                try {
482 >                    AsyncFib f = new AsyncFib(8);
483 >                    f.cancel(true);
484 >                    f.invoke();
485 >                    shouldThrow();
486 >                } catch (CancellationException success) {
487                  }
488 <            };
489 <        mainPool.invoke(a);
488 >            }};
489 >        testInvokeOnPool(mainPool(), a);
490      }
491  
492      /**
# Line 560 | Line 494 | public class ForkJoinTaskTest extends JS
494       */
495      public void testCancelledForkJoin() {
496          RecursiveAction a = new RecursiveAction() {
497 <                public void compute() {
498 <                    try {
499 <                        AsyncFib f = new AsyncFib(8);
500 <                        f.cancel(true);
501 <                        f.fork();
502 <                        f.join();
503 <                        shouldThrow();
504 <                    } catch (CancellationException success) {
571 <                    }
497 >            public void compute() {
498 >                try {
499 >                    AsyncFib f = new AsyncFib(8);
500 >                    f.cancel(true);
501 >                    f.fork();
502 >                    f.join();
503 >                    shouldThrow();
504 >                } catch (CancellationException success) {
505                  }
506 <            };
507 <        mainPool.invoke(a);
506 >            }};
507 >        testInvokeOnPool(mainPool(), a);
508      }
509  
510      /**
# Line 579 | Line 512 | public class ForkJoinTaskTest extends JS
512       */
513      public void testCancelledForkGet() {
514          RecursiveAction a = new RecursiveAction() {
515 <                public void compute() {
516 <                    try {
517 <                        AsyncFib f = new AsyncFib(8);
518 <                        f.cancel(true);
519 <                        f.fork();
520 <                        f.get();
521 <                        shouldThrow();
522 <                    } catch (CancellationException success) {
523 <                    } catch (Exception ex) {
524 <                        unexpectedException(ex);
592 <                    }
515 >            public void compute() {
516 >                try {
517 >                    AsyncFib f = new AsyncFib(8);
518 >                    f.cancel(true);
519 >                    f.fork();
520 >                    f.get();
521 >                    shouldThrow();
522 >                } catch (CancellationException success) {
523 >                } catch (Exception ex) {
524 >                    unexpectedException(ex);
525                  }
526 <            };
527 <        mainPool.invoke(a);
526 >            }};
527 >        testInvokeOnPool(mainPool(), a);
528      }
529  
530      /**
# Line 600 | Line 532 | public class ForkJoinTaskTest extends JS
532       */
533      public void testCancelledForkTimedGet() {
534          RecursiveAction a = new RecursiveAction() {
535 <                public void compute() {
536 <                    try {
605 <                        AsyncFib f = new AsyncFib(8);
606 <                        f.cancel(true);
607 <                        f.fork();
608 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
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() {
535 >            public void compute() {
536 >                try {
537                      AsyncFib f = new AsyncFib(8);
538                      f.cancel(true);
539                      f.fork();
540 <                    f.quietlyHelpJoin();
541 <                    threadAssertTrue(f.isDone());
542 <                    threadAssertTrue(f.isCompletedAbnormally());
543 <                    threadAssertTrue(f.isCancelled());
544 <                    threadAssertTrue(f.getException() instanceof CancellationException);
540 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
541 >                    shouldThrow();
542 >                } catch (CancellationException success) {
543 >                } catch (Exception ex) {
544 >                    unexpectedException(ex);
545                  }
546 <            };
547 <        mainPool.invoke(a);
546 >            }};
547 >        testInvokeOnPool(mainPool(), a);
548      }
549  
550      /**
# Line 662 | Line 552 | public class ForkJoinTaskTest extends JS
552       */
553      public void testCancelledForkQuietlyJoin() {
554          RecursiveAction a = new RecursiveAction() {
555 <                public void compute() {
556 <                    AsyncFib f = new AsyncFib(8);
557 <                    f.cancel(true);
558 <                    f.fork();
559 <                    f.quietlyJoin();
560 <                    threadAssertTrue(f.isDone());
561 <                    threadAssertTrue(f.isCompletedAbnormally());
562 <                    threadAssertTrue(f.getException() instanceof CancellationException);
563 <                }
564 <            };
675 <        mainPool.invoke(a);
555 >            public void compute() {
556 >                AsyncFib f = new AsyncFib(8);
557 >                f.cancel(true);
558 >                f.fork();
559 >                f.quietlyJoin();
560 >                threadAssertTrue(f.isDone());
561 >                threadAssertTrue(f.isCompletedAbnormally());
562 >                threadAssertTrue(f.getException() instanceof CancellationException);
563 >            }};
564 >        testInvokeOnPool(mainPool(), a);
565      }
566  
567      /**
568       * getPool of executing task returns its pool
569       */
570      public void testGetPool() {
571 +        final ForkJoinPool mainPool = mainPool();
572          RecursiveAction a = new RecursiveAction() {
573 <                public void compute() {
574 <                    threadAssertTrue(getPool() == mainPool);
575 <                }
576 <            };
687 <        mainPool.invoke(a);
573 >            public void compute() {
574 >                threadAssertTrue(getPool() == mainPool);
575 >            }};
576 >        testInvokeOnPool(mainPool, a);
577      }
578  
579      /**
# Line 692 | Line 581 | public class ForkJoinTaskTest extends JS
581       */
582      public void testGetPool2() {
583          RecursiveAction a = new RecursiveAction() {
584 <                public void compute() {
585 <                    threadAssertTrue(getPool() == null);
586 <                }
698 <            };
584 >            public void compute() {
585 >                threadAssertTrue(getPool() == null);
586 >            }};
587          a.invoke();
588      }
589  
# Line 704 | Line 592 | public class ForkJoinTaskTest extends JS
592       */
593      public void testInForkJoinPool() {
594          RecursiveAction a = new RecursiveAction() {
595 <                public void compute() {
596 <                    threadAssertTrue(inForkJoinPool());
597 <                }
598 <            };
711 <        mainPool.invoke(a);
595 >            public void compute() {
596 >                threadAssertTrue(inForkJoinPool());
597 >            }};
598 >        testInvokeOnPool(mainPool(), a);
599      }
600  
601      /**
# Line 716 | Line 603 | public class ForkJoinTaskTest extends JS
603       */
604      public void testInForkJoinPool2() {
605          RecursiveAction a = new RecursiveAction() {
606 <                public void compute() {
607 <                    threadAssertTrue(!inForkJoinPool());
608 <                }
722 <            };
606 >            public void compute() {
607 >                threadAssertTrue(!inForkJoinPool());
608 >            }};
609          a.invoke();
610      }
611  
# Line 728 | Line 614 | public class ForkJoinTaskTest extends JS
614       */
615      public void testSetRawResult() {
616          RecursiveAction a = new RecursiveAction() {
617 <                public void compute() {
618 <                    setRawResult(null);
619 <                }
734 <            };
617 >            public void compute() {
618 >                setRawResult(null);
619 >            }};
620          a.invoke();
621      }
622  
# Line 740 | Line 625 | public class ForkJoinTaskTest extends JS
625       */
626      public void testCompleteExceptionally() {
627          RecursiveAction a = new RecursiveAction() {
628 <                public void compute() {
629 <                    try {
630 <                        AsyncFib f = new AsyncFib(8);
631 <                        f.completeExceptionally(new FJException());
632 <                        f.invoke();
633 <                        shouldThrow();
634 <                    } catch (FJException success) {
750 <                    }
628 >            public void compute() {
629 >                try {
630 >                    AsyncFib f = new AsyncFib(8);
631 >                    f.completeExceptionally(new FJException());
632 >                    f.invoke();
633 >                    shouldThrow();
634 >                } catch (FJException success) {
635                  }
636 <            };
637 <        mainPool.invoke(a);
636 >            }};
637 >        testInvokeOnPool(mainPool(), a);
638      }
639  
640      /**
# Line 758 | Line 642 | public class ForkJoinTaskTest extends JS
642       */
643      public void testInvokeAll2() {
644          RecursiveAction a = new RecursiveAction() {
645 <                public void compute() {
646 <                    AsyncFib f = new AsyncFib(8);
647 <                    AsyncFib g = new AsyncFib(9);
648 <                    invokeAll(f, g);
649 <                    threadAssertTrue(f.isDone());
650 <                    threadAssertTrue(f.number == 21);
651 <                    threadAssertTrue(g.isDone());
652 <                    threadAssertTrue(g.number == 34);
653 <                }
654 <            };
771 <        mainPool.invoke(a);
645 >            public void compute() {
646 >                AsyncFib f = new AsyncFib(8);
647 >                AsyncFib g = new AsyncFib(9);
648 >                invokeAll(f, g);
649 >                threadAssertTrue(f.isDone());
650 >                threadAssertTrue(f.number == 21);
651 >                threadAssertTrue(g.isDone());
652 >                threadAssertTrue(g.number == 34);
653 >            }};
654 >        testInvokeOnPool(mainPool(), a);
655      }
656  
657      /**
# Line 776 | Line 659 | public class ForkJoinTaskTest extends JS
659       */
660      public void testInvokeAll1() {
661          RecursiveAction a = new RecursiveAction() {
662 <                public void compute() {
663 <                    AsyncFib f = new AsyncFib(8);
664 <                    invokeAll(f);
665 <                    threadAssertTrue(f.isDone());
666 <                    threadAssertTrue(f.number == 21);
667 <                }
668 <            };
786 <        mainPool.invoke(a);
662 >            public void compute() {
663 >                AsyncFib f = new AsyncFib(8);
664 >                invokeAll(f);
665 >                threadAssertTrue(f.isDone());
666 >                threadAssertTrue(f.number == 21);
667 >            }};
668 >        testInvokeOnPool(mainPool(), a);
669      }
670  
671      /**
# Line 791 | Line 673 | public class ForkJoinTaskTest extends JS
673       */
674      public void testInvokeAll3() {
675          RecursiveAction a = new RecursiveAction() {
676 <                public void compute() {
677 <                    AsyncFib f = new AsyncFib(8);
678 <                    AsyncFib g = new AsyncFib(9);
679 <                    AsyncFib h = new AsyncFib(7);
680 <                    invokeAll(f, g, h);
681 <                    threadAssertTrue(f.isDone());
682 <                    threadAssertTrue(f.number == 21);
683 <                    threadAssertTrue(g.isDone());
684 <                    threadAssertTrue(g.number == 34);
685 <                    threadAssertTrue(h.isDone());
686 <                    threadAssertTrue(h.number == 13);
687 <                }
688 <            };
807 <        mainPool.invoke(a);
676 >            public void compute() {
677 >                AsyncFib f = new AsyncFib(8);
678 >                AsyncFib g = new AsyncFib(9);
679 >                AsyncFib h = new AsyncFib(7);
680 >                invokeAll(f, g, h);
681 >                threadAssertTrue(f.isDone());
682 >                threadAssertTrue(f.number == 21);
683 >                threadAssertTrue(g.isDone());
684 >                threadAssertTrue(g.number == 34);
685 >                threadAssertTrue(h.isDone());
686 >                threadAssertTrue(h.number == 13);
687 >            }};
688 >        testInvokeOnPool(mainPool(), a);
689      }
690  
691      /**
# Line 812 | Line 693 | public class ForkJoinTaskTest extends JS
693       */
694      public void testInvokeAllCollection() {
695          RecursiveAction a = new RecursiveAction() {
696 <                public void compute() {
697 <                    AsyncFib f = new AsyncFib(8);
698 <                    AsyncFib g = new AsyncFib(9);
699 <                    AsyncFib h = new AsyncFib(7);
700 <                    HashSet set = new HashSet();
701 <                    set.add(f);
702 <                    set.add(g);
703 <                    set.add(h);
704 <                    invokeAll(set);
705 <                    threadAssertTrue(f.isDone());
706 <                    threadAssertTrue(f.number == 21);
707 <                    threadAssertTrue(g.isDone());
708 <                    threadAssertTrue(g.number == 34);
709 <                    threadAssertTrue(h.isDone());
710 <                    threadAssertTrue(h.number == 13);
711 <                }
712 <            };
832 <        mainPool.invoke(a);
696 >            public void compute() {
697 >                AsyncFib f = new AsyncFib(8);
698 >                AsyncFib g = new AsyncFib(9);
699 >                AsyncFib h = new AsyncFib(7);
700 >                HashSet set = new HashSet();
701 >                set.add(f);
702 >                set.add(g);
703 >                set.add(h);
704 >                invokeAll(set);
705 >                threadAssertTrue(f.isDone());
706 >                threadAssertTrue(f.number == 21);
707 >                threadAssertTrue(g.isDone());
708 >                threadAssertTrue(g.number == 34);
709 >                threadAssertTrue(h.isDone());
710 >                threadAssertTrue(h.number == 13);
711 >            }};
712 >        testInvokeOnPool(mainPool(), a);
713      }
714  
715  
# Line 838 | Line 718 | public class ForkJoinTaskTest extends JS
718       */
719      public void testInvokeAllNPE() {
720          RecursiveAction a = new RecursiveAction() {
721 <                public void compute() {
722 <                    try {
723 <                        AsyncFib f = new AsyncFib(8);
724 <                        AsyncFib g = new AsyncFib(9);
725 <                        AsyncFib h = null;
726 <                        invokeAll(f, g, h);
727 <                        shouldThrow();
728 <                    } catch (NullPointerException success) {
849 <                    }
721 >            public void compute() {
722 >                try {
723 >                    AsyncFib f = new AsyncFib(8);
724 >                    AsyncFib g = new AsyncFib(9);
725 >                    AsyncFib h = null;
726 >                    invokeAll(f, g, h);
727 >                    shouldThrow();
728 >                } catch (NullPointerException success) {
729                  }
730 <            };
731 <        mainPool.invoke(a);
730 >            }};
731 >        testInvokeOnPool(mainPool(), a);
732      }
733  
734      /**
# Line 857 | Line 736 | public class ForkJoinTaskTest extends JS
736       */
737      public void testAbnormalInvokeAll2() {
738          RecursiveAction a = new RecursiveAction() {
739 <                public void compute() {
740 <                    try {
741 <                        AsyncFib f = new AsyncFib(8);
742 <                        FailingAsyncFib g = new FailingAsyncFib(9);
743 <                        invokeAll(f, g);
744 <                        shouldThrow();
745 <                    } catch (FJException success) {
867 <                    }
739 >            public void compute() {
740 >                try {
741 >                    AsyncFib f = new AsyncFib(8);
742 >                    FailingAsyncFib g = new FailingAsyncFib(9);
743 >                    invokeAll(f, g);
744 >                    shouldThrow();
745 >                } catch (FJException success) {
746                  }
747 <            };
748 <        mainPool.invoke(a);
747 >            }};
748 >        testInvokeOnPool(mainPool(), a);
749      }
750  
751      /**
# Line 875 | Line 753 | public class ForkJoinTaskTest extends JS
753       */
754      public void testAbnormalInvokeAll1() {
755          RecursiveAction a = new RecursiveAction() {
756 <                public void compute() {
757 <                    try {
758 <                        FailingAsyncFib g = new FailingAsyncFib(9);
759 <                        invokeAll(g);
760 <                        shouldThrow();
761 <                    } catch (FJException success) {
884 <                    }
756 >            public void compute() {
757 >                try {
758 >                    FailingAsyncFib g = new FailingAsyncFib(9);
759 >                    invokeAll(g);
760 >                    shouldThrow();
761 >                } catch (FJException success) {
762                  }
763 <            };
764 <        mainPool.invoke(a);
763 >            }};
764 >        testInvokeOnPool(mainPool(), a);
765      }
766  
767      /**
# Line 892 | Line 769 | public class ForkJoinTaskTest extends JS
769       */
770      public void testAbnormalInvokeAll3() {
771          RecursiveAction a = new RecursiveAction() {
772 <                public void compute() {
773 <                    try {
774 <                        AsyncFib f = new AsyncFib(8);
775 <                        FailingAsyncFib g = new FailingAsyncFib(9);
776 <                        AsyncFib h = new AsyncFib(7);
777 <                        invokeAll(f, g, h);
778 <                        shouldThrow();
779 <                    } catch (FJException success) {
903 <                    }
772 >            public void compute() {
773 >                try {
774 >                    AsyncFib f = new AsyncFib(8);
775 >                    FailingAsyncFib g = new FailingAsyncFib(9);
776 >                    AsyncFib h = new AsyncFib(7);
777 >                    invokeAll(f, g, h);
778 >                    shouldThrow();
779 >                } catch (FJException success) {
780                  }
781 <            };
782 <        mainPool.invoke(a);
781 >            }};
782 >        testInvokeOnPool(mainPool(), a);
783      }
784  
785      /**
# Line 911 | Line 787 | public class ForkJoinTaskTest extends JS
787       */
788      public void testAbnormalInvokeAllCollection() {
789          RecursiveAction a = new RecursiveAction() {
790 <                public void compute() {
791 <                    try {
792 <                        FailingAsyncFib f = new FailingAsyncFib(8);
793 <                        AsyncFib g = new AsyncFib(9);
794 <                        AsyncFib h = new AsyncFib(7);
795 <                        HashSet set = new HashSet();
796 <                        set.add(f);
797 <                        set.add(g);
798 <                        set.add(h);
799 <                        invokeAll(set);
800 <                        shouldThrow();
801 <                    } catch (FJException success) {
926 <                    }
790 >            public void compute() {
791 >                try {
792 >                    FailingAsyncFib f = new FailingAsyncFib(8);
793 >                    AsyncFib g = new AsyncFib(9);
794 >                    AsyncFib h = new AsyncFib(7);
795 >                    HashSet set = new HashSet();
796 >                    set.add(f);
797 >                    set.add(g);
798 >                    set.add(h);
799 >                    invokeAll(set);
800 >                    shouldThrow();
801 >                } catch (FJException success) {
802                  }
803 <            };
804 <        mainPool.invoke(a);
803 >            }};
804 >        testInvokeOnPool(mainPool(), a);
805      }
806  
807      /**
# Line 935 | Line 810 | public class ForkJoinTaskTest extends JS
810       */
811      public void testTryUnfork() {
812          RecursiveAction a = new RecursiveAction() {
813 <                public void compute() {
814 <                    AsyncFib g = new AsyncFib(9);
815 <                    g.fork();
816 <                    AsyncFib f = new AsyncFib(8);
817 <                    f.fork();
818 <                    threadAssertTrue(f.tryUnfork());
819 <                    helpQuiesce();
820 <                    threadAssertFalse(f.isDone());
821 <                    threadAssertTrue(g.isDone());
822 <                }
823 <            };
949 <        singletonPool.invoke(a);
813 >            public void compute() {
814 >                AsyncFib g = new AsyncFib(9);
815 >                g.fork();
816 >                AsyncFib f = new AsyncFib(8);
817 >                f.fork();
818 >                threadAssertTrue(f.tryUnfork());
819 >                helpQuiesce();
820 >                threadAssertFalse(f.isDone());
821 >                threadAssertTrue(g.isDone());
822 >            }};
823 >        testInvokeOnPool(singletonPool(), a);
824      }
825  
826      /**
# Line 955 | Line 829 | public class ForkJoinTaskTest extends JS
829       */
830      public void testGetSurplusQueuedTaskCount() {
831          RecursiveAction a = new RecursiveAction() {
832 <                public void compute() {
833 <                    AsyncFib h = new AsyncFib(7);
834 <                    h.fork();
835 <                    AsyncFib g = new AsyncFib(9);
836 <                    g.fork();
837 <                    AsyncFib f = new AsyncFib(8);
838 <                    f.fork();
839 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
840 <                    helpQuiesce();
841 <                }
842 <            };
969 <        singletonPool.invoke(a);
832 >            public void compute() {
833 >                AsyncFib h = new AsyncFib(7);
834 >                h.fork();
835 >                AsyncFib g = new AsyncFib(9);
836 >                g.fork();
837 >                AsyncFib f = new AsyncFib(8);
838 >                f.fork();
839 >                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
840 >                helpQuiesce();
841 >            }};
842 >        testInvokeOnPool(singletonPool(), a);
843      }
844  
845      /**
# Line 974 | Line 847 | public class ForkJoinTaskTest extends JS
847       */
848      public void testPeekNextLocalTask() {
849          RecursiveAction a = new RecursiveAction() {
850 <                public void compute() {
851 <                    AsyncFib g = new AsyncFib(9);
852 <                    g.fork();
853 <                    AsyncFib f = new AsyncFib(8);
854 <                    f.fork();
855 <                    threadAssertTrue(peekNextLocalTask() == f);
856 <                    f.join();
857 <                    threadAssertTrue(f.isDone());
858 <                    helpQuiesce();
859 <                }
860 <            };
988 <        singletonPool.invoke(a);
850 >            public void compute() {
851 >                AsyncFib g = new AsyncFib(9);
852 >                g.fork();
853 >                AsyncFib f = new AsyncFib(8);
854 >                f.fork();
855 >                threadAssertTrue(peekNextLocalTask() == f);
856 >                f.join();
857 >                threadAssertTrue(f.isDone());
858 >                helpQuiesce();
859 >            }};
860 >        testInvokeOnPool(singletonPool(), a);
861      }
862  
863      /**
# Line 994 | Line 866 | public class ForkJoinTaskTest extends JS
866       */
867      public void testPollNextLocalTask() {
868          RecursiveAction a = new RecursiveAction() {
869 <                public void compute() {
870 <                    AsyncFib g = new AsyncFib(9);
871 <                    g.fork();
872 <                    AsyncFib f = new AsyncFib(8);
873 <                    f.fork();
874 <                    threadAssertTrue(pollNextLocalTask() == f);
875 <                    helpQuiesce();
876 <                    threadAssertFalse(f.isDone());
877 <                }
878 <            };
1007 <        singletonPool.invoke(a);
869 >            public void compute() {
870 >                AsyncFib g = new AsyncFib(9);
871 >                g.fork();
872 >                AsyncFib f = new AsyncFib(8);
873 >                f.fork();
874 >                threadAssertTrue(pollNextLocalTask() == f);
875 >                helpQuiesce();
876 >                threadAssertFalse(f.isDone());
877 >            }};
878 >        testInvokeOnPool(singletonPool(), a);
879      }
880  
881      /**
# Line 1013 | Line 884 | public class ForkJoinTaskTest extends JS
884       */
885      public void testPollTask() {
886          RecursiveAction a = new RecursiveAction() {
887 <                public void compute() {
888 <                    AsyncFib g = new AsyncFib(9);
889 <                    g.fork();
890 <                    AsyncFib f = new AsyncFib(8);
891 <                    f.fork();
892 <                    threadAssertTrue(pollTask() == f);
893 <                    helpQuiesce();
894 <                    threadAssertFalse(f.isDone());
895 <                    threadAssertTrue(g.isDone());
896 <                }
897 <            };
1027 <        singletonPool.invoke(a);
887 >            public void compute() {
888 >                AsyncFib g = new AsyncFib(9);
889 >                g.fork();
890 >                AsyncFib f = new AsyncFib(8);
891 >                f.fork();
892 >                threadAssertTrue(pollTask() == f);
893 >                helpQuiesce();
894 >                threadAssertFalse(f.isDone());
895 >                threadAssertTrue(g.isDone());
896 >            }};
897 >        testInvokeOnPool(singletonPool(), a);
898      }
899  
900      /**
# Line 1032 | Line 902 | public class ForkJoinTaskTest extends JS
902       */
903      public void testPeekNextLocalTaskAsync() {
904          RecursiveAction a = new RecursiveAction() {
905 <                public void compute() {
906 <                    AsyncFib g = new AsyncFib(9);
907 <                    g.fork();
908 <                    AsyncFib f = new AsyncFib(8);
909 <                    f.fork();
910 <                    threadAssertTrue(peekNextLocalTask() == g);
911 <                    f.join();
912 <                    helpQuiesce();
913 <                    threadAssertTrue(f.isDone());
914 <                }
915 <            };
1046 <        asyncSingletonPool.invoke(a);
905 >            public void compute() {
906 >                AsyncFib g = new AsyncFib(9);
907 >                g.fork();
908 >                AsyncFib f = new AsyncFib(8);
909 >                f.fork();
910 >                threadAssertTrue(peekNextLocalTask() == g);
911 >                f.join();
912 >                helpQuiesce();
913 >                threadAssertTrue(f.isDone());
914 >            }};
915 >        testInvokeOnPool(asyncSingletonPool(), a);
916      }
917  
918      /**
# Line 1052 | Line 921 | public class ForkJoinTaskTest extends JS
921       */
922      public void testPollNextLocalTaskAsync() {
923          RecursiveAction a = new RecursiveAction() {
924 <                public void compute() {
925 <                    AsyncFib g = new AsyncFib(9);
926 <                    g.fork();
927 <                    AsyncFib f = new AsyncFib(8);
928 <                    f.fork();
929 <                    threadAssertTrue(pollNextLocalTask() == g);
930 <                    helpQuiesce();
931 <                    threadAssertTrue(f.isDone());
932 <                    threadAssertFalse(g.isDone());
933 <                }
934 <            };
1066 <        asyncSingletonPool.invoke(a);
924 >            public void compute() {
925 >                AsyncFib g = new AsyncFib(9);
926 >                g.fork();
927 >                AsyncFib f = new AsyncFib(8);
928 >                f.fork();
929 >                threadAssertTrue(pollNextLocalTask() == g);
930 >                helpQuiesce();
931 >                threadAssertTrue(f.isDone());
932 >                threadAssertFalse(g.isDone());
933 >            }};
934 >        testInvokeOnPool(asyncSingletonPool(), a);
935      }
936  
937      /**
# Line 1072 | Line 940 | public class ForkJoinTaskTest extends JS
940       */
941      public void testPollTaskAsync() {
942          RecursiveAction a = new RecursiveAction() {
943 <                public void compute() {
944 <                    AsyncFib g = new AsyncFib(9);
945 <                    g.fork();
946 <                    AsyncFib f = new AsyncFib(8);
947 <                    f.fork();
948 <                    threadAssertTrue(pollTask() == g);
949 <                    helpQuiesce();
950 <                    threadAssertTrue(f.isDone());
951 <                    threadAssertFalse(g.isDone());
952 <                }
953 <            };
1086 <        asyncSingletonPool.invoke(a);
943 >            public void compute() {
944 >                AsyncFib g = new AsyncFib(9);
945 >                g.fork();
946 >                AsyncFib f = new AsyncFib(8);
947 >                f.fork();
948 >                threadAssertTrue(pollTask() == g);
949 >                helpQuiesce();
950 >                threadAssertTrue(f.isDone());
951 >                threadAssertFalse(g.isDone());
952 >            }};
953 >        testInvokeOnPool(asyncSingletonPool(), a);
954      }
955   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines