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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.15 by jsr166, Mon Sep 13 20:48:58 2010 UTC vs.
Revision 1.24 by jsr166, Sun Nov 21 19:06:53 2010 UTC

# Line 10 | Line 10 | import java.util.concurrent.ForkJoinTask
10   import java.util.concurrent.ForkJoinWorkerThread;
11   import java.util.concurrent.RecursiveAction;
12   import java.util.concurrent.TimeUnit;
13 + import java.util.concurrent.TimeoutException;
14   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
15 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
16 + import static java.util.concurrent.TimeUnit.SECONDS;
17   import java.util.HashSet;
18   import junit.framework.*;
19  
# Line 24 | Line 27 | public class ForkJoinTaskTest extends JS
27          return new TestSuite(ForkJoinTaskTest.class);
28      }
29  
30 +    // Runs with "mainPool" use > 1 thread. singletonPool tests use 1
31 +    static final int mainPoolSize =
32 +        Math.max(2, Runtime.getRuntime().availableProcessors());
33 +
34      private static ForkJoinPool mainPool() {
35 <        return new ForkJoinPool();
35 >        return new ForkJoinPool(mainPoolSize);
36      }
37  
38      private static ForkJoinPool singletonPool() {
# Line 40 | Line 47 | public class ForkJoinTaskTest extends JS
47  
48      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
49          try {
50 <            assertTrue(pool.invoke(a) == null);
50 >            assertFalse(a.isDone());
51 >            assertFalse(a.isCompletedNormally());
52 >            assertFalse(a.isCompletedAbnormally());
53 >            assertFalse(a.isCancelled());
54 >            assertNull(a.getException());
55 >            assertNull(a.getRawResult());
56 >
57 >            assertNull(pool.invoke(a));
58 >
59 >            assertTrue(a.isDone());
60 >            assertTrue(a.isCompletedNormally());
61 >            assertFalse(a.isCompletedAbnormally());
62 >            assertFalse(a.isCancelled());
63 >            assertNull(a.getException());
64 >            assertNull(a.getRawResult());
65          } finally {
66              joinPool(pool);
67          }
68      }
69  
70 +    void checkNotDone(ForkJoinTask a) {
71 +        assertFalse(a.isDone());
72 +        assertFalse(a.isCompletedNormally());
73 +        assertFalse(a.isCompletedAbnormally());
74 +        assertFalse(a.isCancelled());
75 +        assertNull(a.getException());
76 +        assertNull(a.getRawResult());
77 +
78 +        try {
79 +            a.get(0L, SECONDS);
80 +            shouldThrow();
81 +        } catch (TimeoutException success) {
82 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
83 +    }
84 +
85 +    <T> void checkCompletedNormally(ForkJoinTask<T> a) {
86 +        checkCompletedNormally(a, null);
87 +    }
88 +
89 +    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
90 +        assertTrue(a.isDone());
91 +        assertFalse(a.isCancelled());
92 +        assertTrue(a.isCompletedNormally());
93 +        assertFalse(a.isCompletedAbnormally());
94 +        assertNull(a.getException());
95 +        assertSame(expected, a.getRawResult());
96 +        assertSame(expected, a.join());
97 +        try {
98 +            assertSame(expected, a.get());
99 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
100 +        try {
101 +            assertSame(expected, a.get(5L, SECONDS));
102 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
103 +    }
104 +
105 +    void checkCancelled(ForkJoinTask a) {
106 +        assertTrue(a.isDone());
107 +        assertTrue(a.isCancelled());
108 +        assertFalse(a.isCompletedNormally());
109 +        assertTrue(a.isCompletedAbnormally());
110 +        assertTrue(a.getException() instanceof CancellationException);
111 +        assertNull(a.getRawResult());
112 +
113 +        try {
114 +            a.join();
115 +            shouldThrow();
116 +        } catch (CancellationException success) {
117 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
118 +
119 +        try {
120 +            a.get();
121 +            shouldThrow();
122 +        } catch (CancellationException success) {
123 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
124 +
125 +        try {
126 +            a.get(5L, SECONDS);
127 +            shouldThrow();
128 +        } catch (CancellationException success) {
129 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
130 +    }
131 +
132 +    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
133 +        assertTrue(a.isDone());
134 +        assertFalse(a.isCancelled());
135 +        assertFalse(a.isCompletedNormally());
136 +        assertTrue(a.isCompletedAbnormally());
137 +        assertSame(t, a.getException());
138 +        assertNull(a.getRawResult());
139 +
140 +        try {
141 +            a.join();
142 +            shouldThrow();
143 +        } catch (Throwable expected) {
144 +            assertSame(t, expected);
145 +        }
146 +
147 +        try {
148 +            a.get();
149 +            shouldThrow();
150 +        } catch (ExecutionException success) {
151 +            assertSame(t, success.getCause());
152 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
153 +
154 +        try {
155 +            a.get(5L, SECONDS);
156 +            shouldThrow();
157 +        } catch (ExecutionException success) {
158 +            assertSame(t, success.getCause());
159 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
160 +    }
161 +
162      /*
163       * Testing coverage notes:
164       *
# Line 58 | Line 171 | public class ForkJoinTaskTest extends JS
171          FJException() { super(); }
172      }
173  
174 <    static abstract class BinaryAsyncAction extends ForkJoinTask<Void> {
174 >    abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
175          private volatile int controlState;
176  
177          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
# Line 233 | Line 346 | public class ForkJoinTaskTest extends JS
346       * completed tasks. getRawResult of a RecursiveAction returns null;
347       */
348      public void testInvoke() {
349 <        RecursiveAction a = new RecursiveAction() {
350 <            public void compute() {
349 >        RecursiveAction a = new CheckedRecursiveAction() {
350 >            public void realCompute() {
351                  AsyncFib f = new AsyncFib(8);
352 <                f.invoke();
353 <                threadAssertTrue(f.number == 21);
354 <                threadAssertTrue(f.isDone());
242 <                threadAssertFalse(f.isCancelled());
243 <                threadAssertFalse(f.isCompletedAbnormally());
244 <                threadAssertTrue(f.getRawResult() == null);
352 >                assertNull(f.invoke());
353 >                assertEquals(21, f.number);
354 >                checkCompletedNormally(f);
355              }};
356          testInvokeOnPool(mainPool(), a);
357      }
# Line 252 | Line 362 | public class ForkJoinTaskTest extends JS
362       * completed tasks
363       */
364      public void testQuietlyInvoke() {
365 <        RecursiveAction a = new RecursiveAction() {
366 <            public void compute() {
365 >        RecursiveAction a = new CheckedRecursiveAction() {
366 >            public void realCompute() {
367                  AsyncFib f = new AsyncFib(8);
368                  f.quietlyInvoke();
369 <                threadAssertTrue(f.number == 21);
370 <                threadAssertTrue(f.isDone());
261 <                threadAssertFalse(f.isCancelled());
262 <                threadAssertFalse(f.isCompletedAbnormally());
263 <                threadAssertTrue(f.getRawResult() == null);
369 >                assertEquals(21, f.number);
370 >                checkCompletedNormally(f);
371              }};
372          testInvokeOnPool(mainPool(), a);
373      }
# Line 269 | Line 376 | public class ForkJoinTaskTest extends JS
376       * join of a forked task returns when task completes
377       */
378      public void testForkJoin() {
379 <        RecursiveAction a = new RecursiveAction() {
380 <            public void compute() {
379 >        RecursiveAction a = new CheckedRecursiveAction() {
380 >            public void realCompute() {
381                  AsyncFib f = new AsyncFib(8);
382 <                f.fork();
383 <                f.join();
384 <                threadAssertTrue(f.number == 21);
385 <                threadAssertTrue(f.isDone());
279 <                threadAssertTrue(f.getRawResult() == null);
382 >                assertSame(f, f.fork());
383 >                assertNull(f.join());
384 >                assertEquals(21, f.number);
385 >                checkCompletedNormally(f);
386              }};
387          testInvokeOnPool(mainPool(), a);
388      }
# Line 285 | Line 391 | public class ForkJoinTaskTest extends JS
391       * get of a forked task returns when task completes
392       */
393      public void testForkGet() {
394 <        RecursiveAction a = new RecursiveAction() {
395 <            public void compute() {
396 <                try {
397 <                    AsyncFib f = new AsyncFib(8);
398 <                    f.fork();
399 <                    f.get();
400 <                    threadAssertTrue(f.number == 21);
295 <                    threadAssertTrue(f.isDone());
296 <                } catch (Exception ex) {
297 <                    unexpectedException(ex);
298 <                }
394 >        RecursiveAction a = new CheckedRecursiveAction() {
395 >            public void realCompute() throws Exception {
396 >                AsyncFib f = new AsyncFib(8);
397 >                assertSame(f, f.fork());
398 >                assertNull(f.get());
399 >                assertEquals(21, f.number);
400 >                checkCompletedNormally(f);
401              }};
402          testInvokeOnPool(mainPool(), a);
403      }
# Line 304 | Line 406 | public class ForkJoinTaskTest extends JS
406       * timed get of a forked task returns when task completes
407       */
408      public void testForkTimedGet() {
409 <        RecursiveAction a = new RecursiveAction() {
410 <            public void compute() {
411 <                try {
412 <                    AsyncFib f = new AsyncFib(8);
413 <                    f.fork();
414 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
415 <                    threadAssertTrue(f.number == 21);
314 <                    threadAssertTrue(f.isDone());
315 <                } catch (Exception ex) {
316 <                    unexpectedException(ex);
317 <                }
409 >        RecursiveAction a = new CheckedRecursiveAction() {
410 >            public void realCompute() throws Exception {
411 >                AsyncFib f = new AsyncFib(8);
412 >                assertSame(f, f.fork());
413 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
414 >                assertEquals(21, f.number);
415 >                checkCompletedNormally(f);
416              }};
417          testInvokeOnPool(mainPool(), a);
418      }
# Line 323 | Line 421 | public class ForkJoinTaskTest extends JS
421       * timed get with null time unit throws NPE
422       */
423      public void testForkTimedGetNPE() {
424 <        RecursiveAction a = new RecursiveAction() {
425 <            public void compute() {
424 >        RecursiveAction a = new CheckedRecursiveAction() {
425 >            public void realCompute() throws Exception {
426 >                AsyncFib f = new AsyncFib(8);
427 >                assertSame(f, f.fork());
428                  try {
329                    AsyncFib f = new AsyncFib(8);
330                    f.fork();
429                      f.get(5L, null);
430                      shouldThrow();
431 <                } catch (NullPointerException success) {
334 <                } catch (Exception ex) {
335 <                    unexpectedException(ex);
336 <                }
431 >                } catch (NullPointerException success) {}
432              }};
433          testInvokeOnPool(mainPool(), a);
434      }
# Line 342 | Line 437 | public class ForkJoinTaskTest extends JS
437       * quietlyJoin of a forked task returns when task completes
438       */
439      public void testForkQuietlyJoin() {
440 <        RecursiveAction a = new RecursiveAction() {
441 <            public void compute() {
440 >        RecursiveAction a = new CheckedRecursiveAction() {
441 >            public void realCompute() {
442                  AsyncFib f = new AsyncFib(8);
443 <                f.fork();
443 >                assertSame(f, f.fork());
444                  f.quietlyJoin();
445 <                threadAssertTrue(f.number == 21);
446 <                threadAssertTrue(f.isDone());
445 >                assertEquals(21, f.number);
446 >                checkCompletedNormally(f);
447              }};
448          testInvokeOnPool(mainPool(), a);
449      }
# Line 359 | Line 454 | public class ForkJoinTaskTest extends JS
454       * getQueuedTaskCount returns 0 when quiescent
455       */
456      public void testForkHelpQuiesce() {
457 <        RecursiveAction a = new RecursiveAction() {
458 <            public void compute() {
457 >        RecursiveAction a = new CheckedRecursiveAction() {
458 >            public void realCompute() {
459                  AsyncFib f = new AsyncFib(8);
460 <                f.fork();
460 >                assertSame(f, f.fork());
461                  f.helpQuiesce();
462 <                threadAssertTrue(f.number == 21);
463 <                threadAssertTrue(f.isDone());
464 <                threadAssertTrue(getQueuedTaskCount() == 0);
462 >                assertEquals(21, f.number);
463 >                assertEquals(0, getQueuedTaskCount());
464 >                checkCompletedNormally(f);
465              }};
466          testInvokeOnPool(mainPool(), a);
467      }
# Line 376 | Line 471 | public class ForkJoinTaskTest extends JS
471       * invoke task throws exception when task completes abnormally
472       */
473      public void testAbnormalInvoke() {
474 <        RecursiveAction a = new RecursiveAction() {
475 <            public void compute() {
474 >        RecursiveAction a = new CheckedRecursiveAction() {
475 >            public void realCompute() {
476 >                FailingAsyncFib f = new FailingAsyncFib(8);
477                  try {
382                    FailingAsyncFib f = new FailingAsyncFib(8);
478                      f.invoke();
479                      shouldThrow();
480                  } catch (FJException success) {
481 +                    checkCompletedAbnormally(f, success);
482                  }
483              }};
484          testInvokeOnPool(mainPool(), a);
# Line 392 | Line 488 | public class ForkJoinTaskTest extends JS
488       * quietlyInvoke task returns when task completes abnormally
489       */
490      public void testAbnormalQuietlyInvoke() {
491 <        RecursiveAction a = new RecursiveAction() {
492 <            public void compute() {
491 >        RecursiveAction a = new CheckedRecursiveAction() {
492 >            public void realCompute() {
493                  FailingAsyncFib f = new FailingAsyncFib(8);
494                  f.quietlyInvoke();
495 <                threadAssertTrue(f.isDone());
495 >                assertTrue(f.getException() instanceof FJException);
496 >                checkCompletedAbnormally(f, f.getException());
497              }};
498          testInvokeOnPool(mainPool(), a);
499      }
# Line 405 | Line 502 | public class ForkJoinTaskTest extends JS
502       * join of a forked task throws exception when task completes abnormally
503       */
504      public void testAbnormalForkJoin() {
505 <        RecursiveAction a = new RecursiveAction() {
506 <            public void compute() {
505 >        RecursiveAction a = new CheckedRecursiveAction() {
506 >            public void realCompute() {
507 >                FailingAsyncFib f = new FailingAsyncFib(8);
508 >                assertSame(f, f.fork());
509                  try {
411                    FailingAsyncFib f = new FailingAsyncFib(8);
412                    f.fork();
510                      f.join();
511                      shouldThrow();
512                  } catch (FJException success) {
513 +                    checkCompletedAbnormally(f, success);
514                  }
515              }};
516          testInvokeOnPool(mainPool(), a);
# Line 422 | Line 520 | public class ForkJoinTaskTest extends JS
520       * get of a forked task throws exception when task completes abnormally
521       */
522      public void testAbnormalForkGet() {
523 <        RecursiveAction a = new RecursiveAction() {
524 <            public void compute() {
523 >        RecursiveAction a = new CheckedRecursiveAction() {
524 >            public void realCompute() throws Exception {
525 >                FailingAsyncFib f = new FailingAsyncFib(8);
526 >                assertSame(f, f.fork());
527                  try {
428                    FailingAsyncFib f = new FailingAsyncFib(8);
429                    f.fork();
528                      f.get();
529                      shouldThrow();
530                  } catch (ExecutionException success) {
531 <                } catch (Exception ex) {
532 <                    unexpectedException(ex);
531 >                    Throwable cause = success.getCause();
532 >                    assertTrue(cause instanceof FJException);
533 >                    checkCompletedAbnormally(f, cause);
534                  }
535              }};
536          testInvokeOnPool(mainPool(), a);
# Line 441 | Line 540 | public class ForkJoinTaskTest extends JS
540       * timed get of a forked task throws exception when task completes abnormally
541       */
542      public void testAbnormalForkTimedGet() {
543 <        RecursiveAction a = new RecursiveAction() {
544 <            public void compute() {
543 >        RecursiveAction a = new CheckedRecursiveAction() {
544 >            public void realCompute() throws Exception {
545 >                FailingAsyncFib f = new FailingAsyncFib(8);
546 >                assertSame(f, f.fork());
547                  try {
548 <                    FailingAsyncFib f = new FailingAsyncFib(8);
448 <                    f.fork();
449 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
548 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
549                      shouldThrow();
550                  } catch (ExecutionException success) {
551 <                } catch (Exception ex) {
552 <                    unexpectedException(ex);
551 >                    Throwable cause = success.getCause();
552 >                    assertTrue(cause instanceof FJException);
553 >                    checkCompletedAbnormally(f, cause);
554                  }
555              }};
556          testInvokeOnPool(mainPool(), a);
# Line 460 | Line 560 | public class ForkJoinTaskTest extends JS
560       * quietlyJoin of a forked task returns when task completes abnormally
561       */
562      public void testAbnormalForkQuietlyJoin() {
563 <        RecursiveAction a = new RecursiveAction() {
564 <            public void compute() {
563 >        RecursiveAction a = new CheckedRecursiveAction() {
564 >            public void realCompute() {
565                  FailingAsyncFib f = new FailingAsyncFib(8);
566 <                f.fork();
566 >                assertSame(f, f.fork());
567                  f.quietlyJoin();
568 <                threadAssertTrue(f.isDone());
569 <                threadAssertTrue(f.isCompletedAbnormally());
470 <                threadAssertTrue(f.getException() instanceof FJException);
568 >                assertTrue(f.getException() instanceof FJException);
569 >                checkCompletedAbnormally(f, f.getException());
570              }};
571          testInvokeOnPool(mainPool(), a);
572      }
# Line 476 | Line 575 | public class ForkJoinTaskTest extends JS
575       * invoke task throws exception when task cancelled
576       */
577      public void testCancelledInvoke() {
578 <        RecursiveAction a = new RecursiveAction() {
579 <            public void compute() {
578 >        RecursiveAction a = new CheckedRecursiveAction() {
579 >            public void realCompute() {
580 >                AsyncFib f = new AsyncFib(8);
581 >                assertTrue(f.cancel(true));
582                  try {
482                    AsyncFib f = new AsyncFib(8);
483                    f.cancel(true);
583                      f.invoke();
584                      shouldThrow();
585                  } catch (CancellationException success) {
586 +                    checkCancelled(f);
587                  }
588              }};
589          testInvokeOnPool(mainPool(), a);
# Line 493 | Line 593 | public class ForkJoinTaskTest extends JS
593       * join of a forked task throws exception when task cancelled
594       */
595      public void testCancelledForkJoin() {
596 <        RecursiveAction a = new RecursiveAction() {
597 <            public void compute() {
596 >        RecursiveAction a = new CheckedRecursiveAction() {
597 >            public void realCompute() {
598 >                AsyncFib f = new AsyncFib(8);
599 >                assertTrue(f.cancel(true));
600 >                assertSame(f, f.fork());
601                  try {
499                    AsyncFib f = new AsyncFib(8);
500                    f.cancel(true);
501                    f.fork();
602                      f.join();
603                      shouldThrow();
604                  } catch (CancellationException success) {
605 +                    checkCancelled(f);
606                  }
607              }};
608          testInvokeOnPool(mainPool(), a);
# Line 511 | Line 612 | public class ForkJoinTaskTest extends JS
612       * get of a forked task throws exception when task cancelled
613       */
614      public void testCancelledForkGet() {
615 <        RecursiveAction a = new RecursiveAction() {
616 <            public void compute() {
615 >        RecursiveAction a = new CheckedRecursiveAction() {
616 >            public void realCompute() throws Exception {
617 >                AsyncFib f = new AsyncFib(8);
618 >                assertTrue(f.cancel(true));
619 >                assertSame(f, f.fork());
620                  try {
517                    AsyncFib f = new AsyncFib(8);
518                    f.cancel(true);
519                    f.fork();
621                      f.get();
622                      shouldThrow();
623                  } catch (CancellationException success) {
624 <                } catch (Exception ex) {
524 <                    unexpectedException(ex);
624 >                    checkCancelled(f);
625                  }
626              }};
627          testInvokeOnPool(mainPool(), a);
# Line 530 | Line 630 | public class ForkJoinTaskTest extends JS
630      /**
631       * timed get of a forked task throws exception when task cancelled
632       */
633 <    public void testCancelledForkTimedGet() {
634 <        RecursiveAction a = new RecursiveAction() {
635 <            public void compute() {
636 <                try {
637 <                    AsyncFib f = new AsyncFib(8);
638 <                    f.cancel(true);
639 <                    f.fork();
640 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
633 >    public void testCancelledForkTimedGet() throws Exception {
634 >        RecursiveAction a = new CheckedRecursiveAction() {
635 >            public void realCompute() throws Exception {
636 >                AsyncFib f = new AsyncFib(8);
637 >                assertTrue(f.cancel(true));
638 >                assertSame(f, f.fork());
639 >                try {
640 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
641                      shouldThrow();
642                  } catch (CancellationException success) {
643 <                } catch (Exception ex) {
544 <                    unexpectedException(ex);
643 >                    checkCancelled(f);
644                  }
645              }};
646          testInvokeOnPool(mainPool(), a);
# Line 551 | Line 650 | public class ForkJoinTaskTest extends JS
650       * quietlyJoin of a forked task returns when task cancelled
651       */
652      public void testCancelledForkQuietlyJoin() {
653 <        RecursiveAction a = new RecursiveAction() {
654 <            public void compute() {
653 >        RecursiveAction a = new CheckedRecursiveAction() {
654 >            public void realCompute() {
655                  AsyncFib f = new AsyncFib(8);
656 <                f.cancel(true);
657 <                f.fork();
656 >                assertTrue(f.cancel(true));
657 >                assertSame(f, f.fork());
658                  f.quietlyJoin();
659 <                threadAssertTrue(f.isDone());
561 <                threadAssertTrue(f.isCompletedAbnormally());
562 <                threadAssertTrue(f.getException() instanceof CancellationException);
659 >                checkCancelled(f);
660              }};
661          testInvokeOnPool(mainPool(), a);
662      }
# Line 569 | Line 666 | public class ForkJoinTaskTest extends JS
666       */
667      public void testGetPool() {
668          final ForkJoinPool mainPool = mainPool();
669 <        RecursiveAction a = new RecursiveAction() {
670 <            public void compute() {
671 <                threadAssertTrue(getPool() == mainPool);
669 >        RecursiveAction a = new CheckedRecursiveAction() {
670 >            public void realCompute() {
671 >                assertSame(mainPool, getPool());
672              }};
673          testInvokeOnPool(mainPool, a);
674      }
# Line 580 | Line 677 | public class ForkJoinTaskTest extends JS
677       * getPool of non-FJ task returns null
678       */
679      public void testGetPool2() {
680 <        RecursiveAction a = new RecursiveAction() {
681 <            public void compute() {
682 <                threadAssertTrue(getPool() == null);
680 >        RecursiveAction a = new CheckedRecursiveAction() {
681 >            public void realCompute() {
682 >                assertNull(getPool());
683              }};
684 <        a.invoke();
684 >        assertNull(a.invoke());
685      }
686  
687      /**
688       * inForkJoinPool of executing task returns true
689       */
690      public void testInForkJoinPool() {
691 <        RecursiveAction a = new RecursiveAction() {
692 <            public void compute() {
693 <                threadAssertTrue(inForkJoinPool());
691 >        RecursiveAction a = new CheckedRecursiveAction() {
692 >            public void realCompute() {
693 >                assertTrue(inForkJoinPool());
694              }};
695          testInvokeOnPool(mainPool(), a);
696      }
# Line 602 | Line 699 | public class ForkJoinTaskTest extends JS
699       * inForkJoinPool of non-FJ task returns false
700       */
701      public void testInForkJoinPool2() {
702 <        RecursiveAction a = new RecursiveAction() {
703 <            public void compute() {
704 <                threadAssertTrue(!inForkJoinPool());
702 >        RecursiveAction a = new CheckedRecursiveAction() {
703 >            public void realCompute() {
704 >                assertFalse(inForkJoinPool());
705              }};
706 <        a.invoke();
706 >        assertNull(a.invoke());
707      }
708  
709      /**
710       * setRawResult(null) succeeds
711       */
712      public void testSetRawResult() {
713 <        RecursiveAction a = new RecursiveAction() {
714 <            public void compute() {
713 >        RecursiveAction a = new CheckedRecursiveAction() {
714 >            public void realCompute() {
715                  setRawResult(null);
716              }};
717 <        a.invoke();
717 >        assertNull(a.invoke());
718      }
719  
720      /**
721       * invoke task throws exception after invoking completeExceptionally
722       */
723      public void testCompleteExceptionally() {
724 <        RecursiveAction a = new RecursiveAction() {
725 <            public void compute() {
724 >        RecursiveAction a = new CheckedRecursiveAction() {
725 >            public void realCompute() {
726 >                AsyncFib f = new AsyncFib(8);
727 >                f.completeExceptionally(new FJException());
728                  try {
630                    AsyncFib f = new AsyncFib(8);
631                    f.completeExceptionally(new FJException());
729                      f.invoke();
730                      shouldThrow();
731                  } catch (FJException success) {
732 +                    checkCompletedAbnormally(f, success);
733                  }
734              }};
735          testInvokeOnPool(mainPool(), a);
# Line 641 | Line 739 | public class ForkJoinTaskTest extends JS
739       * invokeAll(t1, t2) invokes all task arguments
740       */
741      public void testInvokeAll2() {
742 <        RecursiveAction a = new RecursiveAction() {
743 <            public void compute() {
742 >        RecursiveAction a = new CheckedRecursiveAction() {
743 >            public void realCompute() {
744                  AsyncFib f = new AsyncFib(8);
745                  AsyncFib g = new AsyncFib(9);
746                  invokeAll(f, g);
747 <                threadAssertTrue(f.isDone());
748 <                threadAssertTrue(f.number == 21);
749 <                threadAssertTrue(g.isDone());
750 <                threadAssertTrue(g.number == 34);
747 >                assertEquals(21, f.number);
748 >                assertEquals(34, g.number);
749 >                checkCompletedNormally(f);
750 >                checkCompletedNormally(g);
751              }};
752          testInvokeOnPool(mainPool(), a);
753      }
# Line 658 | Line 756 | public class ForkJoinTaskTest extends JS
756       * invokeAll(tasks) with 1 argument invokes task
757       */
758      public void testInvokeAll1() {
759 <        RecursiveAction a = new RecursiveAction() {
760 <            public void compute() {
759 >        RecursiveAction a = new CheckedRecursiveAction() {
760 >            public void realCompute() {
761                  AsyncFib f = new AsyncFib(8);
762                  invokeAll(f);
763 <                threadAssertTrue(f.isDone());
764 <                threadAssertTrue(f.number == 21);
763 >                checkCompletedNormally(f);
764 >                assertEquals(21, f.number);
765              }};
766          testInvokeOnPool(mainPool(), a);
767      }
# Line 672 | Line 770 | public class ForkJoinTaskTest extends JS
770       * invokeAll(tasks) with > 2 argument invokes tasks
771       */
772      public void testInvokeAll3() {
773 <        RecursiveAction a = new RecursiveAction() {
774 <            public void compute() {
773 >        RecursiveAction a = new CheckedRecursiveAction() {
774 >            public void realCompute() {
775                  AsyncFib f = new AsyncFib(8);
776                  AsyncFib g = new AsyncFib(9);
777                  AsyncFib h = new AsyncFib(7);
778                  invokeAll(f, g, h);
779 <                threadAssertTrue(f.isDone());
780 <                threadAssertTrue(f.number == 21);
781 <                threadAssertTrue(g.isDone());
782 <                threadAssertTrue(g.number == 34);
783 <                threadAssertTrue(h.isDone());
784 <                threadAssertTrue(h.number == 13);
779 >                assertEquals(21, f.number);
780 >                assertEquals(34, g.number);
781 >                assertEquals(13, h.number);
782 >                checkCompletedNormally(f);
783 >                checkCompletedNormally(g);
784 >                checkCompletedNormally(h);
785              }};
786          testInvokeOnPool(mainPool(), a);
787      }
# Line 692 | Line 790 | public class ForkJoinTaskTest extends JS
790       * invokeAll(collection) invokes all tasks in the collection
791       */
792      public void testInvokeAllCollection() {
793 <        RecursiveAction a = new RecursiveAction() {
794 <            public void compute() {
793 >        RecursiveAction a = new CheckedRecursiveAction() {
794 >            public void realCompute() {
795                  AsyncFib f = new AsyncFib(8);
796                  AsyncFib g = new AsyncFib(9);
797                  AsyncFib h = new AsyncFib(7);
# Line 702 | Line 800 | public class ForkJoinTaskTest extends JS
800                  set.add(g);
801                  set.add(h);
802                  invokeAll(set);
803 <                threadAssertTrue(f.isDone());
804 <                threadAssertTrue(f.number == 21);
805 <                threadAssertTrue(g.isDone());
806 <                threadAssertTrue(g.number == 34);
807 <                threadAssertTrue(h.isDone());
808 <                threadAssertTrue(h.number == 13);
803 >                assertEquals(21, f.number);
804 >                assertEquals(34, g.number);
805 >                assertEquals(13, h.number);
806 >                checkCompletedNormally(f);
807 >                checkCompletedNormally(g);
808 >                checkCompletedNormally(h);
809              }};
810          testInvokeOnPool(mainPool(), a);
811      }
# Line 717 | Line 815 | public class ForkJoinTaskTest extends JS
815       * invokeAll(tasks) with any null task throws NPE
816       */
817      public void testInvokeAllNPE() {
818 <        RecursiveAction a = new RecursiveAction() {
819 <            public void compute() {
818 >        RecursiveAction a = new CheckedRecursiveAction() {
819 >            public void realCompute() {
820 >                AsyncFib f = new AsyncFib(8);
821 >                AsyncFib g = new AsyncFib(9);
822 >                AsyncFib h = null;
823                  try {
723                    AsyncFib f = new AsyncFib(8);
724                    AsyncFib g = new AsyncFib(9);
725                    AsyncFib h = null;
824                      invokeAll(f, g, h);
825                      shouldThrow();
826 <                } catch (NullPointerException success) {
729 <                }
826 >                } catch (NullPointerException success) {}
827              }};
828          testInvokeOnPool(mainPool(), a);
829      }
# Line 735 | Line 832 | public class ForkJoinTaskTest extends JS
832       * invokeAll(t1, t2) throw exception if any task does
833       */
834      public void testAbnormalInvokeAll2() {
835 <        RecursiveAction a = new RecursiveAction() {
836 <            public void compute() {
835 >        RecursiveAction a = new CheckedRecursiveAction() {
836 >            public void realCompute() {
837 >                AsyncFib f = new AsyncFib(8);
838 >                FailingAsyncFib g = new FailingAsyncFib(9);
839                  try {
741                    AsyncFib f = new AsyncFib(8);
742                    FailingAsyncFib g = new FailingAsyncFib(9);
840                      invokeAll(f, g);
841                      shouldThrow();
842                  } catch (FJException success) {
843 +                    checkCompletedAbnormally(g, success);
844                  }
845              }};
846          testInvokeOnPool(mainPool(), a);
# Line 752 | Line 850 | public class ForkJoinTaskTest extends JS
850       * invokeAll(tasks) with 1 argument throws exception if task does
851       */
852      public void testAbnormalInvokeAll1() {
853 <        RecursiveAction a = new RecursiveAction() {
854 <            public void compute() {
853 >        RecursiveAction a = new CheckedRecursiveAction() {
854 >            public void realCompute() {
855 >                FailingAsyncFib g = new FailingAsyncFib(9);
856                  try {
758                    FailingAsyncFib g = new FailingAsyncFib(9);
857                      invokeAll(g);
858                      shouldThrow();
859                  } catch (FJException success) {
860 +                    checkCompletedAbnormally(g, success);
861                  }
862              }};
863          testInvokeOnPool(mainPool(), a);
# Line 768 | Line 867 | public class ForkJoinTaskTest extends JS
867       * invokeAll(tasks) with > 2 argument throws exception if any task does
868       */
869      public void testAbnormalInvokeAll3() {
870 <        RecursiveAction a = new RecursiveAction() {
871 <            public void compute() {
870 >        RecursiveAction a = new CheckedRecursiveAction() {
871 >            public void realCompute() {
872 >                AsyncFib f = new AsyncFib(8);
873 >                FailingAsyncFib g = new FailingAsyncFib(9);
874 >                AsyncFib h = new AsyncFib(7);
875                  try {
774                    AsyncFib f = new AsyncFib(8);
775                    FailingAsyncFib g = new FailingAsyncFib(9);
776                    AsyncFib h = new AsyncFib(7);
876                      invokeAll(f, g, h);
877                      shouldThrow();
878                  } catch (FJException success) {
879 +                    checkCompletedAbnormally(g, success);
880                  }
881              }};
882          testInvokeOnPool(mainPool(), a);
# Line 786 | Line 886 | public class ForkJoinTaskTest extends JS
886       * invokeAll(collection)  throws exception if any task does
887       */
888      public void testAbnormalInvokeAllCollection() {
889 <        RecursiveAction a = new RecursiveAction() {
890 <            public void compute() {
889 >        RecursiveAction a = new CheckedRecursiveAction() {
890 >            public void realCompute() {
891 >                FailingAsyncFib f = new FailingAsyncFib(8);
892 >                AsyncFib g = new AsyncFib(9);
893 >                AsyncFib h = new AsyncFib(7);
894 >                HashSet set = new HashSet();
895 >                set.add(f);
896 >                set.add(g);
897 >                set.add(h);
898                  try {
792                    FailingAsyncFib f = new FailingAsyncFib(8);
793                    AsyncFib g = new AsyncFib(9);
794                    AsyncFib h = new AsyncFib(7);
795                    HashSet set = new HashSet();
796                    set.add(f);
797                    set.add(g);
798                    set.add(h);
899                      invokeAll(set);
900                      shouldThrow();
901                  } catch (FJException success) {
902 +                    checkCompletedAbnormally(f, success);
903                  }
904              }};
905          testInvokeOnPool(mainPool(), a);
# Line 809 | Line 910 | public class ForkJoinTaskTest extends JS
910       * and suppresses execution
911       */
912      public void testTryUnfork() {
913 <        RecursiveAction a = new RecursiveAction() {
914 <            public void compute() {
913 >        RecursiveAction a = new CheckedRecursiveAction() {
914 >            public void realCompute() {
915                  AsyncFib g = new AsyncFib(9);
916 <                g.fork();
916 >                assertSame(g, g.fork());
917                  AsyncFib f = new AsyncFib(8);
918 <                f.fork();
919 <                threadAssertTrue(f.tryUnfork());
918 >                assertSame(f, f.fork());
919 >                assertTrue(f.tryUnfork());
920                  helpQuiesce();
921 <                threadAssertFalse(f.isDone());
922 <                threadAssertTrue(g.isDone());
921 >                checkNotDone(f);
922 >                checkCompletedNormally(g);
923              }};
924          testInvokeOnPool(singletonPool(), a);
925      }
# Line 828 | Line 929 | public class ForkJoinTaskTest extends JS
929       * there are more tasks than threads
930       */
931      public void testGetSurplusQueuedTaskCount() {
932 <        RecursiveAction a = new RecursiveAction() {
933 <            public void compute() {
932 >        RecursiveAction a = new CheckedRecursiveAction() {
933 >            public void realCompute() {
934                  AsyncFib h = new AsyncFib(7);
935 <                h.fork();
935 >                assertSame(h, h.fork());
936                  AsyncFib g = new AsyncFib(9);
937 <                g.fork();
937 >                assertSame(g, g.fork());
938                  AsyncFib f = new AsyncFib(8);
939 <                f.fork();
940 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
939 >                assertSame(f, f.fork());
940 >                assertTrue(getSurplusQueuedTaskCount() > 0);
941                  helpQuiesce();
942 +                assertEquals(0, getSurplusQueuedTaskCount());
943 +                checkCompletedNormally(f);
944 +                checkCompletedNormally(g);
945 +                checkCompletedNormally(h);
946              }};
947          testInvokeOnPool(singletonPool(), a);
948      }
# Line 846 | Line 951 | public class ForkJoinTaskTest extends JS
951       * peekNextLocalTask returns most recent unexecuted task.
952       */
953      public void testPeekNextLocalTask() {
954 <        RecursiveAction a = new RecursiveAction() {
955 <            public void compute() {
954 >        RecursiveAction a = new CheckedRecursiveAction() {
955 >            public void realCompute() {
956                  AsyncFib g = new AsyncFib(9);
957 <                g.fork();
957 >                assertSame(g, g.fork());
958                  AsyncFib f = new AsyncFib(8);
959 <                f.fork();
960 <                threadAssertTrue(peekNextLocalTask() == f);
961 <                f.join();
962 <                threadAssertTrue(f.isDone());
959 >                assertSame(f, f.fork());
960 >                assertSame(f, peekNextLocalTask());
961 >                assertNull(f.join());
962 >                checkCompletedNormally(f);
963                  helpQuiesce();
964 +                checkCompletedNormally(g);
965              }};
966          testInvokeOnPool(singletonPool(), a);
967      }
968  
969      /**
970 <     * pollNextLocalTask returns most recent unexecuted task
971 <     * without executing it
970 >     * pollNextLocalTask returns most recent unexecuted task without
971 >     * executing it
972       */
973      public void testPollNextLocalTask() {
974 <        RecursiveAction a = new RecursiveAction() {
975 <            public void compute() {
974 >        RecursiveAction a = new CheckedRecursiveAction() {
975 >            public void realCompute() {
976                  AsyncFib g = new AsyncFib(9);
977 <                g.fork();
977 >                assertSame(g, g.fork());
978                  AsyncFib f = new AsyncFib(8);
979 <                f.fork();
980 <                threadAssertTrue(pollNextLocalTask() == f);
979 >                assertSame(f, f.fork());
980 >                assertSame(f, pollNextLocalTask());
981                  helpQuiesce();
982 <                threadAssertFalse(f.isDone());
982 >                checkNotDone(f);
983 >                assertEquals(34, g.number);
984 >                checkCompletedNormally(g);
985              }};
986          testInvokeOnPool(singletonPool(), a);
987      }
988  
989      /**
990 <     * pollTask returns an unexecuted task
883 <     * without executing it
990 >     * pollTask returns an unexecuted task without executing it
991       */
992      public void testPollTask() {
993 <        RecursiveAction a = new RecursiveAction() {
994 <            public void compute() {
993 >        RecursiveAction a = new CheckedRecursiveAction() {
994 >            public void realCompute() {
995                  AsyncFib g = new AsyncFib(9);
996 <                g.fork();
996 >                assertSame(g, g.fork());
997                  AsyncFib f = new AsyncFib(8);
998 <                f.fork();
999 <                threadAssertTrue(pollTask() == f);
998 >                assertSame(f, f.fork());
999 >                assertSame(f, pollTask());
1000                  helpQuiesce();
1001 <                threadAssertFalse(f.isDone());
1002 <                threadAssertTrue(g.isDone());
1001 >                checkNotDone(f);
1002 >                checkCompletedNormally(g);
1003              }};
1004          testInvokeOnPool(singletonPool(), a);
1005      }
# Line 901 | Line 1008 | public class ForkJoinTaskTest extends JS
1008       * peekNextLocalTask returns least recent unexecuted task in async mode
1009       */
1010      public void testPeekNextLocalTaskAsync() {
1011 <        RecursiveAction a = new RecursiveAction() {
1012 <            public void compute() {
1011 >        RecursiveAction a = new CheckedRecursiveAction() {
1012 >            public void realCompute() {
1013                  AsyncFib g = new AsyncFib(9);
1014 <                g.fork();
1014 >                assertSame(g, g.fork());
1015                  AsyncFib f = new AsyncFib(8);
1016 <                f.fork();
1017 <                threadAssertTrue(peekNextLocalTask() == g);
1018 <                f.join();
1016 >                assertSame(f, f.fork());
1017 >                assertSame(g, peekNextLocalTask());
1018 >                assertNull(f.join());
1019                  helpQuiesce();
1020 <                threadAssertTrue(f.isDone());
1020 >                checkCompletedNormally(f);
1021 >                assertEquals(34, g.number);
1022 >                checkCompletedNormally(g);
1023              }};
1024          testInvokeOnPool(asyncSingletonPool(), a);
1025      }
1026  
1027      /**
1028 <     * pollNextLocalTask returns least recent unexecuted task
1029 <     * without executing it, in async mode
1028 >     * pollNextLocalTask returns least recent unexecuted task without
1029 >     * executing it, in async mode
1030       */
1031      public void testPollNextLocalTaskAsync() {
1032 <        RecursiveAction a = new RecursiveAction() {
1033 <            public void compute() {
1032 >        RecursiveAction a = new CheckedRecursiveAction() {
1033 >            public void realCompute() {
1034                  AsyncFib g = new AsyncFib(9);
1035 <                g.fork();
1035 >                assertSame(g, g.fork());
1036                  AsyncFib f = new AsyncFib(8);
1037 <                f.fork();
1038 <                threadAssertTrue(pollNextLocalTask() == g);
1037 >                assertSame(f, f.fork());
1038 >                assertSame(g, pollNextLocalTask());
1039                  helpQuiesce();
1040 <                threadAssertTrue(f.isDone());
1041 <                threadAssertFalse(g.isDone());
1040 >                assertEquals(21, f.number);
1041 >                checkCompletedNormally(f);
1042 >                checkNotDone(g);
1043              }};
1044          testInvokeOnPool(asyncSingletonPool(), a);
1045      }
1046  
1047      /**
1048 <     * pollTask returns an unexecuted task
1049 <     * without executing it, in async mode
1048 >     * pollTask returns an unexecuted task without executing it, in
1049 >     * async mode
1050       */
1051      public void testPollTaskAsync() {
1052 <        RecursiveAction a = new RecursiveAction() {
1053 <            public void compute() {
1052 >        RecursiveAction a = new CheckedRecursiveAction() {
1053 >            public void realCompute() {
1054                  AsyncFib g = new AsyncFib(9);
1055 <                g.fork();
1055 >                assertSame(g, g.fork());
1056                  AsyncFib f = new AsyncFib(8);
1057 <                f.fork();
1058 <                threadAssertTrue(pollTask() == g);
1057 >                assertSame(f, f.fork());
1058 >                assertSame(g, pollTask());
1059                  helpQuiesce();
1060 <                threadAssertTrue(f.isDone());
1061 <                threadAssertFalse(g.isDone());
1060 >                assertEquals(21, f.number);
1061 >                checkCompletedNormally(f);
1062 >                checkNotDone(g);
1063              }};
1064          testInvokeOnPool(asyncSingletonPool(), a);
1065      }
1066 +
1067 +    // versions for singleton pools
1068 +
1069 +    /**
1070 +     * invoke returns when task completes normally.
1071 +     * isCompletedAbnormally and isCancelled return false for normally
1072 +     * completed tasks. getRawResult of a RecursiveAction returns null;
1073 +     */
1074 +    public void testInvokeSingleton() {
1075 +        RecursiveAction a = new CheckedRecursiveAction() {
1076 +            public void realCompute() {
1077 +                AsyncFib f = new AsyncFib(8);
1078 +                assertNull(f.invoke());
1079 +                assertEquals(21, f.number);
1080 +                checkCompletedNormally(f);
1081 +            }};
1082 +        testInvokeOnPool(singletonPool(), a);
1083 +    }
1084 +
1085 +    /**
1086 +     * quietlyInvoke task returns when task completes normally.
1087 +     * isCompletedAbnormally and isCancelled return false for normally
1088 +     * completed tasks
1089 +     */
1090 +    public void testQuietlyInvokeSingleton() {
1091 +        RecursiveAction a = new CheckedRecursiveAction() {
1092 +            public void realCompute() {
1093 +                AsyncFib f = new AsyncFib(8);
1094 +                f.quietlyInvoke();
1095 +                assertEquals(21, f.number);
1096 +                checkCompletedNormally(f);
1097 +            }};
1098 +        testInvokeOnPool(singletonPool(), a);
1099 +    }
1100 +
1101 +    /**
1102 +     * join of a forked task returns when task completes
1103 +     */
1104 +    public void testForkJoinSingleton() {
1105 +        RecursiveAction a = new CheckedRecursiveAction() {
1106 +            public void realCompute() {
1107 +                AsyncFib f = new AsyncFib(8);
1108 +                assertSame(f, f.fork());
1109 +                assertNull(f.join());
1110 +                assertEquals(21, f.number);
1111 +                checkCompletedNormally(f);
1112 +            }};
1113 +        testInvokeOnPool(singletonPool(), a);
1114 +    }
1115 +
1116 +    /**
1117 +     * get of a forked task returns when task completes
1118 +     */
1119 +    public void testForkGetSingleton() {
1120 +        RecursiveAction a = new CheckedRecursiveAction() {
1121 +            public void realCompute() throws Exception {
1122 +                AsyncFib f = new AsyncFib(8);
1123 +                assertSame(f, f.fork());
1124 +                assertNull(f.get());
1125 +                assertEquals(21, f.number);
1126 +                checkCompletedNormally(f);
1127 +            }};
1128 +        testInvokeOnPool(singletonPool(), a);
1129 +    }
1130 +
1131 +    /**
1132 +     * timed get of a forked task returns when task completes
1133 +     */
1134 +    public void testForkTimedGetSingleton() {
1135 +        RecursiveAction a = new CheckedRecursiveAction() {
1136 +            public void realCompute() throws Exception {
1137 +                AsyncFib f = new AsyncFib(8);
1138 +                assertSame(f, f.fork());
1139 +                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1140 +                assertEquals(21, f.number);
1141 +                checkCompletedNormally(f);
1142 +            }};
1143 +        testInvokeOnPool(singletonPool(), a);
1144 +    }
1145 +
1146 +    /**
1147 +     * timed get with null time unit throws NPE
1148 +     */
1149 +    public void testForkTimedGetNPESingleton() {
1150 +        RecursiveAction a = new CheckedRecursiveAction() {
1151 +            public void realCompute() throws Exception {
1152 +                AsyncFib f = new AsyncFib(8);
1153 +                assertSame(f, f.fork());
1154 +                try {
1155 +                    f.get(5L, null);
1156 +                    shouldThrow();
1157 +                } catch (NullPointerException success) {}
1158 +            }};
1159 +        testInvokeOnPool(singletonPool(), a);
1160 +    }
1161 +
1162 +    /**
1163 +     * quietlyJoin of a forked task returns when task completes
1164 +     */
1165 +    public void testForkQuietlyJoinSingleton() {
1166 +        RecursiveAction a = new CheckedRecursiveAction() {
1167 +            public void realCompute() {
1168 +                AsyncFib f = new AsyncFib(8);
1169 +                assertSame(f, f.fork());
1170 +                f.quietlyJoin();
1171 +                assertEquals(21, f.number);
1172 +                checkCompletedNormally(f);
1173 +            }};
1174 +        testInvokeOnPool(singletonPool(), a);
1175 +    }
1176 +
1177 +
1178 +    /**
1179 +     * helpQuiesce returns when tasks are complete.
1180 +     * getQueuedTaskCount returns 0 when quiescent
1181 +     */
1182 +    public void testForkHelpQuiesceSingleton() {
1183 +        RecursiveAction a = new CheckedRecursiveAction() {
1184 +            public void realCompute() {
1185 +                AsyncFib f = new AsyncFib(8);
1186 +                assertSame(f, f.fork());
1187 +                f.helpQuiesce();
1188 +                assertEquals(0, getQueuedTaskCount());
1189 +                assertEquals(21, f.number);
1190 +                checkCompletedNormally(f);
1191 +            }};
1192 +        testInvokeOnPool(singletonPool(), a);
1193 +    }
1194 +
1195 +
1196 +    /**
1197 +     * invoke task throws exception when task completes abnormally
1198 +     */
1199 +    public void testAbnormalInvokeSingleton() {
1200 +        RecursiveAction a = new CheckedRecursiveAction() {
1201 +            public void realCompute() {
1202 +                FailingAsyncFib f = new FailingAsyncFib(8);
1203 +                try {
1204 +                    f.invoke();
1205 +                    shouldThrow();
1206 +                } catch (FJException success) {
1207 +                    checkCompletedAbnormally(f, success);
1208 +                }
1209 +            }};
1210 +        testInvokeOnPool(singletonPool(), a);
1211 +    }
1212 +
1213 +    /**
1214 +     * quietlyInvoke task returns when task completes abnormally
1215 +     */
1216 +    public void testAbnormalQuietlyInvokeSingleton() {
1217 +        RecursiveAction a = new CheckedRecursiveAction() {
1218 +            public void realCompute() {
1219 +                FailingAsyncFib f = new FailingAsyncFib(8);
1220 +                f.quietlyInvoke();
1221 +                assertTrue(f.getException() instanceof FJException);
1222 +                checkCompletedAbnormally(f, f.getException());
1223 +            }};
1224 +        testInvokeOnPool(singletonPool(), a);
1225 +    }
1226 +
1227 +    /**
1228 +     * join of a forked task throws exception when task completes abnormally
1229 +     */
1230 +    public void testAbnormalForkJoinSingleton() {
1231 +        RecursiveAction a = new CheckedRecursiveAction() {
1232 +            public void realCompute() {
1233 +                FailingAsyncFib f = new FailingAsyncFib(8);
1234 +                assertSame(f, f.fork());
1235 +                try {
1236 +                    f.join();
1237 +                    shouldThrow();
1238 +                } catch (FJException success) {
1239 +                    checkCompletedAbnormally(f, success);
1240 +                }
1241 +            }};
1242 +        testInvokeOnPool(singletonPool(), a);
1243 +    }
1244 +
1245 +    /**
1246 +     * get of a forked task throws exception when task completes abnormally
1247 +     */
1248 +    public void testAbnormalForkGetSingleton() {
1249 +        RecursiveAction a = new CheckedRecursiveAction() {
1250 +            public void realCompute() throws Exception {
1251 +                FailingAsyncFib f = new FailingAsyncFib(8);
1252 +                assertSame(f, f.fork());
1253 +                try {
1254 +                    f.get();
1255 +                    shouldThrow();
1256 +                } catch (ExecutionException success) {
1257 +                    Throwable cause = success.getCause();
1258 +                    assertTrue(cause instanceof FJException);
1259 +                    checkCompletedAbnormally(f, cause);
1260 +                }
1261 +            }};
1262 +        testInvokeOnPool(singletonPool(), a);
1263 +    }
1264 +
1265 +    /**
1266 +     * timed get of a forked task throws exception when task completes abnormally
1267 +     */
1268 +    public void testAbnormalForkTimedGetSingleton() {
1269 +        RecursiveAction a = new CheckedRecursiveAction() {
1270 +            public void realCompute() throws Exception {
1271 +                FailingAsyncFib f = new FailingAsyncFib(8);
1272 +                assertSame(f, f.fork());
1273 +                try {
1274 +                    f.get(LONG_DELAY_MS, MILLISECONDS);
1275 +                    shouldThrow();
1276 +                } catch (ExecutionException success) {
1277 +                    Throwable cause = success.getCause();
1278 +                    assertTrue(cause instanceof FJException);
1279 +                    checkCompletedAbnormally(f, cause);
1280 +                }
1281 +            }};
1282 +        testInvokeOnPool(singletonPool(), a);
1283 +    }
1284 +
1285 +    /**
1286 +     * quietlyJoin of a forked task returns when task completes abnormally
1287 +     */
1288 +    public void testAbnormalForkQuietlyJoinSingleton() {
1289 +        RecursiveAction a = new CheckedRecursiveAction() {
1290 +            public void realCompute() {
1291 +                FailingAsyncFib f = new FailingAsyncFib(8);
1292 +                assertSame(f, f.fork());
1293 +                f.quietlyJoin();
1294 +                assertTrue(f.getException() instanceof FJException);
1295 +                checkCompletedAbnormally(f, f.getException());
1296 +            }};
1297 +        testInvokeOnPool(singletonPool(), a);
1298 +    }
1299 +
1300 +    /**
1301 +     * invoke task throws exception when task cancelled
1302 +     */
1303 +    public void testCancelledInvokeSingleton() {
1304 +        RecursiveAction a = new CheckedRecursiveAction() {
1305 +            public void realCompute() {
1306 +                AsyncFib f = new AsyncFib(8);
1307 +                assertTrue(f.cancel(true));
1308 +                try {
1309 +                    f.invoke();
1310 +                    shouldThrow();
1311 +                } catch (CancellationException success) {
1312 +                    checkCancelled(f);
1313 +                }
1314 +            }};
1315 +        testInvokeOnPool(singletonPool(), a);
1316 +    }
1317 +
1318 +    /**
1319 +     * join of a forked task throws exception when task cancelled
1320 +     */
1321 +    public void testCancelledForkJoinSingleton() {
1322 +        RecursiveAction a = new CheckedRecursiveAction() {
1323 +            public void realCompute() {
1324 +                AsyncFib f = new AsyncFib(8);
1325 +                assertTrue(f.cancel(true));
1326 +                assertSame(f, f.fork());
1327 +                try {
1328 +                    f.join();
1329 +                    shouldThrow();
1330 +                } catch (CancellationException success) {
1331 +                    checkCancelled(f);
1332 +                }
1333 +            }};
1334 +        testInvokeOnPool(singletonPool(), a);
1335 +    }
1336 +
1337 +    /**
1338 +     * get of a forked task throws exception when task cancelled
1339 +     */
1340 +    public void testCancelledForkGetSingleton() {
1341 +        RecursiveAction a = new CheckedRecursiveAction() {
1342 +            public void realCompute() throws Exception {
1343 +                AsyncFib f = new AsyncFib(8);
1344 +                assertTrue(f.cancel(true));
1345 +                assertSame(f, f.fork());
1346 +                try {
1347 +                    f.get();
1348 +                    shouldThrow();
1349 +                } catch (CancellationException success) {
1350 +                    checkCancelled(f);
1351 +                }
1352 +            }};
1353 +        testInvokeOnPool(singletonPool(), a);
1354 +    }
1355 +
1356 +    /**
1357 +     * timed get of a forked task throws exception when task cancelled
1358 +     */
1359 +    public void testCancelledForkTimedGetSingleton() throws Exception {
1360 +        RecursiveAction a = new CheckedRecursiveAction() {
1361 +            public void realCompute() throws Exception {
1362 +                AsyncFib f = new AsyncFib(8);
1363 +                assertTrue(f.cancel(true));
1364 +                assertSame(f, f.fork());
1365 +                try {
1366 +                    f.get(LONG_DELAY_MS, MILLISECONDS);
1367 +                    shouldThrow();
1368 +                } catch (CancellationException success) {
1369 +                    checkCancelled(f);
1370 +                }
1371 +            }};
1372 +        testInvokeOnPool(singletonPool(), a);
1373 +    }
1374 +
1375 +    /**
1376 +     * quietlyJoin of a forked task returns when task cancelled
1377 +     */
1378 +    public void testCancelledForkQuietlyJoinSingleton() {
1379 +        RecursiveAction a = new CheckedRecursiveAction() {
1380 +            public void realCompute() {
1381 +                AsyncFib f = new AsyncFib(8);
1382 +                assertTrue(f.cancel(true));
1383 +                assertSame(f, f.fork());
1384 +                f.quietlyJoin();
1385 +                checkCancelled(f);
1386 +            }};
1387 +        testInvokeOnPool(singletonPool(), a);
1388 +    }
1389 +
1390 +    /**
1391 +     * invoke task throws exception after invoking completeExceptionally
1392 +     */
1393 +    public void testCompleteExceptionallySingleton() {
1394 +        RecursiveAction a = new CheckedRecursiveAction() {
1395 +            public void realCompute() {
1396 +                AsyncFib f = new AsyncFib(8);
1397 +                f.completeExceptionally(new FJException());
1398 +                try {
1399 +                    f.invoke();
1400 +                    shouldThrow();
1401 +                } catch (FJException success) {
1402 +                    checkCompletedAbnormally(f, success);
1403 +                }
1404 +            }};
1405 +        testInvokeOnPool(singletonPool(), a);
1406 +    }
1407 +
1408 +    /**
1409 +     * invokeAll(t1, t2) invokes all task arguments
1410 +     */
1411 +    public void testInvokeAll2Singleton() {
1412 +        RecursiveAction a = new CheckedRecursiveAction() {
1413 +            public void realCompute() {
1414 +                AsyncFib f = new AsyncFib(8);
1415 +                AsyncFib g = new AsyncFib(9);
1416 +                invokeAll(f, g);
1417 +                assertEquals(21, f.number);
1418 +                assertEquals(34, g.number);
1419 +                checkCompletedNormally(f);
1420 +                checkCompletedNormally(g);
1421 +            }};
1422 +        testInvokeOnPool(singletonPool(), a);
1423 +    }
1424 +
1425 +    /**
1426 +     * invokeAll(tasks) with 1 argument invokes task
1427 +     */
1428 +    public void testInvokeAll1Singleton() {
1429 +        RecursiveAction a = new CheckedRecursiveAction() {
1430 +            public void realCompute() {
1431 +                AsyncFib f = new AsyncFib(8);
1432 +                invokeAll(f);
1433 +                checkCompletedNormally(f);
1434 +                assertEquals(21, f.number);
1435 +            }};
1436 +        testInvokeOnPool(singletonPool(), a);
1437 +    }
1438 +
1439 +    /**
1440 +     * invokeAll(tasks) with > 2 argument invokes tasks
1441 +     */
1442 +    public void testInvokeAll3Singleton() {
1443 +        RecursiveAction a = new CheckedRecursiveAction() {
1444 +            public void realCompute() {
1445 +                AsyncFib f = new AsyncFib(8);
1446 +                AsyncFib g = new AsyncFib(9);
1447 +                AsyncFib h = new AsyncFib(7);
1448 +                invokeAll(f, g, h);
1449 +                assertEquals(21, f.number);
1450 +                assertEquals(34, g.number);
1451 +                assertEquals(13, h.number);
1452 +                checkCompletedNormally(f);
1453 +                checkCompletedNormally(g);
1454 +                checkCompletedNormally(h);
1455 +            }};
1456 +        testInvokeOnPool(singletonPool(), a);
1457 +    }
1458 +
1459 +    /**
1460 +     * invokeAll(collection) invokes all tasks in the collection
1461 +     */
1462 +    public void testInvokeAllCollectionSingleton() {
1463 +        RecursiveAction a = new CheckedRecursiveAction() {
1464 +            public void realCompute() {
1465 +                AsyncFib f = new AsyncFib(8);
1466 +                AsyncFib g = new AsyncFib(9);
1467 +                AsyncFib h = new AsyncFib(7);
1468 +                HashSet set = new HashSet();
1469 +                set.add(f);
1470 +                set.add(g);
1471 +                set.add(h);
1472 +                invokeAll(set);
1473 +                assertEquals(21, f.number);
1474 +                assertEquals(34, g.number);
1475 +                assertEquals(13, h.number);
1476 +                checkCompletedNormally(f);
1477 +                checkCompletedNormally(g);
1478 +                checkCompletedNormally(h);
1479 +            }};
1480 +        testInvokeOnPool(singletonPool(), a);
1481 +    }
1482 +
1483 +
1484 +    /**
1485 +     * invokeAll(tasks) with any null task throws NPE
1486 +     */
1487 +    public void testInvokeAllNPESingleton() {
1488 +        RecursiveAction a = new CheckedRecursiveAction() {
1489 +            public void realCompute() {
1490 +                AsyncFib f = new AsyncFib(8);
1491 +                AsyncFib g = new AsyncFib(9);
1492 +                AsyncFib h = null;
1493 +                try {
1494 +                    invokeAll(f, g, h);
1495 +                    shouldThrow();
1496 +                } catch (NullPointerException success) {}
1497 +            }};
1498 +        testInvokeOnPool(singletonPool(), a);
1499 +    }
1500 +
1501 +    /**
1502 +     * invokeAll(t1, t2) throw exception if any task does
1503 +     */
1504 +    public void testAbnormalInvokeAll2Singleton() {
1505 +        RecursiveAction a = new CheckedRecursiveAction() {
1506 +            public void realCompute() {
1507 +                AsyncFib f = new AsyncFib(8);
1508 +                FailingAsyncFib g = new FailingAsyncFib(9);
1509 +                try {
1510 +                    invokeAll(f, g);
1511 +                    shouldThrow();
1512 +                } catch (FJException success) {
1513 +                    checkCompletedAbnormally(g, success);
1514 +                }
1515 +            }};
1516 +        testInvokeOnPool(singletonPool(), a);
1517 +    }
1518 +
1519 +    /**
1520 +     * invokeAll(tasks) with 1 argument throws exception if task does
1521 +     */
1522 +    public void testAbnormalInvokeAll1Singleton() {
1523 +        RecursiveAction a = new CheckedRecursiveAction() {
1524 +            public void realCompute() {
1525 +                FailingAsyncFib g = new FailingAsyncFib(9);
1526 +                try {
1527 +                    invokeAll(g);
1528 +                    shouldThrow();
1529 +                } catch (FJException success) {
1530 +                    checkCompletedAbnormally(g, success);
1531 +                }
1532 +            }};
1533 +        testInvokeOnPool(singletonPool(), a);
1534 +    }
1535 +
1536 +    /**
1537 +     * invokeAll(tasks) with > 2 argument throws exception if any task does
1538 +     */
1539 +    public void testAbnormalInvokeAll3Singleton() {
1540 +        RecursiveAction a = new CheckedRecursiveAction() {
1541 +            public void realCompute() {
1542 +                AsyncFib f = new AsyncFib(8);
1543 +                FailingAsyncFib g = new FailingAsyncFib(9);
1544 +                AsyncFib h = new AsyncFib(7);
1545 +                try {
1546 +                    invokeAll(f, g, h);
1547 +                    shouldThrow();
1548 +                } catch (FJException success) {
1549 +                    checkCompletedAbnormally(g, success);
1550 +                }
1551 +            }};
1552 +        testInvokeOnPool(singletonPool(), a);
1553 +    }
1554 +
1555 +    /**
1556 +     * invokeAll(collection)  throws exception if any task does
1557 +     */
1558 +    public void testAbnormalInvokeAllCollectionSingleton() {
1559 +        RecursiveAction a = new CheckedRecursiveAction() {
1560 +            public void realCompute() {
1561 +                FailingAsyncFib f = new FailingAsyncFib(8);
1562 +                AsyncFib g = new AsyncFib(9);
1563 +                AsyncFib h = new AsyncFib(7);
1564 +                HashSet set = new HashSet();
1565 +                set.add(f);
1566 +                set.add(g);
1567 +                set.add(h);
1568 +                try {
1569 +                    invokeAll(set);
1570 +                    shouldThrow();
1571 +                } catch (FJException success) {
1572 +                    checkCompletedAbnormally(f, success);
1573 +                }
1574 +            }};
1575 +        testInvokeOnPool(singletonPool(), a);
1576 +    }
1577 +
1578   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines