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

Comparing jsr166/src/test/tck/ForkJoinTask8Test.java (file contents):
Revision 1.9 by jsr166, Sat Feb 7 17:43:38 2015 UTC vs.
Revision 1.27 by jsr166, Wed Aug 24 22:22:39 2016 UTC

# Line 7 | Line 7
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8   import static java.util.concurrent.TimeUnit.SECONDS;
9  
10 < import java.util.HashSet;
10 > import java.util.Arrays;
11 > import java.util.concurrent.CountDownLatch;
12   import java.util.concurrent.ExecutionException;
13   import java.util.concurrent.ForkJoinPool;
14   import java.util.concurrent.ForkJoinTask;
15 + import java.util.concurrent.ForkJoinWorkerThread;
16   import java.util.concurrent.RecursiveAction;
17   import java.util.concurrent.TimeoutException;
18  
# Line 34 | Line 36 | public class ForkJoinTask8Test extends J
36      static final short EXCEPTION_STATE = 1;
37  
38      public static void main(String[] args) {
39 <        junit.textui.TestRunner.run(suite());
39 >        main(suite(), args);
40      }
41  
42      public static Test suite() {
# Line 59 | Line 61 | public class ForkJoinTask8Test extends J
61                                  null, true);
62      }
63  
64 +    // Compute fib naively and efficiently
65 +    final int[] fib;
66 +    {
67 +        int[] fib = new int[10];
68 +        fib[0] = 0;
69 +        fib[1] = 1;
70 +        for (int i = 2; i < fib.length; i++)
71 +            fib[i] = fib[i - 1] + fib[i - 2];
72 +        this.fib = fib;
73 +    }
74 +
75      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
76 <        try {
76 >        try (PoolCleaner cleaner = cleaner(pool)) {
77              assertFalse(a.isDone());
78              assertFalse(a.isCompletedNormally());
79              assertFalse(a.isCompletedAbnormally());
# Line 76 | Line 89 | public class ForkJoinTask8Test extends J
89              assertFalse(a.isCancelled());
90              assertNull(a.getException());
91              assertNull(a.getRawResult());
79        } finally {
80            joinPool(pool);
92          }
93      }
94  
# Line 114 | Line 125 | public class ForkJoinTask8Test extends J
125  
126          {
127              Thread.currentThread().interrupt();
128 <            long t0 = System.nanoTime();
128 >            long startTime = System.nanoTime();
129              assertSame(expected, a.join());
130 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
130 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
131              Thread.interrupted();
132          }
133  
134          {
135              Thread.currentThread().interrupt();
136 <            long t0 = System.nanoTime();
136 >            long startTime = System.nanoTime();
137              a.quietlyJoin();        // should be no-op
138 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
138 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
139              Thread.interrupted();
140          }
141  
# Line 160 | Line 171 | public class ForkJoinTask8Test extends J
171          Thread.interrupted();
172  
173          {
174 <            long t0 = System.nanoTime();
174 >            long startTime = System.nanoTime();
175              a.quietlyJoin();        // should be no-op
176 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
176 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
177          }
178  
179          try {
# Line 186 | Line 197 | public class ForkJoinTask8Test extends J
197  
198      abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
199  
200 <        private BinaryAsyncAction parent;
200 >        private volatile BinaryAsyncAction parent;
201  
202 <        private BinaryAsyncAction sibling;
202 >        private volatile BinaryAsyncAction sibling;
203  
204          protected BinaryAsyncAction() {
205              setForkJoinTaskTag(INITIAL_STATE);
# Line 231 | Line 242 | public class ForkJoinTask8Test extends J
242              super.completeExceptionally(ex);
243          }
244  
245 +        public boolean cancel(boolean mayInterruptIfRunning) {
246 +            if (super.cancel(mayInterruptIfRunning)) {
247 +                completeExceptionally(new FJException());
248 +                return true;
249 +            }
250 +            return false;
251 +        }
252 +
253          public final void complete() {
254              BinaryAsyncAction a = this;
255              for (;;) {
# Line 253 | Line 272 | public class ForkJoinTask8Test extends J
272          }
273  
274          public final void completeExceptionally(Throwable ex) {
275 <            BinaryAsyncAction a = this;
257 <            while (!a.isCompletedAbnormally()) {
275 >            for (BinaryAsyncAction a = this;;) {
276                  a.completeThisExceptionally(ex);
277                  BinaryAsyncAction s = a.sibling;
278 <                if (s != null)
279 <                    s.cancel(false);
280 <                if (!a.onException() || (a = a.parent) == null)
278 >                if (s != null && !s.isDone())
279 >                    s.completeExceptionally(ex);
280 >                if ((a = a.parent) == null)
281                      break;
282              }
283          }
# Line 279 | Line 297 | public class ForkJoinTask8Test extends J
297  
298      }
299  
300 <    static final class AsyncFib extends BinaryAsyncAction {
300 >    final class AsyncFib extends BinaryAsyncAction {
301          int number;
302 <        public AsyncFib(int n) {
303 <            this.number = n;
302 >        int expectedResult;
303 >        public AsyncFib(int number) {
304 >            this.number = number;
305 >            this.expectedResult = fib[number];
306          }
307  
308          public final boolean exec() {
309              try {
310                  AsyncFib f = this;
311                  int n = f.number;
312 <                if (n > 1) {
313 <                    while (n > 1) {
314 <                        AsyncFib p = f;
315 <                        AsyncFib r = new AsyncFib(n - 2);
316 <                        f = new AsyncFib(--n);
317 <                        p.linkSubtasks(r, f);
298 <                        r.fork();
299 <                    }
300 <                    f.number = n;
312 >                while (n > 1) {
313 >                    AsyncFib p = f;
314 >                    AsyncFib r = new AsyncFib(n - 2);
315 >                    f = new AsyncFib(--n);
316 >                    p.linkSubtasks(r, f);
317 >                    r.fork();
318                  }
319                  f.complete();
320              }
321              catch (Throwable ex) {
322                  compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
323              }
324 +            if (getForkJoinTaskTag() == EXCEPTION_STATE)
325 +                throw new FJException();
326              return false;
327          }
328  
# Line 311 | Line 330 | public class ForkJoinTask8Test extends J
330              number = ((AsyncFib)x).number + ((AsyncFib)y).number;
331              super.onComplete(x, y);
332          }
333 +
334 +        public void checkCompletedNormally() {
335 +            assertEquals(expectedResult, number);
336 +            ForkJoinTask8Test.this.checkCompletedNormally(this);
337 +        }
338      }
339  
340      static final class FailingAsyncFib extends BinaryAsyncAction {
# Line 320 | Line 344 | public class ForkJoinTask8Test extends J
344          }
345  
346          public final boolean exec() {
347 <            FailingAsyncFib f = this;
348 <            int n = f.number;
349 <            if (n > 1) {
347 >            try {
348 >                FailingAsyncFib f = this;
349 >                int n = f.number;
350                  while (n > 1) {
351                      FailingAsyncFib p = f;
352                      FailingAsyncFib r = new FailingAsyncFib(n - 2);
# Line 330 | Line 354 | public class ForkJoinTask8Test extends J
354                      p.linkSubtasks(r, f);
355                      r.fork();
356                  }
357 <                f.number = n;
357 >                f.complete();
358 >            }
359 >            catch (Throwable ex) {
360 >                compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
361              }
362 <            f.complete();
362 >            if (getForkJoinTaskTag() == EXCEPTION_STATE)
363 >                throw new FJException();
364              return false;
365          }
366  
# Line 347 | Line 375 | public class ForkJoinTask8Test extends J
375       * completed tasks; getRawResult returns null.
376       */
377      public void testInvoke() {
378 +        testInvoke(mainPool());
379 +    }
380 +    public void testInvoke_Singleton() {
381 +        testInvoke(singletonPool());
382 +    }
383 +    public void testInvoke(ForkJoinPool pool) {
384          RecursiveAction a = new CheckedRecursiveAction() {
385              protected void realCompute() {
386                  AsyncFib f = new AsyncFib(8);
387                  assertNull(f.invoke());
388 <                assertEquals(21, f.number);
355 <                checkCompletedNormally(f);
388 >                f.checkCompletedNormally();
389              }};
390 <        testInvokeOnPool(mainPool(), a);
390 >        testInvokeOnPool(pool, a);
391      }
392  
393      /**
# Line 363 | Line 396 | public class ForkJoinTask8Test extends J
396       * completed tasks
397       */
398      public void testQuietlyInvoke() {
399 +        testQuietlyInvoke(mainPool());
400 +    }
401 +    public void testQuietlyInvoke_Singleton() {
402 +        testQuietlyInvoke(singletonPool());
403 +    }
404 +    public void testQuietlyInvoke(ForkJoinPool pool) {
405          RecursiveAction a = new CheckedRecursiveAction() {
406              protected void realCompute() {
407                  AsyncFib f = new AsyncFib(8);
408                  f.quietlyInvoke();
409 <                assertEquals(21, f.number);
371 <                checkCompletedNormally(f);
409 >                f.checkCompletedNormally();
410              }};
411 <        testInvokeOnPool(mainPool(), a);
411 >        testInvokeOnPool(pool, a);
412      }
413  
414      /**
415       * join of a forked task returns when task completes
416       */
417      public void testForkJoin() {
418 +        testForkJoin(mainPool());
419 +    }
420 +    public void testForkJoin_Singleton() {
421 +        testForkJoin(singletonPool());
422 +    }
423 +    public void testForkJoin(ForkJoinPool pool) {
424          RecursiveAction a = new CheckedRecursiveAction() {
425              protected void realCompute() {
426                  AsyncFib f = new AsyncFib(8);
427                  assertSame(f, f.fork());
428                  assertNull(f.join());
429 <                assertEquals(21, f.number);
386 <                checkCompletedNormally(f);
429 >                f.checkCompletedNormally();
430              }};
431 <        testInvokeOnPool(mainPool(), a);
431 >        testInvokeOnPool(pool, a);
432      }
433  
434      /**
435       * get of a forked task returns when task completes
436       */
437      public void testForkGet() {
438 +        testForkGet(mainPool());
439 +    }
440 +    public void testForkGet_Singleton() {
441 +        testForkGet(singletonPool());
442 +    }
443 +    public void testForkGet(ForkJoinPool pool) {
444          RecursiveAction a = new CheckedRecursiveAction() {
445              protected void realCompute() throws Exception {
446                  AsyncFib f = new AsyncFib(8);
447                  assertSame(f, f.fork());
448                  assertNull(f.get());
449 <                assertEquals(21, f.number);
401 <                checkCompletedNormally(f);
449 >                f.checkCompletedNormally();
450              }};
451 <        testInvokeOnPool(mainPool(), a);
451 >        testInvokeOnPool(pool, a);
452      }
453  
454      /**
455       * timed get of a forked task returns when task completes
456       */
457      public void testForkTimedGet() {
458 +        testForkTimedGet(mainPool());
459 +    }
460 +    public void testForkTimedGet_Singleton() {
461 +        testForkTimedGet(singletonPool());
462 +    }
463 +    public void testForkTimedGet(ForkJoinPool pool) {
464          RecursiveAction a = new CheckedRecursiveAction() {
465              protected void realCompute() throws Exception {
466                  AsyncFib f = new AsyncFib(8);
467                  assertSame(f, f.fork());
468                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
469 <                assertEquals(21, f.number);
416 <                checkCompletedNormally(f);
469 >                f.checkCompletedNormally();
470              }};
471 <        testInvokeOnPool(mainPool(), a);
471 >        testInvokeOnPool(pool, a);
472      }
473  
474      /**
475 <     * timed get with null time unit throws NPE
475 >     * timed get with null time unit throws NullPointerException
476       */
477 <    public void testForkTimedGetNPE() {
477 >    public void testForkTimedGetNullTimeUnit() {
478 >        testForkTimedGetNullTimeUnit(mainPool());
479 >    }
480 >    public void testForkTimedGetNullTimeUnit_Singleton() {
481 >        testForkTimedGet(singletonPool());
482 >    }
483 >    public void testForkTimedGetNullTimeUnit(ForkJoinPool pool) {
484          RecursiveAction a = new CheckedRecursiveAction() {
485              protected void realCompute() throws Exception {
486                  AsyncFib f = new AsyncFib(8);
# Line 431 | Line 490 | public class ForkJoinTask8Test extends J
490                      shouldThrow();
491                  } catch (NullPointerException success) {}
492              }};
493 <        testInvokeOnPool(mainPool(), a);
493 >        testInvokeOnPool(pool, a);
494      }
495  
496      /**
497       * quietlyJoin of a forked task returns when task completes
498       */
499      public void testForkQuietlyJoin() {
500 +        testForkQuietlyJoin(mainPool());
501 +    }
502 +    public void testForkQuietlyJoin_Singleton() {
503 +        testForkQuietlyJoin(singletonPool());
504 +    }
505 +    public void testForkQuietlyJoin(ForkJoinPool pool) {
506          RecursiveAction a = new CheckedRecursiveAction() {
507              protected void realCompute() {
508                  AsyncFib f = new AsyncFib(8);
509                  assertSame(f, f.fork());
510                  f.quietlyJoin();
511 <                assertEquals(21, f.number);
447 <                checkCompletedNormally(f);
511 >                f.checkCompletedNormally();
512              }};
513 <        testInvokeOnPool(mainPool(), a);
513 >        testInvokeOnPool(pool, a);
514      }
515  
516      /**
# Line 454 | Line 518 | public class ForkJoinTask8Test extends J
518       * getQueuedTaskCount returns 0 when quiescent
519       */
520      public void testForkHelpQuiesce() {
521 +        testForkHelpQuiesce(mainPool());
522 +    }
523 +    public void testForkHelpQuiesce_Singleton() {
524 +        testForkHelpQuiesce(singletonPool());
525 +    }
526 +    public void testForkHelpQuiesce(ForkJoinPool pool) {
527          RecursiveAction a = new CheckedRecursiveAction() {
528              protected void realCompute() {
529                  AsyncFib f = new AsyncFib(8);
530                  assertSame(f, f.fork());
531                  helpQuiesce();
462                assertEquals(21, f.number);
532                  assertEquals(0, getQueuedTaskCount());
533 <                checkCompletedNormally(f);
533 >                f.checkCompletedNormally();
534              }};
535 <        testInvokeOnPool(mainPool(), a);
535 >        testInvokeOnPool(pool, a);
536      }
537  
538      /**
539       * invoke task throws exception when task completes abnormally
540       */
541      public void testAbnormalInvoke() {
542 +        testAbnormalInvoke(mainPool());
543 +    }
544 +    public void testAbnormalInvoke_Singleton() {
545 +        testAbnormalInvoke(singletonPool());
546 +    }
547 +    public void testAbnormalInvoke(ForkJoinPool pool) {
548          RecursiveAction a = new CheckedRecursiveAction() {
549              protected void realCompute() {
550                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 480 | Line 555 | public class ForkJoinTask8Test extends J
555                      checkCompletedAbnormally(f, success);
556                  }
557              }};
558 <        testInvokeOnPool(mainPool(), a);
558 >        testInvokeOnPool(pool, a);
559      }
560  
561      /**
562       * quietlyInvoke task returns when task completes abnormally
563       */
564      public void testAbnormalQuietlyInvoke() {
565 +        testAbnormalQuietlyInvoke(mainPool());
566 +    }
567 +    public void testAbnormalQuietlyInvoke_Singleton() {
568 +        testAbnormalQuietlyInvoke(singletonPool());
569 +    }
570 +    public void testAbnormalQuietlyInvoke(ForkJoinPool pool) {
571          RecursiveAction a = new CheckedRecursiveAction() {
572              protected void realCompute() {
573                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 494 | Line 575 | public class ForkJoinTask8Test extends J
575                  assertTrue(f.getException() instanceof FJException);
576                  checkCompletedAbnormally(f, f.getException());
577              }};
578 <        testInvokeOnPool(mainPool(), a);
578 >        testInvokeOnPool(pool, a);
579      }
580  
581      /**
582       * join of a forked task throws exception when task completes abnormally
583       */
584      public void testAbnormalForkJoin() {
585 +        testAbnormalForkJoin(mainPool());
586 +    }
587 +    public void testAbnormalForkJoin_Singleton() {
588 +        testAbnormalForkJoin(singletonPool());
589 +    }
590 +    public void testAbnormalForkJoin(ForkJoinPool pool) {
591          RecursiveAction a = new CheckedRecursiveAction() {
592              protected void realCompute() {
593                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 512 | Line 599 | public class ForkJoinTask8Test extends J
599                      checkCompletedAbnormally(f, success);
600                  }
601              }};
602 <        testInvokeOnPool(mainPool(), a);
602 >        testInvokeOnPool(pool, a);
603      }
604  
605      /**
606       * get of a forked task throws exception when task completes abnormally
607       */
608      public void testAbnormalForkGet() {
609 +        testAbnormalForkGet(mainPool());
610 +    }
611 +    public void testAbnormalForkGet_Singleton() {
612 +        testAbnormalForkJoin(singletonPool());
613 +    }
614 +    public void testAbnormalForkGet(ForkJoinPool pool) {
615          RecursiveAction a = new CheckedRecursiveAction() {
616              protected void realCompute() throws Exception {
617                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 532 | Line 625 | public class ForkJoinTask8Test extends J
625                      checkCompletedAbnormally(f, cause);
626                  }
627              }};
628 <        testInvokeOnPool(mainPool(), a);
628 >        testInvokeOnPool(pool, a);
629      }
630  
631      /**
632       * timed get of a forked task throws exception when task completes abnormally
633       */
634      public void testAbnormalForkTimedGet() {
635 +        testAbnormalForkTimedGet(mainPool());
636 +    }
637 +    public void testAbnormalForkTimedGet_Singleton() {
638 +        testAbnormalForkTimedGet(singletonPool());
639 +    }
640 +    public void testAbnormalForkTimedGet(ForkJoinPool pool) {
641          RecursiveAction a = new CheckedRecursiveAction() {
642              protected void realCompute() throws Exception {
643                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 552 | Line 651 | public class ForkJoinTask8Test extends J
651                      checkCompletedAbnormally(f, cause);
652                  }
653              }};
654 <        testInvokeOnPool(mainPool(), a);
654 >        testInvokeOnPool(pool, a);
655      }
656  
657      /**
658       * quietlyJoin of a forked task returns when task completes abnormally
659       */
660      public void testAbnormalForkQuietlyJoin() {
661 +        testAbnormalForkQuietlyJoin(mainPool());
662 +    }
663 +    public void testAbnormalForkQuietlyJoin_Singleton() {
664 +        testAbnormalForkQuietlyJoin(singletonPool());
665 +    }
666 +    public void testAbnormalForkQuietlyJoin(ForkJoinPool pool) {
667          RecursiveAction a = new CheckedRecursiveAction() {
668              protected void realCompute() {
669                  FailingAsyncFib f = new FailingAsyncFib(8);
# Line 567 | Line 672 | public class ForkJoinTask8Test extends J
672                  assertTrue(f.getException() instanceof FJException);
673                  checkCompletedAbnormally(f, f.getException());
674              }};
675 <        testInvokeOnPool(mainPool(), a);
675 >        testInvokeOnPool(pool, a);
676      }
677  
678      /**
679       * getPool of executing task returns its pool
680       */
681      public void testGetPool() {
682 <        final ForkJoinPool mainPool = mainPool();
682 >        testGetPool(mainPool());
683 >    }
684 >    public void testGetPool_Singleton() {
685 >        testGetPool(singletonPool());
686 >    }
687 >    public void testGetPool(ForkJoinPool pool) {
688          RecursiveAction a = new CheckedRecursiveAction() {
689              protected void realCompute() {
690 <                assertSame(mainPool, getPool());
690 >                assertSame(pool, getPool());
691              }};
692 <        testInvokeOnPool(mainPool, a);
692 >        testInvokeOnPool(pool, a);
693      }
694  
695      /**
# Line 597 | Line 707 | public class ForkJoinTask8Test extends J
707       * inForkJoinPool of executing task returns true
708       */
709      public void testInForkJoinPool() {
710 +        testInForkJoinPool(mainPool());
711 +    }
712 +    public void testInForkJoinPool_Singleton() {
713 +        testInForkJoinPool(singletonPool());
714 +    }
715 +    public void testInForkJoinPool(ForkJoinPool pool) {
716          RecursiveAction a = new CheckedRecursiveAction() {
717              protected void realCompute() {
718                  assertTrue(inForkJoinPool());
719              }};
720 <        testInvokeOnPool(mainPool(), a);
720 >        testInvokeOnPool(pool, a);
721      }
722  
723      /**
# Line 631 | Line 747 | public class ForkJoinTask8Test extends J
747       * invoke task throws exception after invoking completeExceptionally
748       */
749      public void testCompleteExceptionally() {
750 +        testCompleteExceptionally(mainPool());
751 +    }
752 +    public void testCompleteExceptionally_Singleton() {
753 +        testCompleteExceptionally(singletonPool());
754 +    }
755 +    public void testCompleteExceptionally(ForkJoinPool pool) {
756          RecursiveAction a = new CheckedRecursiveAction() {
757              protected void realCompute() {
758                  AsyncFib f = new AsyncFib(8);
# Line 642 | Line 764 | public class ForkJoinTask8Test extends J
764                      checkCompletedAbnormally(f, success);
765                  }
766              }};
767 <        testInvokeOnPool(mainPool(), a);
767 >        testInvokeOnPool(pool, a);
768      }
769  
770      /**
771 <     * invokeAll(t1, t2) invokes all task arguments
771 >     * invokeAll(tasks) with 1 argument invokes task
772       */
773 <    public void testInvokeAll2() {
773 >    public void testInvokeAll1() {
774 >        testInvokeAll1(mainPool());
775 >    }
776 >    public void testInvokeAll1_Singleton() {
777 >        testInvokeAll1(singletonPool());
778 >    }
779 >    public void testInvokeAll1(ForkJoinPool pool) {
780          RecursiveAction a = new CheckedRecursiveAction() {
781              protected void realCompute() {
782                  AsyncFib f = new AsyncFib(8);
783 <                AsyncFib g = new AsyncFib(9);
784 <                invokeAll(f, g);
657 <                assertEquals(21, f.number);
658 <                assertEquals(34, g.number);
659 <                checkCompletedNormally(f);
660 <                checkCompletedNormally(g);
783 >                invokeAll(f);
784 >                f.checkCompletedNormally();
785              }};
786 <        testInvokeOnPool(mainPool(), a);
786 >        testInvokeOnPool(pool, a);
787      }
788  
789      /**
790 <     * invokeAll(tasks) with 1 argument invokes task
790 >     * invokeAll(t1, t2) invokes all task arguments
791       */
792 <    public void testInvokeAll1() {
792 >    public void testInvokeAll2() {
793 >        testInvokeAll2(mainPool());
794 >    }
795 >    public void testInvokeAll2_Singleton() {
796 >        testInvokeAll2(singletonPool());
797 >    }
798 >    public void testInvokeAll2(ForkJoinPool pool) {
799          RecursiveAction a = new CheckedRecursiveAction() {
800              protected void realCompute() {
801 <                AsyncFib f = new AsyncFib(8);
802 <                invokeAll(f);
803 <                checkCompletedNormally(f);
804 <                assertEquals(21, f.number);
801 >                AsyncFib[] tasks = {
802 >                    new AsyncFib(8),
803 >                    new AsyncFib(9),
804 >                };
805 >                invokeAll(tasks[0], tasks[1]);
806 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
807 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
808              }};
809 <        testInvokeOnPool(mainPool(), a);
809 >        testInvokeOnPool(pool, a);
810      }
811  
812      /**
813       * invokeAll(tasks) with > 2 argument invokes tasks
814       */
815      public void testInvokeAll3() {
816 +        testInvokeAll3(mainPool());
817 +    }
818 +    public void testInvokeAll3_Singleton() {
819 +        testInvokeAll3(singletonPool());
820 +    }
821 +    public void testInvokeAll3(ForkJoinPool pool) {
822          RecursiveAction a = new CheckedRecursiveAction() {
823              protected void realCompute() {
824 <                AsyncFib f = new AsyncFib(8);
825 <                AsyncFib g = new AsyncFib(9);
826 <                AsyncFib h = new AsyncFib(7);
827 <                invokeAll(f, g, h);
828 <                assertEquals(21, f.number);
829 <                assertEquals(34, g.number);
830 <                assertEquals(13, h.number);
831 <                checkCompletedNormally(f);
693 <                checkCompletedNormally(g);
694 <                checkCompletedNormally(h);
824 >                AsyncFib[] tasks = {
825 >                    new AsyncFib(8),
826 >                    new AsyncFib(9),
827 >                    new AsyncFib(7),
828 >                };
829 >                invokeAll(tasks[0], tasks[1], tasks[2]);
830 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
831 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
832              }};
833 <        testInvokeOnPool(mainPool(), a);
833 >        testInvokeOnPool(pool, a);
834      }
835  
836      /**
837       * invokeAll(collection) invokes all tasks in the collection
838       */
839      public void testInvokeAllCollection() {
840 +        testInvokeAllCollection(mainPool());
841 +    }
842 +    public void testInvokeAllCollection_Singleton() {
843 +        testInvokeAllCollection(singletonPool());
844 +    }
845 +    public void testInvokeAllCollection(ForkJoinPool pool) {
846          RecursiveAction a = new CheckedRecursiveAction() {
847              protected void realCompute() {
848 <                AsyncFib f = new AsyncFib(8);
849 <                AsyncFib g = new AsyncFib(9);
850 <                AsyncFib h = new AsyncFib(7);
851 <                HashSet set = new HashSet();
852 <                set.add(f);
853 <                set.add(g);
854 <                set.add(h);
855 <                invokeAll(set);
713 <                assertEquals(21, f.number);
714 <                assertEquals(34, g.number);
715 <                assertEquals(13, h.number);
716 <                checkCompletedNormally(f);
717 <                checkCompletedNormally(g);
718 <                checkCompletedNormally(h);
848 >                AsyncFib[] tasks = {
849 >                    new AsyncFib(8),
850 >                    new AsyncFib(9),
851 >                    new AsyncFib(7),
852 >                };
853 >                invokeAll(Arrays.asList(tasks));
854 >                for (AsyncFib task : tasks) assertTrue(task.isDone());
855 >                for (AsyncFib task : tasks) task.checkCompletedNormally();
856              }};
857 <        testInvokeOnPool(mainPool(), a);
857 >        testInvokeOnPool(pool, a);
858      }
859  
860      /**
861 <     * invokeAll(tasks) with any null task throws NPE
861 >     * invokeAll(tasks) with any null task throws NullPointerException
862       */
863 <    public void testInvokeAllNPE() {
863 >    public void testInvokeAllNullTask() {
864 >        testInvokeAllNullTask(mainPool());
865 >    }
866 >    public void testInvokeAllNullTask_Singleton() {
867 >        testInvokeAllNullTask(singletonPool());
868 >    }
869 >    public void testInvokeAllNullTask(ForkJoinPool pool) {
870          RecursiveAction a = new CheckedRecursiveAction() {
871              protected void realCompute() {
872 <                AsyncFib f = new AsyncFib(8);
730 <                AsyncFib g = new AsyncFib(9);
731 <                AsyncFib h = null;
872 >                AsyncFib nul = null;
873                  Runnable[] throwingActions = {
874 <                    () -> invokeAll(h),
875 <                    () -> invokeAll(f, g, h),
876 <                    () -> invokeAll(f, h, g),
877 <                    () -> invokeAll(h, f, g),
874 >                    () -> invokeAll(nul),
875 >                    () -> invokeAll(nul, nul),
876 >                    () -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul),
877 >                    () -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)),
878 >                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)),
879                  };
880                  assertThrows(NullPointerException.class, throwingActions);
881              }};
882 <        testInvokeOnPool(mainPool(), a);
882 >        testInvokeOnPool(pool, a);
883      }
884  
885      /**
886 <     * invokeAll(t1, t2) throw exception if any task does
886 >     * invokeAll(tasks) with 1 argument throws exception if task does
887       */
888 <    public void testAbnormalInvokeAll2() {
888 >    public void testAbnormalInvokeAll1() {
889 >        testAbnormalInvokeAll1(mainPool());
890 >    }
891 >    public void testAbnormalInvokeAll1_Singleton() {
892 >        testAbnormalInvokeAll1(singletonPool());
893 >    }
894 >    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
895          RecursiveAction a = new CheckedRecursiveAction() {
896              protected void realCompute() {
749                AsyncFib f = new AsyncFib(8);
897                  FailingAsyncFib g = new FailingAsyncFib(9);
898                  try {
899 <                    invokeAll(f, g);
899 >                    invokeAll(g);
900                      shouldThrow();
901                  } catch (FJException success) {
902                      checkCompletedAbnormally(g, success);
903                  }
904              }};
905 <        testInvokeOnPool(mainPool(), a);
905 >        testInvokeOnPool(pool, a);
906      }
907  
908      /**
909 <     * invokeAll(tasks) with 1 argument throws exception if task does
909 >     * invokeAll(t1, t2) throw exception if any task does
910       */
911 <    public void testAbnormalInvokeAll1() {
911 >    public void testAbnormalInvokeAll2() {
912 >        testAbnormalInvokeAll2(mainPool());
913 >    }
914 >    public void testAbnormalInvokeAll2_Singleton() {
915 >        testAbnormalInvokeAll2(singletonPool());
916 >    }
917 >    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
918          RecursiveAction a = new CheckedRecursiveAction() {
919              protected void realCompute() {
920 +                AsyncFib f = new AsyncFib(8);
921                  FailingAsyncFib g = new FailingAsyncFib(9);
922 +                ForkJoinTask[] tasks = { f, g };
923 +                shuffle(tasks);
924                  try {
925 <                    invokeAll(g);
925 >                    invokeAll(tasks[0], tasks[1]);
926                      shouldThrow();
927                  } catch (FJException success) {
928                      checkCompletedAbnormally(g, success);
929                  }
930              }};
931 <        testInvokeOnPool(mainPool(), a);
931 >        testInvokeOnPool(pool, a);
932      }
933  
934      /**
935       * invokeAll(tasks) with > 2 argument throws exception if any task does
936       */
937      public void testAbnormalInvokeAll3() {
938 +        testAbnormalInvokeAll3(mainPool());
939 +    }
940 +    public void testAbnormalInvokeAll3_Singleton() {
941 +        testAbnormalInvokeAll3(singletonPool());
942 +    }
943 +    public void testAbnormalInvokeAll3(ForkJoinPool pool) {
944          RecursiveAction a = new CheckedRecursiveAction() {
945              protected void realCompute() {
946                  AsyncFib f = new AsyncFib(8);
947                  FailingAsyncFib g = new FailingAsyncFib(9);
948                  AsyncFib h = new AsyncFib(7);
949 +                ForkJoinTask[] tasks = { f, g, h };
950 +                shuffle(tasks);
951                  try {
952 <                    invokeAll(f, g, h);
952 >                    invokeAll(tasks[0], tasks[1], tasks[2]);
953                      shouldThrow();
954                  } catch (FJException success) {
955                      checkCompletedAbnormally(g, success);
956                  }
957              }};
958 <        testInvokeOnPool(mainPool(), a);
958 >        testInvokeOnPool(pool, a);
959      }
960  
961      /**
962       * invokeAll(collection) throws exception if any task does
963       */
964      public void testAbnormalInvokeAllCollection() {
965 +        testAbnormalInvokeAllCollection(mainPool());
966 +    }
967 +    public void testAbnormalInvokeAllCollection_Singleton() {
968 +        testAbnormalInvokeAllCollection(singletonPool());
969 +    }
970 +    public void testAbnormalInvokeAllCollection(ForkJoinPool pool) {
971          RecursiveAction a = new CheckedRecursiveAction() {
972              protected void realCompute() {
973                  FailingAsyncFib f = new FailingAsyncFib(8);
974                  AsyncFib g = new AsyncFib(9);
975                  AsyncFib h = new AsyncFib(7);
976 <                HashSet set = new HashSet();
977 <                set.add(f);
808 <                set.add(g);
809 <                set.add(h);
976 >                ForkJoinTask[] tasks = { f, g, h };
977 >                shuffle(tasks);
978                  try {
979 <                    invokeAll(set);
979 >                    invokeAll(Arrays.asList(tasks));
980                      shouldThrow();
981                  } catch (FJException success) {
982                      checkCompletedAbnormally(f, success);
983                  }
984              }};
985 <        testInvokeOnPool(mainPool(), a);
985 >        testInvokeOnPool(pool, a);
986      }
987  
988      /**
# Line 831 | Line 999 | public class ForkJoinTask8Test extends J
999                  assertTrue(f.tryUnfork());
1000                  helpQuiesce();
1001                  checkNotDone(f);
1002 <                checkCompletedNormally(g);
1002 >                g.checkCompletedNormally();
1003              }};
1004          testInvokeOnPool(singletonPool(), a);
1005      }
# Line 852 | Line 1020 | public class ForkJoinTask8Test extends J
1020                  assertTrue(getSurplusQueuedTaskCount() > 0);
1021                  helpQuiesce();
1022                  assertEquals(0, getSurplusQueuedTaskCount());
1023 <                checkCompletedNormally(f);
1024 <                checkCompletedNormally(g);
1025 <                checkCompletedNormally(h);
1023 >                f.checkCompletedNormally();
1024 >                g.checkCompletedNormally();
1025 >                h.checkCompletedNormally();
1026              }};
1027          testInvokeOnPool(singletonPool(), a);
1028      }
# Line 871 | Line 1039 | public class ForkJoinTask8Test extends J
1039                  assertSame(f, f.fork());
1040                  assertSame(f, peekNextLocalTask());
1041                  assertNull(f.join());
1042 <                checkCompletedNormally(f);
1042 >                f.checkCompletedNormally();
1043                  helpQuiesce();
1044 <                checkCompletedNormally(g);
1044 >                g.checkCompletedNormally();
1045              }};
1046          testInvokeOnPool(singletonPool(), a);
1047      }
# Line 892 | Line 1060 | public class ForkJoinTask8Test extends J
1060                  assertSame(f, pollNextLocalTask());
1061                  helpQuiesce();
1062                  checkNotDone(f);
1063 <                assertEquals(34, g.number);
896 <                checkCompletedNormally(g);
1063 >                g.checkCompletedNormally();
1064              }};
1065          testInvokeOnPool(singletonPool(), a);
1066      }
# Line 911 | Line 1078 | public class ForkJoinTask8Test extends J
1078                  assertSame(f, pollTask());
1079                  helpQuiesce();
1080                  checkNotDone(f);
1081 <                checkCompletedNormally(g);
1081 >                g.checkCompletedNormally();
1082              }};
1083          testInvokeOnPool(singletonPool(), a);
1084      }
# Line 929 | Line 1096 | public class ForkJoinTask8Test extends J
1096                  assertSame(g, peekNextLocalTask());
1097                  assertNull(f.join());
1098                  helpQuiesce();
1099 <                checkCompletedNormally(f);
1100 <                assertEquals(34, g.number);
934 <                checkCompletedNormally(g);
1099 >                f.checkCompletedNormally();
1100 >                g.checkCompletedNormally();
1101              }};
1102          testInvokeOnPool(asyncSingletonPool(), a);
1103      }
# Line 949 | Line 1115 | public class ForkJoinTask8Test extends J
1115                  assertSame(f, f.fork());
1116                  assertSame(g, pollNextLocalTask());
1117                  helpQuiesce();
1118 <                assertEquals(21, f.number);
953 <                checkCompletedNormally(f);
1118 >                f.checkCompletedNormally();
1119                  checkNotDone(g);
1120              }};
1121          testInvokeOnPool(asyncSingletonPool(), a);
# Line 969 | Line 1134 | public class ForkJoinTask8Test extends J
1134                  assertSame(f, f.fork());
1135                  assertSame(g, pollTask());
1136                  helpQuiesce();
1137 <                assertEquals(21, f.number);
973 <                checkCompletedNormally(f);
1137 >                f.checkCompletedNormally();
1138                  checkNotDone(g);
1139              }};
1140          testInvokeOnPool(asyncSingletonPool(), a);
1141      }
1142  
979    // versions for singleton pools
980
981    /**
982     * invoke returns when task completes normally.
983     * isCompletedAbnormally and isCancelled return false for normally
984     * completed tasks; getRawResult returns null.
985     */
986    public void testInvokeSingleton() {
987        RecursiveAction a = new CheckedRecursiveAction() {
988            protected void realCompute() {
989                AsyncFib f = new AsyncFib(8);
990                assertNull(f.invoke());
991                assertEquals(21, f.number);
992                checkCompletedNormally(f);
993            }};
994        testInvokeOnPool(singletonPool(), a);
995    }
996
997    /**
998     * quietlyInvoke task returns when task completes normally.
999     * isCompletedAbnormally and isCancelled return false for normally
1000     * completed tasks
1001     */
1002    public void testQuietlyInvokeSingleton() {
1003        RecursiveAction a = new CheckedRecursiveAction() {
1004            protected void realCompute() {
1005                AsyncFib f = new AsyncFib(8);
1006                f.quietlyInvoke();
1007                assertEquals(21, f.number);
1008                checkCompletedNormally(f);
1009            }};
1010        testInvokeOnPool(singletonPool(), a);
1011    }
1012
1013    /**
1014     * join of a forked task returns when task completes
1015     */
1016    public void testForkJoinSingleton() {
1017        RecursiveAction a = new CheckedRecursiveAction() {
1018            protected void realCompute() {
1019                AsyncFib f = new AsyncFib(8);
1020                assertSame(f, f.fork());
1021                assertNull(f.join());
1022                assertEquals(21, f.number);
1023                checkCompletedNormally(f);
1024            }};
1025        testInvokeOnPool(singletonPool(), a);
1026    }
1027
1028    /**
1029     * get of a forked task returns when task completes
1030     */
1031    public void testForkGetSingleton() {
1032        RecursiveAction a = new CheckedRecursiveAction() {
1033            protected void realCompute() throws Exception {
1034                AsyncFib f = new AsyncFib(8);
1035                assertSame(f, f.fork());
1036                assertNull(f.get());
1037                assertEquals(21, f.number);
1038                checkCompletedNormally(f);
1039            }};
1040        testInvokeOnPool(singletonPool(), a);
1041    }
1042
1043    /**
1044     * timed get of a forked task returns when task completes
1045     */
1046    public void testForkTimedGetSingleton() {
1047        RecursiveAction a = new CheckedRecursiveAction() {
1048            protected void realCompute() throws Exception {
1049                AsyncFib f = new AsyncFib(8);
1050                assertSame(f, f.fork());
1051                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1052                assertEquals(21, f.number);
1053                checkCompletedNormally(f);
1054            }};
1055        testInvokeOnPool(singletonPool(), a);
1056    }
1057
1058    /**
1059     * timed get with null time unit throws NPE
1060     */
1061    public void testForkTimedGetNPESingleton() {
1062        RecursiveAction a = new CheckedRecursiveAction() {
1063            protected void realCompute() throws Exception {
1064                AsyncFib f = new AsyncFib(8);
1065                assertSame(f, f.fork());
1066                try {
1067                    f.get(5L, null);
1068                    shouldThrow();
1069                } catch (NullPointerException success) {}
1070            }};
1071        testInvokeOnPool(singletonPool(), a);
1072    }
1073
1074    /**
1075     * quietlyJoin of a forked task returns when task completes
1076     */
1077    public void testForkQuietlyJoinSingleton() {
1078        RecursiveAction a = new CheckedRecursiveAction() {
1079            protected void realCompute() {
1080                AsyncFib f = new AsyncFib(8);
1081                assertSame(f, f.fork());
1082                f.quietlyJoin();
1083                assertEquals(21, f.number);
1084                checkCompletedNormally(f);
1085            }};
1086        testInvokeOnPool(singletonPool(), a);
1087    }
1088
1089    /**
1090     * helpQuiesce returns when tasks are complete.
1091     * getQueuedTaskCount returns 0 when quiescent
1092     */
1093    public void testForkHelpQuiesceSingleton() {
1094        RecursiveAction a = new CheckedRecursiveAction() {
1095            protected void realCompute() {
1096                AsyncFib f = new AsyncFib(8);
1097                assertSame(f, f.fork());
1098                helpQuiesce();
1099                assertEquals(0, getQueuedTaskCount());
1100                assertEquals(21, f.number);
1101                checkCompletedNormally(f);
1102            }};
1103        testInvokeOnPool(singletonPool(), a);
1104    }
1105
1106    /**
1107     * invoke task throws exception when task completes abnormally
1108     */
1109    public void testAbnormalInvokeSingleton() {
1110        RecursiveAction a = new CheckedRecursiveAction() {
1111            protected void realCompute() {
1112                FailingAsyncFib f = new FailingAsyncFib(8);
1113                try {
1114                    f.invoke();
1115                    shouldThrow();
1116                } catch (FJException success) {
1117                    checkCompletedAbnormally(f, success);
1118                }
1119            }};
1120        testInvokeOnPool(singletonPool(), a);
1121    }
1122
1123    /**
1124     * quietlyInvoke task returns when task completes abnormally
1125     */
1126    public void testAbnormalQuietlyInvokeSingleton() {
1127        RecursiveAction a = new CheckedRecursiveAction() {
1128            protected void realCompute() {
1129                FailingAsyncFib f = new FailingAsyncFib(8);
1130                f.quietlyInvoke();
1131                assertTrue(f.getException() instanceof FJException);
1132                checkCompletedAbnormally(f, f.getException());
1133            }};
1134        testInvokeOnPool(singletonPool(), a);
1135    }
1136
1137    /**
1138     * join of a forked task throws exception when task completes abnormally
1139     */
1140    public void testAbnormalForkJoinSingleton() {
1141        RecursiveAction a = new CheckedRecursiveAction() {
1142            protected void realCompute() {
1143                FailingAsyncFib f = new FailingAsyncFib(8);
1144                assertSame(f, f.fork());
1145                try {
1146                    f.join();
1147                    shouldThrow();
1148                } catch (FJException success) {
1149                    checkCompletedAbnormally(f, success);
1150                }
1151            }};
1152        testInvokeOnPool(singletonPool(), a);
1153    }
1154
1155    /**
1156     * get of a forked task throws exception when task completes abnormally
1157     */
1158    public void testAbnormalForkGetSingleton() {
1159        RecursiveAction a = new CheckedRecursiveAction() {
1160            protected void realCompute() throws Exception {
1161                FailingAsyncFib f = new FailingAsyncFib(8);
1162                assertSame(f, f.fork());
1163                try {
1164                    f.get();
1165                    shouldThrow();
1166                } catch (ExecutionException success) {
1167                    Throwable cause = success.getCause();
1168                    assertTrue(cause instanceof FJException);
1169                    checkCompletedAbnormally(f, cause);
1170                }
1171            }};
1172        testInvokeOnPool(singletonPool(), a);
1173    }
1174
1175    /**
1176     * timed get of a forked task throws exception when task completes abnormally
1177     */
1178    public void testAbnormalForkTimedGetSingleton() {
1179        RecursiveAction a = new CheckedRecursiveAction() {
1180            protected void realCompute() throws Exception {
1181                FailingAsyncFib f = new FailingAsyncFib(8);
1182                assertSame(f, f.fork());
1183                try {
1184                    f.get(LONG_DELAY_MS, MILLISECONDS);
1185                    shouldThrow();
1186                } catch (ExecutionException success) {
1187                    Throwable cause = success.getCause();
1188                    assertTrue(cause instanceof FJException);
1189                    checkCompletedAbnormally(f, cause);
1190                }
1191            }};
1192        testInvokeOnPool(singletonPool(), a);
1193    }
1194
1195    /**
1196     * quietlyJoin of a forked task returns when task completes abnormally
1197     */
1198    public void testAbnormalForkQuietlyJoinSingleton() {
1199        RecursiveAction a = new CheckedRecursiveAction() {
1200            protected void realCompute() {
1201                FailingAsyncFib f = new FailingAsyncFib(8);
1202                assertSame(f, f.fork());
1203                f.quietlyJoin();
1204                assertTrue(f.getException() instanceof FJException);
1205                checkCompletedAbnormally(f, f.getException());
1206            }};
1207        testInvokeOnPool(singletonPool(), a);
1208    }
1209
1210    /**
1211     * invoke task throws exception after invoking completeExceptionally
1212     */
1213    public void testCompleteExceptionallySingleton() {
1214        RecursiveAction a = new CheckedRecursiveAction() {
1215            protected void realCompute() {
1216                AsyncFib f = new AsyncFib(8);
1217                f.completeExceptionally(new FJException());
1218                try {
1219                    f.invoke();
1220                    shouldThrow();
1221                } catch (FJException success) {
1222                    checkCompletedAbnormally(f, success);
1223                }
1224            }};
1225        testInvokeOnPool(singletonPool(), a);
1226    }
1227
1228    /**
1229     * invokeAll(t1, t2) invokes all task arguments
1230     */
1231    public void testInvokeAll2Singleton() {
1232        RecursiveAction a = new CheckedRecursiveAction() {
1233            protected void realCompute() {
1234                AsyncFib f = new AsyncFib(8);
1235                AsyncFib g = new AsyncFib(9);
1236                invokeAll(f, g);
1237                assertEquals(21, f.number);
1238                assertEquals(34, g.number);
1239                checkCompletedNormally(f);
1240                checkCompletedNormally(g);
1241            }};
1242        testInvokeOnPool(singletonPool(), a);
1243    }
1244
1245    /**
1246     * invokeAll(tasks) with 1 argument invokes task
1247     */
1248    public void testInvokeAll1Singleton() {
1249        RecursiveAction a = new CheckedRecursiveAction() {
1250            protected void realCompute() {
1251                AsyncFib f = new AsyncFib(8);
1252                invokeAll(f);
1253                checkCompletedNormally(f);
1254                assertEquals(21, f.number);
1255            }};
1256        testInvokeOnPool(singletonPool(), a);
1257    }
1258
1259    /**
1260     * invokeAll(tasks) with > 2 argument invokes tasks
1261     */
1262    public void testInvokeAll3Singleton() {
1263        RecursiveAction a = new CheckedRecursiveAction() {
1264            protected void realCompute() {
1265                AsyncFib f = new AsyncFib(8);
1266                AsyncFib g = new AsyncFib(9);
1267                AsyncFib h = new AsyncFib(7);
1268                invokeAll(f, g, h);
1269                assertEquals(21, f.number);
1270                assertEquals(34, g.number);
1271                assertEquals(13, h.number);
1272                checkCompletedNormally(f);
1273                checkCompletedNormally(g);
1274                checkCompletedNormally(h);
1275            }};
1276        testInvokeOnPool(singletonPool(), a);
1277    }
1278
1279    /**
1280     * invokeAll(collection) invokes all tasks in the collection
1281     */
1282    public void testInvokeAllCollectionSingleton() {
1283        RecursiveAction a = new CheckedRecursiveAction() {
1284            protected void realCompute() {
1285                AsyncFib f = new AsyncFib(8);
1286                AsyncFib g = new AsyncFib(9);
1287                AsyncFib h = new AsyncFib(7);
1288                HashSet set = new HashSet();
1289                set.add(f);
1290                set.add(g);
1291                set.add(h);
1292                invokeAll(set);
1293                assertEquals(21, f.number);
1294                assertEquals(34, g.number);
1295                assertEquals(13, h.number);
1296                checkCompletedNormally(f);
1297                checkCompletedNormally(g);
1298                checkCompletedNormally(h);
1299            }};
1300        testInvokeOnPool(singletonPool(), a);
1301    }
1302
1303    /**
1304     * invokeAll(tasks) with any null task throws NPE
1305     */
1306    public void testInvokeAllNPESingleton() {
1307        RecursiveAction a = new CheckedRecursiveAction() {
1308            protected void realCompute() {
1309                AsyncFib f = new AsyncFib(8);
1310                AsyncFib g = new AsyncFib(9);
1311                AsyncFib h = null;
1312                try {
1313                    invokeAll(f, g, h);
1314                    shouldThrow();
1315                } catch (NullPointerException success) {}
1316            }};
1317        testInvokeOnPool(singletonPool(), a);
1318    }
1319
1320    /**
1321     * invokeAll(t1, t2) throw exception if any task does
1322     */
1323    public void testAbnormalInvokeAll2Singleton() {
1324        RecursiveAction a = new CheckedRecursiveAction() {
1325            protected void realCompute() {
1326                AsyncFib f = new AsyncFib(8);
1327                FailingAsyncFib g = new FailingAsyncFib(9);
1328                try {
1329                    invokeAll(f, g);
1330                    shouldThrow();
1331                } catch (FJException success) {
1332                    checkCompletedAbnormally(g, success);
1333                }
1334            }};
1335        testInvokeOnPool(singletonPool(), a);
1336    }
1337
1338    /**
1339     * invokeAll(tasks) with 1 argument throws exception if task does
1340     */
1341    public void testAbnormalInvokeAll1Singleton() {
1342        RecursiveAction a = new CheckedRecursiveAction() {
1343            protected void realCompute() {
1344                FailingAsyncFib g = new FailingAsyncFib(9);
1345                try {
1346                    invokeAll(g);
1347                    shouldThrow();
1348                } catch (FJException success) {
1349                    checkCompletedAbnormally(g, success);
1350                }
1351            }};
1352        testInvokeOnPool(singletonPool(), a);
1353    }
1354
1355    /**
1356     * invokeAll(tasks) with > 2 argument throws exception if any task does
1357     */
1358    public void testAbnormalInvokeAll3Singleton() {
1359        RecursiveAction a = new CheckedRecursiveAction() {
1360            protected void realCompute() {
1361                AsyncFib f = new AsyncFib(8);
1362                FailingAsyncFib g = new FailingAsyncFib(9);
1363                AsyncFib h = new AsyncFib(7);
1364                try {
1365                    invokeAll(f, g, h);
1366                    shouldThrow();
1367                } catch (FJException success) {
1368                    checkCompletedAbnormally(g, success);
1369                }
1370            }};
1371        testInvokeOnPool(singletonPool(), a);
1372    }
1373
1374    /**
1375     * invokeAll(collection) throws exception if any task does
1376     */
1377    public void testAbnormalInvokeAllCollectionSingleton() {
1378        RecursiveAction a = new CheckedRecursiveAction() {
1379            protected void realCompute() {
1380                FailingAsyncFib f = new FailingAsyncFib(8);
1381                AsyncFib g = new AsyncFib(9);
1382                AsyncFib h = new AsyncFib(7);
1383                HashSet set = new HashSet();
1384                set.add(f);
1385                set.add(g);
1386                set.add(h);
1387                try {
1388                    invokeAll(set);
1389                    shouldThrow();
1390                } catch (FJException success) {
1391                    checkCompletedAbnormally(f, success);
1392                }
1393            }};
1394        testInvokeOnPool(singletonPool(), a);
1395    }
1396
1143      /**
1144       * ForkJoinTask.quietlyComplete returns when task completes
1145       * normally without setting a value. The most recent value
# Line 1415 | Line 1161 | public class ForkJoinTask8Test extends J
1161          testInvokeOnPool(mainPool(), a);
1162      }
1163  
1164 +    // jdk9
1165 +
1166 +    /**
1167 +     * pollSubmission returns unexecuted submitted task, if present
1168 +     */
1169 +    public void testPollSubmission() {
1170 +        final CountDownLatch done = new CountDownLatch(1);
1171 +        final ForkJoinTask a = ForkJoinTask.adapt(awaiter(done));
1172 +        final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1173 +        final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1174 +        final ForkJoinPool p = singletonPool();
1175 +        try (PoolCleaner cleaner = cleaner(p, done)) {
1176 +            Thread external = new Thread(new CheckedRunnable() {
1177 +                public void realRun() {
1178 +                    p.execute(a);
1179 +                    p.execute(b);
1180 +                    p.execute(c);
1181 +                }});
1182 +            RecursiveAction s = new CheckedRecursiveAction() {
1183 +                protected void realCompute() {
1184 +                    external.start();
1185 +                    try {
1186 +                        external.join();
1187 +                    } catch (Exception ex) {
1188 +                        threadUnexpectedException(ex);
1189 +                    }
1190 +                    assertTrue(p.hasQueuedSubmissions());
1191 +                    assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
1192 +                    ForkJoinTask r = ForkJoinTask.pollSubmission();
1193 +                    assertTrue(r == a || r == b || r == c);
1194 +                    assertFalse(r.isDone());
1195 +                }};
1196 +            p.invoke(s);
1197 +        }
1198 +    }
1199 +
1200   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines