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.6 by jsr166, Wed Dec 31 17:00:58 2014 UTC vs.
Revision 1.21 by jsr166, Tue Oct 6 05:56:01 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines