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.9 by jsr166, Wed Aug 25 00:07:03 2010 UTC vs.
Revision 1.16 by jsr166, Mon Sep 13 23:23:44 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.*;
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;
6   import java.util.concurrent.ExecutionException;
7   import java.util.concurrent.CancellationException;
16 import java.util.concurrent.RejectedExecutionException;
8   import java.util.concurrent.ForkJoinPool;
9   import java.util.concurrent.ForkJoinTask;
10   import java.util.concurrent.ForkJoinWorkerThread;
11   import java.util.concurrent.RecursiveAction;
21 import java.util.concurrent.RecursiveTask;
12   import java.util.concurrent.TimeUnit;
13 + import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
14 + import java.util.HashSet;
15   import junit.framework.*;
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.atomic.*;
26 import java.util.*;
16  
17   public class ForkJoinTaskTest extends JSR166TestCase {
18  
19      public static void main(String[] args) {
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 42 | Line 54 | public class ForkJoinTaskTest extends JS
54       * differently than supplied Recursive forms.
55       */
56  
45    static final ForkJoinPool mainPool = new ForkJoinPool();
46    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
47    static final ForkJoinPool asyncSingletonPool =
48        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
49                         null, true);
57      static final class FJException extends RuntimeException {
58          FJException() { super(); }
59      }
# Line 224 | 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;
227     *
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 <            };
241 <        mainPool.invoke(a);
237 >            public void compute() {
238 >                AsyncFib f = new AsyncFib(8);
239 >                threadAssertNull(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 248 | 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 <            };
261 <        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 266 | 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 <            };
278 <        mainPool.invoke(a);
273 >            public void compute() {
274 >                AsyncFib f = new AsyncFib(8);
275 >                threadAssertSame(f, f.fork());
276 >                threadAssertNull(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 283 | 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);
295 <                    }
289 >            public void compute() {
290 >                try {
291 >                    AsyncFib f = new AsyncFib(8);
292 >                    threadAssertSame(f, f.fork());
293 >                    threadAssertNull(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 303 | Line 305 | public class ForkJoinTaskTest extends JS
305       */
306      public void testForkTimedGet() {
307          RecursiveAction a = new RecursiveAction() {
308 <                public void compute() {
309 <                    try {
310 <                        AsyncFib f = new AsyncFib(8);
311 <                        f.fork();
312 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
313 <                        threadAssertTrue(f.number == 21);
314 <                        threadAssertTrue(f.isDone());
315 <                    } catch (Exception ex) {
316 <                        unexpectedException(ex);
315 <                    }
308 >            public void compute() {
309 >                try {
310 >                    AsyncFib f = new AsyncFib(8);
311 >                    threadAssertSame(f, f.fork());
312 >                    threadAssertNull(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      /**
# Line 323 | Line 324 | public class ForkJoinTaskTest extends JS
324       */
325      public void testForkTimedGetNPE() {
326          RecursiveAction a = new RecursiveAction() {
327 <                public void compute() {
328 <                    try {
329 <                        AsyncFib f = new AsyncFib(8);
330 <                        f.fork();
331 <                        f.get(5L, null);
332 <                        shouldThrow();
333 <                    } catch (NullPointerException success) {
334 <                    } catch (Exception ex) {
335 <                        unexpectedException(ex);
335 <                    }
327 >            public void compute() {
328 >                try {
329 >                    AsyncFib f = new AsyncFib(8);
330 >                    threadAssertSame(f, f.fork());
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  
341      /**
# Line 343 | Line 343 | public class ForkJoinTaskTest extends JS
343       */
344      public void testForkQuietlyJoin() {
345          RecursiveAction a = new RecursiveAction() {
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 <            };
354 <        mainPool.invoke(a);
346 >            public void compute() {
347 >                AsyncFib f = new AsyncFib(8);
348 >                threadAssertSame(f, f.fork());
349 >                f.quietlyJoin();
350 >                threadAssertTrue(f.number == 21);
351 >                threadAssertTrue(f.isDone());
352 >            }};
353 >        testInvokeOnPool(mainPool(), a);
354      }
355  
356  
# Line 361 | 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 <            };
373 <        mainPool.invoke(a);
363 >            public void compute() {
364 >                AsyncFib f = new AsyncFib(8);
365 >                threadAssertSame(f, 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 379 | 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) {
388 <                    }
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 396 | 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 <            };
405 <        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 410 | 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) {
420 <                    }
409 >            public void compute() {
410 >                try {
411 >                    FailingAsyncFib f = new FailingAsyncFib(8);
412 >                    threadAssertSame(f, 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 428 | 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);
440 <                    }
426 >            public void compute() {
427 >                try {
428 >                    FailingAsyncFib f = new FailingAsyncFib(8);
429 >                    threadAssertSame(f, 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 448 | Line 442 | public class ForkJoinTaskTest extends JS
442       */
443      public void testAbnormalForkTimedGet() {
444          RecursiveAction a = new RecursiveAction() {
445 <                public void compute() {
446 <                    try {
447 <                        FailingAsyncFib f = new FailingAsyncFib(8);
448 <                        f.fork();
449 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
450 <                        shouldThrow();
451 <                    } catch (ExecutionException success) {
452 <                    } catch (Exception ex) {
453 <                        unexpectedException(ex);
460 <                    }
445 >            public void compute() {
446 >                try {
447 >                    FailingAsyncFib f = new FailingAsyncFib(8);
448 >                    threadAssertSame(f, f.fork());
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 468 | 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 <            };
480 <        mainPool.invoke(a);
464 >            public void compute() {
465 >                FailingAsyncFib f = new FailingAsyncFib(8);
466 >                threadAssertSame(f, 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 485 | 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) {
495 <                    }
480 >            public void compute() {
481 >                try {
482 >                    AsyncFib f = new AsyncFib(8);
483 >                    threadAssertTrue(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 503 | 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) {
514 <                    }
497 >            public void compute() {
498 >                try {
499 >                    AsyncFib f = new AsyncFib(8);
500 >                    threadAssertTrue(f.cancel(true));
501 >                    threadAssertSame(f, 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 522 | 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);
535 <                    }
515 >            public void compute() {
516 >                try {
517 >                    AsyncFib f = new AsyncFib(8);
518 >                    threadAssertTrue(f.cancel(true));
519 >                    threadAssertSame(f, 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 543 | Line 532 | public class ForkJoinTaskTest extends JS
532       */
533      public void testCancelledForkTimedGet() {
534          RecursiveAction a = new RecursiveAction() {
535 <                public void compute() {
536 <                    try {
537 <                        AsyncFib f = new AsyncFib(8);
538 <                        f.cancel(true);
539 <                        f.fork();
540 <                        f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
541 <                        shouldThrow();
542 <                    } catch (CancellationException success) {
543 <                    } catch (Exception ex) {
544 <                        unexpectedException(ex);
556 <                    }
535 >            public void compute() {
536 >                try {
537 >                    AsyncFib f = new AsyncFib(8);
538 >                    threadAssertTrue(f.cancel(true));
539 >                    threadAssertSame(f, f.fork());
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 564 | 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 <            };
577 <        mainPool.invoke(a);
555 >            public void compute() {
556 >                AsyncFib f = new AsyncFib(8);
557 >                threadAssertTrue(f.cancel(true));
558 >                threadAssertSame(f, 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 <            };
589 <        mainPool.invoke(a);
573 >            public void compute() {
574 >                threadAssertTrue(getPool() == mainPool);
575 >            }};
576 >        testInvokeOnPool(mainPool, a);
577      }
578  
579      /**
# Line 594 | 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 <                }
587 <            };
601 <        a.invoke();
584 >            public void compute() {
585 >                threadAssertTrue(getPool() == null);
586 >            }};
587 >        assertNull(a.invoke());
588      }
589  
590      /**
# Line 606 | 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 <            };
613 <        mainPool.invoke(a);
595 >            public void compute() {
596 >                threadAssertTrue(inForkJoinPool());
597 >            }};
598 >        testInvokeOnPool(mainPool(), a);
599      }
600  
601      /**
# Line 618 | 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 <                }
609 <            };
625 <        a.invoke();
606 >            public void compute() {
607 >                threadAssertTrue(!inForkJoinPool());
608 >            }};
609 >        assertNull(a.invoke());
610      }
611  
612      /**
# Line 630 | 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 <                }
620 <            };
637 <        a.invoke();
617 >            public void compute() {
618 >                setRawResult(null);
619 >            }};
620 >        assertNull(a.invoke());
621      }
622  
623      /**
# Line 642 | 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) {
652 <                    }
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 660 | 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 <            };
673 <        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 678 | 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 <            };
688 <        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 693 | 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 <            };
709 <        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 714 | 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 <            };
734 <        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 740 | 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) {
751 <                    }
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 759 | 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) {
769 <                    }
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 777 | 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) {
786 <                    }
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 794 | 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) {
805 <                    }
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 813 | 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) {
828 <                    }
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 837 | 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 <            };
851 <        singletonPool.invoke(a);
813 >            public void compute() {
814 >                AsyncFib g = new AsyncFib(9);
815 >                threadAssertSame(g, g.fork());
816 >                AsyncFib f = new AsyncFib(8);
817 >                threadAssertSame(f, 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 857 | 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 <            };
871 <        singletonPool.invoke(a);
832 >            public void compute() {
833 >                AsyncFib h = new AsyncFib(7);
834 >                threadAssertSame(h, h.fork());
835 >                AsyncFib g = new AsyncFib(9);
836 >                threadAssertSame(g, g.fork());
837 >                AsyncFib f = new AsyncFib(8);
838 >                threadAssertSame(f, f.fork());
839 >                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
840 >                helpQuiesce();
841 >            }};
842 >        testInvokeOnPool(singletonPool(), a);
843      }
844  
845      /**
# Line 876 | 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 <            };
890 <        singletonPool.invoke(a);
850 >            public void compute() {
851 >                AsyncFib g = new AsyncFib(9);
852 >                threadAssertSame(g, g.fork());
853 >                AsyncFib f = new AsyncFib(8);
854 >                threadAssertSame(f, f.fork());
855 >                threadAssertTrue(peekNextLocalTask() == f);
856 >                threadAssertNull(f.join());
857 >                threadAssertTrue(f.isDone());
858 >                helpQuiesce();
859 >            }};
860 >        testInvokeOnPool(singletonPool(), a);
861      }
862  
863      /**
# Line 896 | 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 <            };
909 <        singletonPool.invoke(a);
869 >            public void compute() {
870 >                AsyncFib g = new AsyncFib(9);
871 >                threadAssertSame(g, g.fork());
872 >                AsyncFib f = new AsyncFib(8);
873 >                threadAssertSame(f, f.fork());
874 >                threadAssertTrue(pollNextLocalTask() == f);
875 >                helpQuiesce();
876 >                threadAssertFalse(f.isDone());
877 >            }};
878 >        testInvokeOnPool(singletonPool(), a);
879      }
880  
881      /**
# Line 915 | 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 <            };
929 <        singletonPool.invoke(a);
887 >            public void compute() {
888 >                AsyncFib g = new AsyncFib(9);
889 >                threadAssertSame(g, g.fork());
890 >                AsyncFib f = new AsyncFib(8);
891 >                threadAssertSame(f, 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 934 | 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 <            };
948 <        asyncSingletonPool.invoke(a);
905 >            public void compute() {
906 >                AsyncFib g = new AsyncFib(9);
907 >                threadAssertSame(g, g.fork());
908 >                AsyncFib f = new AsyncFib(8);
909 >                threadAssertSame(f, f.fork());
910 >                threadAssertTrue(peekNextLocalTask() == g);
911 >                threadAssertNull(f.join());
912 >                helpQuiesce();
913 >                threadAssertTrue(f.isDone());
914 >            }};
915 >        testInvokeOnPool(asyncSingletonPool(), a);
916      }
917  
918      /**
# Line 954 | 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 <            };
968 <        asyncSingletonPool.invoke(a);
924 >            public void compute() {
925 >                AsyncFib g = new AsyncFib(9);
926 >                threadAssertSame(g, g.fork());
927 >                AsyncFib f = new AsyncFib(8);
928 >                threadAssertSame(f, 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 974 | 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 <            };
988 <        asyncSingletonPool.invoke(a);
943 >            public void compute() {
944 >                AsyncFib g = new AsyncFib(9);
945 >                threadAssertSame(g, g.fork());
946 >                AsyncFib f = new AsyncFib(8);
947 >                threadAssertSame(f, 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