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.8 by jsr166, Thu Jan 15 18:34:19 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);
873 <                AsyncFib g = new AsyncFib(9);
874 <                AsyncFib h = null;
875 <                try {
876 <                    invokeAll(f, g, h);
877 <                    shouldThrow();
878 <                } catch (NullPointerException success) {}
872 >                AsyncFib nul = null;
873 >                Runnable[] throwingActions = {
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() {
746                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);
805 <                set.add(g);
806 <                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 828 | 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 849 | 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 868 | 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 889 | Line 1060 | public class ForkJoinTask8Test extends J
1060                  assertSame(f, pollNextLocalTask());
1061                  helpQuiesce();
1062                  checkNotDone(f);
1063 <                assertEquals(34, g.number);
893 <                checkCompletedNormally(g);
1063 >                g.checkCompletedNormally();
1064              }};
1065          testInvokeOnPool(singletonPool(), a);
1066      }
# Line 908 | 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 926 | 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);
931 <                checkCompletedNormally(g);
1099 >                f.checkCompletedNormally();
1100 >                g.checkCompletedNormally();
1101              }};
1102          testInvokeOnPool(asyncSingletonPool(), a);
1103      }
# Line 946 | Line 1115 | public class ForkJoinTask8Test extends J
1115                  assertSame(f, f.fork());
1116                  assertSame(g, pollNextLocalTask());
1117                  helpQuiesce();
1118 <                assertEquals(21, f.number);
950 <                checkCompletedNormally(f);
1118 >                f.checkCompletedNormally();
1119                  checkNotDone(g);
1120              }};
1121          testInvokeOnPool(asyncSingletonPool(), a);
# Line 966 | Line 1134 | public class ForkJoinTask8Test extends J
1134                  assertSame(f, f.fork());
1135                  assertSame(g, pollTask());
1136                  helpQuiesce();
1137 <                assertEquals(21, f.number);
970 <                checkCompletedNormally(f);
1137 >                f.checkCompletedNormally();
1138                  checkNotDone(g);
1139              }};
1140          testInvokeOnPool(asyncSingletonPool(), a);
1141      }
1142  
976    // versions for singleton pools
977
978    /**
979     * invoke returns when task completes normally.
980     * isCompletedAbnormally and isCancelled return false for normally
981     * completed tasks; getRawResult returns null.
982     */
983    public void testInvokeSingleton() {
984        RecursiveAction a = new CheckedRecursiveAction() {
985            protected void realCompute() {
986                AsyncFib f = new AsyncFib(8);
987                assertNull(f.invoke());
988                assertEquals(21, f.number);
989                checkCompletedNormally(f);
990            }};
991        testInvokeOnPool(singletonPool(), a);
992    }
993
994    /**
995     * quietlyInvoke task returns when task completes normally.
996     * isCompletedAbnormally and isCancelled return false for normally
997     * completed tasks
998     */
999    public void testQuietlyInvokeSingleton() {
1000        RecursiveAction a = new CheckedRecursiveAction() {
1001            protected void realCompute() {
1002                AsyncFib f = new AsyncFib(8);
1003                f.quietlyInvoke();
1004                assertEquals(21, f.number);
1005                checkCompletedNormally(f);
1006            }};
1007        testInvokeOnPool(singletonPool(), a);
1008    }
1009
1010    /**
1011     * join of a forked task returns when task completes
1012     */
1013    public void testForkJoinSingleton() {
1014        RecursiveAction a = new CheckedRecursiveAction() {
1015            protected void realCompute() {
1016                AsyncFib f = new AsyncFib(8);
1017                assertSame(f, f.fork());
1018                assertNull(f.join());
1019                assertEquals(21, f.number);
1020                checkCompletedNormally(f);
1021            }};
1022        testInvokeOnPool(singletonPool(), a);
1023    }
1024
1025    /**
1026     * get of a forked task returns when task completes
1027     */
1028    public void testForkGetSingleton() {
1029        RecursiveAction a = new CheckedRecursiveAction() {
1030            protected void realCompute() throws Exception {
1031                AsyncFib f = new AsyncFib(8);
1032                assertSame(f, f.fork());
1033                assertNull(f.get());
1034                assertEquals(21, f.number);
1035                checkCompletedNormally(f);
1036            }};
1037        testInvokeOnPool(singletonPool(), a);
1038    }
1039
1040    /**
1041     * timed get of a forked task returns when task completes
1042     */
1043    public void testForkTimedGetSingleton() {
1044        RecursiveAction a = new CheckedRecursiveAction() {
1045            protected void realCompute() throws Exception {
1046                AsyncFib f = new AsyncFib(8);
1047                assertSame(f, f.fork());
1048                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1049                assertEquals(21, f.number);
1050                checkCompletedNormally(f);
1051            }};
1052        testInvokeOnPool(singletonPool(), a);
1053    }
1054
1055    /**
1056     * timed get with null time unit throws NPE
1057     */
1058    public void testForkTimedGetNPESingleton() {
1059        RecursiveAction a = new CheckedRecursiveAction() {
1060            protected void realCompute() throws Exception {
1061                AsyncFib f = new AsyncFib(8);
1062                assertSame(f, f.fork());
1063                try {
1064                    f.get(5L, null);
1065                    shouldThrow();
1066                } catch (NullPointerException success) {}
1067            }};
1068        testInvokeOnPool(singletonPool(), a);
1069    }
1070
1071    /**
1072     * quietlyJoin of a forked task returns when task completes
1073     */
1074    public void testForkQuietlyJoinSingleton() {
1075        RecursiveAction a = new CheckedRecursiveAction() {
1076            protected void realCompute() {
1077                AsyncFib f = new AsyncFib(8);
1078                assertSame(f, f.fork());
1079                f.quietlyJoin();
1080                assertEquals(21, f.number);
1081                checkCompletedNormally(f);
1082            }};
1083        testInvokeOnPool(singletonPool(), a);
1084    }
1085
1086    /**
1087     * helpQuiesce returns when tasks are complete.
1088     * getQueuedTaskCount returns 0 when quiescent
1089     */
1090    public void testForkHelpQuiesceSingleton() {
1091        RecursiveAction a = new CheckedRecursiveAction() {
1092            protected void realCompute() {
1093                AsyncFib f = new AsyncFib(8);
1094                assertSame(f, f.fork());
1095                helpQuiesce();
1096                assertEquals(0, getQueuedTaskCount());
1097                assertEquals(21, f.number);
1098                checkCompletedNormally(f);
1099            }};
1100        testInvokeOnPool(singletonPool(), a);
1101    }
1102
1103    /**
1104     * invoke task throws exception when task completes abnormally
1105     */
1106    public void testAbnormalInvokeSingleton() {
1107        RecursiveAction a = new CheckedRecursiveAction() {
1108            protected void realCompute() {
1109                FailingAsyncFib f = new FailingAsyncFib(8);
1110                try {
1111                    f.invoke();
1112                    shouldThrow();
1113                } catch (FJException success) {
1114                    checkCompletedAbnormally(f, success);
1115                }
1116            }};
1117        testInvokeOnPool(singletonPool(), a);
1118    }
1119
1120    /**
1121     * quietlyInvoke task returns when task completes abnormally
1122     */
1123    public void testAbnormalQuietlyInvokeSingleton() {
1124        RecursiveAction a = new CheckedRecursiveAction() {
1125            protected void realCompute() {
1126                FailingAsyncFib f = new FailingAsyncFib(8);
1127                f.quietlyInvoke();
1128                assertTrue(f.getException() instanceof FJException);
1129                checkCompletedAbnormally(f, f.getException());
1130            }};
1131        testInvokeOnPool(singletonPool(), a);
1132    }
1133
1134    /**
1135     * join of a forked task throws exception when task completes abnormally
1136     */
1137    public void testAbnormalForkJoinSingleton() {
1138        RecursiveAction a = new CheckedRecursiveAction() {
1139            protected void realCompute() {
1140                FailingAsyncFib f = new FailingAsyncFib(8);
1141                assertSame(f, f.fork());
1142                try {
1143                    f.join();
1144                    shouldThrow();
1145                } catch (FJException success) {
1146                    checkCompletedAbnormally(f, success);
1147                }
1148            }};
1149        testInvokeOnPool(singletonPool(), a);
1150    }
1151
1152    /**
1153     * get of a forked task throws exception when task completes abnormally
1154     */
1155    public void testAbnormalForkGetSingleton() {
1156        RecursiveAction a = new CheckedRecursiveAction() {
1157            protected void realCompute() throws Exception {
1158                FailingAsyncFib f = new FailingAsyncFib(8);
1159                assertSame(f, f.fork());
1160                try {
1161                    f.get();
1162                    shouldThrow();
1163                } catch (ExecutionException success) {
1164                    Throwable cause = success.getCause();
1165                    assertTrue(cause instanceof FJException);
1166                    checkCompletedAbnormally(f, cause);
1167                }
1168            }};
1169        testInvokeOnPool(singletonPool(), a);
1170    }
1171
1172    /**
1173     * timed get of a forked task throws exception when task completes abnormally
1174     */
1175    public void testAbnormalForkTimedGetSingleton() {
1176        RecursiveAction a = new CheckedRecursiveAction() {
1177            protected void realCompute() throws Exception {
1178                FailingAsyncFib f = new FailingAsyncFib(8);
1179                assertSame(f, f.fork());
1180                try {
1181                    f.get(LONG_DELAY_MS, MILLISECONDS);
1182                    shouldThrow();
1183                } catch (ExecutionException success) {
1184                    Throwable cause = success.getCause();
1185                    assertTrue(cause instanceof FJException);
1186                    checkCompletedAbnormally(f, cause);
1187                }
1188            }};
1189        testInvokeOnPool(singletonPool(), a);
1190    }
1191
1192    /**
1193     * quietlyJoin of a forked task returns when task completes abnormally
1194     */
1195    public void testAbnormalForkQuietlyJoinSingleton() {
1196        RecursiveAction a = new CheckedRecursiveAction() {
1197            protected void realCompute() {
1198                FailingAsyncFib f = new FailingAsyncFib(8);
1199                assertSame(f, f.fork());
1200                f.quietlyJoin();
1201                assertTrue(f.getException() instanceof FJException);
1202                checkCompletedAbnormally(f, f.getException());
1203            }};
1204        testInvokeOnPool(singletonPool(), a);
1205    }
1206
1207    /**
1208     * invoke task throws exception after invoking completeExceptionally
1209     */
1210    public void testCompleteExceptionallySingleton() {
1211        RecursiveAction a = new CheckedRecursiveAction() {
1212            protected void realCompute() {
1213                AsyncFib f = new AsyncFib(8);
1214                f.completeExceptionally(new FJException());
1215                try {
1216                    f.invoke();
1217                    shouldThrow();
1218                } catch (FJException success) {
1219                    checkCompletedAbnormally(f, success);
1220                }
1221            }};
1222        testInvokeOnPool(singletonPool(), a);
1223    }
1224
1225    /**
1226     * invokeAll(t1, t2) invokes all task arguments
1227     */
1228    public void testInvokeAll2Singleton() {
1229        RecursiveAction a = new CheckedRecursiveAction() {
1230            protected void realCompute() {
1231                AsyncFib f = new AsyncFib(8);
1232                AsyncFib g = new AsyncFib(9);
1233                invokeAll(f, g);
1234                assertEquals(21, f.number);
1235                assertEquals(34, g.number);
1236                checkCompletedNormally(f);
1237                checkCompletedNormally(g);
1238            }};
1239        testInvokeOnPool(singletonPool(), a);
1240    }
1241
1242    /**
1243     * invokeAll(tasks) with 1 argument invokes task
1244     */
1245    public void testInvokeAll1Singleton() {
1246        RecursiveAction a = new CheckedRecursiveAction() {
1247            protected void realCompute() {
1248                AsyncFib f = new AsyncFib(8);
1249                invokeAll(f);
1250                checkCompletedNormally(f);
1251                assertEquals(21, f.number);
1252            }};
1253        testInvokeOnPool(singletonPool(), a);
1254    }
1255
1256    /**
1257     * invokeAll(tasks) with > 2 argument invokes tasks
1258     */
1259    public void testInvokeAll3Singleton() {
1260        RecursiveAction a = new CheckedRecursiveAction() {
1261            protected void realCompute() {
1262                AsyncFib f = new AsyncFib(8);
1263                AsyncFib g = new AsyncFib(9);
1264                AsyncFib h = new AsyncFib(7);
1265                invokeAll(f, g, h);
1266                assertEquals(21, f.number);
1267                assertEquals(34, g.number);
1268                assertEquals(13, h.number);
1269                checkCompletedNormally(f);
1270                checkCompletedNormally(g);
1271                checkCompletedNormally(h);
1272            }};
1273        testInvokeOnPool(singletonPool(), a);
1274    }
1275
1276    /**
1277     * invokeAll(collection) invokes all tasks in the collection
1278     */
1279    public void testInvokeAllCollectionSingleton() {
1280        RecursiveAction a = new CheckedRecursiveAction() {
1281            protected void realCompute() {
1282                AsyncFib f = new AsyncFib(8);
1283                AsyncFib g = new AsyncFib(9);
1284                AsyncFib h = new AsyncFib(7);
1285                HashSet set = new HashSet();
1286                set.add(f);
1287                set.add(g);
1288                set.add(h);
1289                invokeAll(set);
1290                assertEquals(21, f.number);
1291                assertEquals(34, g.number);
1292                assertEquals(13, h.number);
1293                checkCompletedNormally(f);
1294                checkCompletedNormally(g);
1295                checkCompletedNormally(h);
1296            }};
1297        testInvokeOnPool(singletonPool(), a);
1298    }
1299
1300    /**
1301     * invokeAll(tasks) with any null task throws NPE
1302     */
1303    public void testInvokeAllNPESingleton() {
1304        RecursiveAction a = new CheckedRecursiveAction() {
1305            protected void realCompute() {
1306                AsyncFib f = new AsyncFib(8);
1307                AsyncFib g = new AsyncFib(9);
1308                AsyncFib h = null;
1309                try {
1310                    invokeAll(f, g, h);
1311                    shouldThrow();
1312                } catch (NullPointerException success) {}
1313            }};
1314        testInvokeOnPool(singletonPool(), a);
1315    }
1316
1317    /**
1318     * invokeAll(t1, t2) throw exception if any task does
1319     */
1320    public void testAbnormalInvokeAll2Singleton() {
1321        RecursiveAction a = new CheckedRecursiveAction() {
1322            protected void realCompute() {
1323                AsyncFib f = new AsyncFib(8);
1324                FailingAsyncFib g = new FailingAsyncFib(9);
1325                try {
1326                    invokeAll(f, g);
1327                    shouldThrow();
1328                } catch (FJException success) {
1329                    checkCompletedAbnormally(g, success);
1330                }
1331            }};
1332        testInvokeOnPool(singletonPool(), a);
1333    }
1334
1335    /**
1336     * invokeAll(tasks) with 1 argument throws exception if task does
1337     */
1338    public void testAbnormalInvokeAll1Singleton() {
1339        RecursiveAction a = new CheckedRecursiveAction() {
1340            protected void realCompute() {
1341                FailingAsyncFib g = new FailingAsyncFib(9);
1342                try {
1343                    invokeAll(g);
1344                    shouldThrow();
1345                } catch (FJException success) {
1346                    checkCompletedAbnormally(g, success);
1347                }
1348            }};
1349        testInvokeOnPool(singletonPool(), a);
1350    }
1351
1352    /**
1353     * invokeAll(tasks) with > 2 argument throws exception if any task does
1354     */
1355    public void testAbnormalInvokeAll3Singleton() {
1356        RecursiveAction a = new CheckedRecursiveAction() {
1357            protected void realCompute() {
1358                AsyncFib f = new AsyncFib(8);
1359                FailingAsyncFib g = new FailingAsyncFib(9);
1360                AsyncFib h = new AsyncFib(7);
1361                try {
1362                    invokeAll(f, g, h);
1363                    shouldThrow();
1364                } catch (FJException success) {
1365                    checkCompletedAbnormally(g, success);
1366                }
1367            }};
1368        testInvokeOnPool(singletonPool(), a);
1369    }
1370
1371    /**
1372     * invokeAll(collection) throws exception if any task does
1373     */
1374    public void testAbnormalInvokeAllCollectionSingleton() {
1375        RecursiveAction a = new CheckedRecursiveAction() {
1376            protected void realCompute() {
1377                FailingAsyncFib f = new FailingAsyncFib(8);
1378                AsyncFib g = new AsyncFib(9);
1379                AsyncFib h = new AsyncFib(7);
1380                HashSet set = new HashSet();
1381                set.add(f);
1382                set.add(g);
1383                set.add(h);
1384                try {
1385                    invokeAll(set);
1386                    shouldThrow();
1387                } catch (FJException success) {
1388                    checkCompletedAbnormally(f, success);
1389                }
1390            }};
1391        testInvokeOnPool(singletonPool(), a);
1392    }
1393
1143      /**
1144       * ForkJoinTask.quietlyComplete returns when task completes
1145       * normally without setting a value. The most recent value
# Line 1412 | 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