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

Comparing jsr166/src/test/tck/RecursiveTaskTest.java (file contents):
Revision 1.19 by jsr166, Thu Sep 16 00:52:49 2010 UTC vs.
Revision 1.24 by jsr166, Mon Nov 22 07:45:50 2010 UTC

# Line 8 | Line 8 | import junit.framework.*;
8   import java.util.concurrent.CancellationException;
9   import java.util.concurrent.ExecutionException;
10   import java.util.concurrent.ForkJoinPool;
11 + import java.util.concurrent.ForkJoinWorkerThread;
12   import java.util.concurrent.RecursiveTask;
13   import java.util.concurrent.TimeUnit;
14 + import java.util.concurrent.TimeoutException;
15 + import static java.util.concurrent.TimeUnit.SECONDS;
16   import java.util.HashSet;
17  
18   public class RecursiveTaskTest extends JSR166TestCase {
# Line 37 | Line 40 | public class RecursiveTaskTest extends J
40  
41      private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) {
42          try {
43 <            assertFalse(a.isDone());
41 <            assertFalse(a.isCompletedNormally());
42 <            assertFalse(a.isCompletedAbnormally());
43 <            assertFalse(a.isCancelled());
43 >            checkNotDone(a);
44  
45              T result = pool.invoke(a);
46  
47 <            assertTrue(a.isDone());
48 <            assertTrue(a.isCompletedNormally());
49 <            assertFalse(a.isCompletedAbnormally());
50 <            assertFalse(a.isCancelled());
51 <            assertNull(a.getException());
47 >            checkCompletedNormally(a, result);
48              return result;
49          } finally {
50              joinPool(pool);
51          }
52      }
53  
54 +    void checkNotDone(RecursiveTask a) {
55 +        assertFalse(a.isDone());
56 +        assertFalse(a.isCompletedNormally());
57 +        assertFalse(a.isCompletedAbnormally());
58 +        assertFalse(a.isCancelled());
59 +        assertNull(a.getException());
60 +        assertNull(a.getRawResult());
61 +
62 +        if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) {
63 +            Thread.currentThread().interrupt();
64 +            try {
65 +                a.get();
66 +                shouldThrow();
67 +            } catch (InterruptedException success) {
68 +            } catch (Throwable fail) { threadUnexpectedException(fail); }
69 +
70 +            Thread.currentThread().interrupt();
71 +            try {
72 +                a.get(5L, SECONDS);
73 +                shouldThrow();
74 +            } catch (InterruptedException success) {
75 +            } catch (Throwable fail) { threadUnexpectedException(fail); }
76 +        }
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(RecursiveTask<T> a, T expected) {
86 +        assertTrue(a.isDone());
87 +        assertFalse(a.isCancelled());
88 +        assertTrue(a.isCompletedNormally());
89 +        assertFalse(a.isCompletedAbnormally());
90 +        assertNull(a.getException());
91 +        assertSame(expected, a.getRawResult());
92 +        assertSame(expected, a.join());
93 +        assertFalse(a.cancel(false));
94 +        assertFalse(a.cancel(true));
95 +        try {
96 +            assertSame(expected, a.get());
97 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
98 +        try {
99 +            assertSame(expected, a.get(5L, SECONDS));
100 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
101 +    }
102 +
103 +    /**
104 +     * Waits for the task to complete, and checks that when it does,
105 +     * it will have an Integer result equals to the given int.
106 +     */
107 +    void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
108 +        Integer r = a.join();
109 +        assertEquals(expected, (int) r);
110 +        checkCompletedNormally(a, r);
111 +    }
112 +
113 +    /**
114 +     * Like checkCompletesNormally, but verifies that the task has
115 +     * already completed.
116 +     */
117 +    void checkCompletedNormally(RecursiveTask<Integer> a, int expected) {
118 +        Integer r = a.getRawResult();
119 +        assertEquals(expected, (int) r);
120 +        checkCompletedNormally(a, r);
121 +    }
122 +
123 +    void checkCancelled(RecursiveTask a) {
124 +        assertTrue(a.isDone());
125 +        assertTrue(a.isCancelled());
126 +        assertFalse(a.isCompletedNormally());
127 +        assertTrue(a.isCompletedAbnormally());
128 +        assertTrue(a.getException() instanceof CancellationException);
129 +        assertNull(a.getRawResult());
130 +
131 +        try {
132 +            a.join();
133 +            shouldThrow();
134 +        } catch (CancellationException success) {
135 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
136 +
137 +        try {
138 +            a.get();
139 +            shouldThrow();
140 +        } catch (CancellationException success) {
141 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
142 +
143 +        try {
144 +            a.get(5L, SECONDS);
145 +            shouldThrow();
146 +        } catch (CancellationException success) {
147 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
148 +    }
149 +
150 +    void checkCompletedAbnormally(RecursiveTask a, Throwable t) {
151 +        assertTrue(a.isDone());
152 +        assertFalse(a.isCancelled());
153 +        assertFalse(a.isCompletedNormally());
154 +        assertTrue(a.isCompletedAbnormally());
155 +        assertSame(t, a.getException());
156 +        assertNull(a.getRawResult());
157 +        assertFalse(a.cancel(false));
158 +        assertFalse(a.cancel(true));
159 +
160 +        try {
161 +            a.join();
162 +            shouldThrow();
163 +        } catch (Throwable expected) {
164 +            assertSame(t, expected);
165 +        }
166 +
167 +        try {
168 +            a.get();
169 +            shouldThrow();
170 +        } catch (ExecutionException success) {
171 +            assertSame(t, success.getCause());
172 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
173 +
174 +        try {
175 +            a.get(5L, SECONDS);
176 +            shouldThrow();
177 +        } catch (ExecutionException success) {
178 +            assertSame(t, success.getCause());
179 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
180 +    }
181 +
182      static final class FJException extends RuntimeException {
183          FJException() { super(); }
184      }
# Line 74 | Line 198 | public class RecursiveTaskTest extends J
198              f1.fork();
199              return (new FibTask(n - 2)).compute() + f1.join();
200          }
201 +
202 +        public void publicSetRawResult(Integer result) {
203 +            setRawResult(result);
204 +        }
205      }
206  
207      // A recursive action failing in base case
# Line 103 | Line 231 | public class RecursiveTaskTest extends J
231                  FibTask f = new FibTask(8);
232                  Integer r = f.invoke();
233                  assertEquals(21, (int) r);
234 <                assertTrue(f.isDone());
107 <                assertFalse(f.isCancelled());
108 <                assertFalse(f.isCompletedAbnormally());
109 <                assertEquals(21, (int) f.getRawResult());
234 >                checkCompletedNormally(f, r);
235                  return r;
236              }};
237          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
# Line 122 | Line 247 | public class RecursiveTaskTest extends J
247              public Integer realCompute() {
248                  FibTask f = new FibTask(8);
249                  f.quietlyInvoke();
250 <                Integer r = f.getRawResult();
251 <                assertEquals(21, (int) r);
127 <                assertTrue(f.isDone());
128 <                assertFalse(f.isCancelled());
129 <                assertFalse(f.isCompletedAbnormally());
130 <                return r;
250 >                checkCompletedNormally(f, 21);
251 >                return NoResult;
252              }};
253 <        assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
253 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
254      }
255  
256      /**
# Line 142 | Line 263 | public class RecursiveTaskTest extends J
263                  assertSame(f, f.fork());
264                  Integer r = f.join();
265                  assertEquals(21, (int) r);
266 <                assertTrue(f.isDone());
266 >                checkCompletedNormally(f, r);
267                  return r;
268              }};
269          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
# Line 158 | Line 279 | public class RecursiveTaskTest extends J
279                  assertSame(f, f.fork());
280                  Integer r = f.get();
281                  assertEquals(21, (int) r);
282 <                assertTrue(f.isDone());
282 >                checkCompletedNormally(f, r);
283                  return r;
284              }};
285          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
# Line 172 | Line 293 | public class RecursiveTaskTest extends J
293              public Integer realCompute() throws Exception {
294                  FibTask f = new FibTask(8);
295                  assertSame(f, f.fork());
296 <                Integer r = f.get(5L, TimeUnit.SECONDS);
296 >                Integer r = f.get(5L, SECONDS);
297                  assertEquals(21, (int) r);
298 <                assertTrue(f.isDone());
298 >                checkCompletedNormally(f, r);
299                  return r;
300              }};
301          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
# Line 191 | Line 312 | public class RecursiveTaskTest extends J
312                  f.quietlyJoin();
313                  Integer r = f.getRawResult();
314                  assertEquals(21, (int) r);
315 <                assertTrue(f.isDone());
315 >                checkCompletedNormally(f, r);
316                  return r;
317              }};
318          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
# Line 208 | Line 329 | public class RecursiveTaskTest extends J
329                  FibTask f = new FibTask(8);
330                  assertSame(f, f.fork());
331                  f.helpQuiesce();
211                Integer r = f.getRawResult();
212                assertEquals(21, (int) r);
213                assertTrue(f.isDone());
332                  assertEquals(0, getQueuedTaskCount());
333 <                return r;
333 >                checkCompletedNormally(f, 21);
334 >                return NoResult;
335              }};
336 <        assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
336 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
337      }
338  
339  
# Line 228 | Line 347 | public class RecursiveTaskTest extends J
347                  try {
348                      f.invoke();
349                      shouldThrow();
350 <                    return NoResult;
351 <                } catch (FJException success) {}
350 >                } catch (FJException success) {
351 >                    checkCompletedAbnormally(f, success);
352 >                }
353                  return NoResult;
354              }};
355          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 243 | Line 363 | public class RecursiveTaskTest extends J
363              public Integer realCompute() {
364                  FailingFibTask f = new FailingFibTask(8);
365                  f.quietlyInvoke();
366 <                assertTrue(f.isDone());
366 >                assertTrue(f.getException() instanceof FJException);
367 >                checkCompletedAbnormally(f, f.getException());
368                  return NoResult;
369              }};
370          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 260 | Line 381 | public class RecursiveTaskTest extends J
381                  try {
382                      Integer r = f.join();
383                      shouldThrow();
384 <                    return r;
385 <                } catch (FJException success) {}
384 >                } catch (FJException success) {
385 >                    checkCompletedAbnormally(f, success);
386 >                }
387                  return NoResult;
388              }};
389          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 278 | Line 400 | public class RecursiveTaskTest extends J
400                  try {
401                      Integer r = f.get();
402                      shouldThrow();
403 <                    return r;
404 <                } catch (ExecutionException success) {}
403 >                } catch (ExecutionException success) {
404 >                    Throwable cause = success.getCause();
405 >                    assertTrue(cause instanceof FJException);
406 >                    checkCompletedAbnormally(f, cause);
407 >                }
408                  return NoResult;
409              }};
410          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 294 | Line 419 | public class RecursiveTaskTest extends J
419                  FailingFibTask f = new FailingFibTask(8);
420                  assertSame(f, f.fork());
421                  try {
422 <                    Integer r = f.get(5L, TimeUnit.SECONDS);
422 >                    Integer r = f.get(5L, SECONDS);
423                      shouldThrow();
424 <                    return r;
425 <                } catch (ExecutionException success) {}
424 >                } catch (ExecutionException success) {
425 >                    Throwable cause = success.getCause();
426 >                    assertTrue(cause instanceof FJException);
427 >                    checkCompletedAbnormally(f, cause);
428 >                }
429                  return NoResult;
430              }};
431          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 312 | Line 440 | public class RecursiveTaskTest extends J
440                  FailingFibTask f = new FailingFibTask(8);
441                  assertSame(f, f.fork());
442                  f.quietlyJoin();
315                assertTrue(f.isDone());
316                assertTrue(f.isCompletedAbnormally());
443                  assertTrue(f.getException() instanceof FJException);
444 +                checkCompletedAbnormally(f, f.getException());
445                  return NoResult;
446              }};
447          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 331 | Line 458 | public class RecursiveTaskTest extends J
458                  try {
459                      Integer r = f.invoke();
460                      shouldThrow();
461 <                    return r;
462 <                } catch (CancellationException success) {}
461 >                } catch (CancellationException success) {
462 >                    checkCancelled(f);
463 >                }
464                  return NoResult;
465              }};
466          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 350 | Line 478 | public class RecursiveTaskTest extends J
478                  try {
479                      Integer r = f.join();
480                      shouldThrow();
481 <                    return r;
482 <                } catch (CancellationException success) {}
481 >                } catch (CancellationException success) {
482 >                    checkCancelled(f);
483 >                }
484                  return NoResult;
485              }};
486          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 369 | Line 498 | public class RecursiveTaskTest extends J
498                  try {
499                      Integer r = f.get();
500                      shouldThrow();
501 <                    return r;
502 <                } catch (CancellationException success) {}
501 >                } catch (CancellationException success) {
502 >                    checkCancelled(f);
503 >                }
504                  return NoResult;
505              }};
506          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 386 | Line 516 | public class RecursiveTaskTest extends J
516                  assertTrue(f.cancel(true));
517                  assertSame(f, f.fork());
518                  try {
519 <                    Integer r = f.get(5L, TimeUnit.SECONDS);
519 >                    Integer r = f.get(5L, SECONDS);
520                      shouldThrow();
521 <                    return r;
522 <                } catch (CancellationException success) {}
521 >                } catch (CancellationException success) {
522 >                    checkCancelled(f);
523 >                }
524                  return NoResult;
525              }};
526          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 405 | Line 536 | public class RecursiveTaskTest extends J
536                  assertTrue(f.cancel(true));
537                  assertSame(f, f.fork());
538                  f.quietlyJoin();
539 <                assertTrue(f.isDone());
409 <                assertTrue(f.isCompletedAbnormally());
410 <                assertTrue(f.isCancelled());
411 <                assertTrue(f.getException() instanceof CancellationException);
539 >                checkCancelled(f);
540                  return NoResult;
541              }};
542          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 457 | Line 585 | public class RecursiveTaskTest extends J
585      public void testInForkJoinPool2() {
586          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
587              public Integer realCompute() {
588 <                assertTrue(!inForkJoinPool());
588 >                assertFalse(inForkJoinPool());
589                  return NoResult;
590              }};
591          assertSame(NoResult, a.invoke());
# Line 474 | Line 602 | public class RecursiveTaskTest extends J
602                  return NoResult;
603              }
604          };
605 <        a.invoke();
605 >        assertSame(NoResult, a.invoke());
606      }
607  
608      /**
609 <     * A reinitialized task may be re-invoked
609 >     * A reinitialized normally completed task may be re-invoked
610       */
611      public void testReinitialize() {
612          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
613              public Integer realCompute() {
614                  FibTask f = new FibTask(8);
615 <                Integer r = f.invoke();
616 <                assertEquals(21, (int) r);
617 <                assertTrue(f.isDone());
618 <                assertFalse(f.isCancelled());
619 <                assertFalse(f.isCompletedAbnormally());
620 <                f.reinitialize();
621 <                r = f.invoke();
622 <                assertEquals(21, (int) r);
615 >                checkNotDone(f);
616 >
617 >                for (int i = 0; i < 3; i++) {
618 >                    Integer r = f.invoke();
619 >                    assertEquals(21, (int) r);
620 >                    checkCompletedNormally(f, r);
621 >                    f.reinitialize();
622 >                    f.publicSetRawResult(null);
623 >                    checkNotDone(f);
624 >                }
625 >                return NoResult;
626 >            }};
627 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
628 >    }
629 >
630 >    /**
631 >     * A reinitialized abnormally completed task may be re-invoked
632 >     */
633 >    public void testReinitializeAbnormal() {
634 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
635 >            public Integer realCompute() {
636 >                FailingFibTask f = new FailingFibTask(8);
637 >                checkNotDone(f);
638 >
639 >                for (int i = 0; i < 3; i++) {
640 >                    try {
641 >                        f.invoke();
642 >                        shouldThrow();
643 >                    } catch (FJException success) {
644 >                        checkCompletedAbnormally(f, success);
645 >                    }
646 >                    f.reinitialize();
647 >                    checkNotDone(f);
648 >                }
649                  return NoResult;
650              }};
651          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 508 | Line 662 | public class RecursiveTaskTest extends J
662                  try {
663                      Integer r = f.invoke();
664                      shouldThrow();
665 <                    return r;
666 <                } catch (FJException success) {}
665 >                } catch (FJException success) {
666 >                    checkCompletedAbnormally(f, success);
667 >                }
668                  return NoResult;
669              }};
670          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 524 | Line 679 | public class RecursiveTaskTest extends J
679                  FibTask f = new FibTask(8);
680                  f.complete(NoResult);
681                  Integer r = f.invoke();
527                assertTrue(f.isDone());
682                  assertSame(NoResult, r);
683 +                checkCompletedNormally(f, NoResult);
684                  return r;
685              }};
686          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 540 | Line 695 | public class RecursiveTaskTest extends J
695                  FibTask f = new FibTask(8);
696                  FibTask g = new FibTask(9);
697                  invokeAll(f, g);
698 <                assertTrue(f.isDone());
699 <                assertEquals(21, (int) f.join());
545 <                assertTrue(g.isDone());
546 <                assertEquals(34, (int) g.join());
698 >                checkCompletedNormally(f, 21);
699 >                checkCompletedNormally(g, 34);
700                  return NoResult;
701              }};
702          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 557 | Line 710 | public class RecursiveTaskTest extends J
710              public Integer realCompute() {
711                  FibTask f = new FibTask(8);
712                  invokeAll(f);
713 <                assertTrue(f.isDone());
561 <                assertEquals(21, (int) f.join());
713 >                checkCompletedNormally(f, 21);
714                  return NoResult;
715              }};
716          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 575 | Line 727 | public class RecursiveTaskTest extends J
727                  FibTask h = new FibTask(7);
728                  invokeAll(f, g, h);
729                  assertTrue(f.isDone());
578                assertEquals(21, (int) f.join());
730                  assertTrue(g.isDone());
580                assertEquals(34, (int) g.join());
731                  assertTrue(h.isDone());
732 <                assertEquals(13, (int) h.join());
732 >                checkCompletedNormally(f, 21);
733 >                checkCompletedNormally(g, 34);
734 >                checkCompletedNormally(h, 13);
735                  return NoResult;
736              }};
737          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 600 | Line 752 | public class RecursiveTaskTest extends J
752                  set.add(h);
753                  invokeAll(set);
754                  assertTrue(f.isDone());
603                assertEquals(21, (int) f.join());
755                  assertTrue(g.isDone());
605                assertEquals(34, (int) g.join());
756                  assertTrue(h.isDone());
757 <                assertEquals(13, (int) h.join());
757 >                checkCompletedNormally(f, 21);
758 >                checkCompletedNormally(g, 34);
759 >                checkCompletedNormally(h, 13);
760                  return NoResult;
761              }};
762          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 612 | Line 764 | public class RecursiveTaskTest extends J
764  
765  
766      /**
767 +     * invokeAll(tasks) with any null task throws NPE
768 +     */
769 +    public void testInvokeAllNPE() {
770 +        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
771 +            public Integer realCompute() {
772 +                FibTask f = new FibTask(8);
773 +                FibTask g = new FibTask(9);
774 +                FibTask h = null;
775 +                try {
776 +                    invokeAll(f, g, h);
777 +                    shouldThrow();
778 +                } catch (NullPointerException success) {}
779 +                return NoResult;
780 +            }};
781 +        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
782 +    }
783 +
784 +    /**
785       * invokeAll(t1, t2) throw exception if any task does
786       */
787      public void testAbnormalInvokeAll2() {
# Line 622 | Line 792 | public class RecursiveTaskTest extends J
792                  try {
793                      invokeAll(f, g);
794                      shouldThrow();
795 <                    return NoResult;
796 <                } catch (FJException success) {}
795 >                } catch (FJException success) {
796 >                    checkCompletedAbnormally(g, success);
797 >                }
798                  return NoResult;
799              }};
800          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 639 | Line 810 | public class RecursiveTaskTest extends J
810                  try {
811                      invokeAll(g);
812                      shouldThrow();
813 <                    return NoResult;
814 <                } catch (FJException success) {}
813 >                } catch (FJException success) {
814 >                    checkCompletedAbnormally(g, success);
815 >                }
816                  return NoResult;
817              }};
818          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 658 | Line 830 | public class RecursiveTaskTest extends J
830                  try {
831                      invokeAll(f, g, h);
832                      shouldThrow();
833 <                    return NoResult;
834 <                } catch (FJException success) {}
833 >                } catch (FJException success) {
834 >                    checkCompletedAbnormally(g, success);
835 >                }
836                  return NoResult;
837              }};
838          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 681 | Line 854 | public class RecursiveTaskTest extends J
854                  try {
855                      invokeAll(set);
856                      shouldThrow();
857 <                    return NoResult;
858 <                } catch (FJException success) {}
857 >                } catch (FJException success) {
858 >                    checkCompletedAbnormally(f, success);
859 >                }
860                  return NoResult;
861              }};
862          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 701 | Line 875 | public class RecursiveTaskTest extends J
875                  assertSame(f, f.fork());
876                  assertTrue(f.tryUnfork());
877                  helpQuiesce();
878 <                assertFalse(f.isDone());
879 <                assertTrue(g.isDone());
878 >                checkNotDone(f);
879 >                checkCompletedNormally(g, 34);
880                  return NoResult;
881              }};
882          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 723 | Line 897 | public class RecursiveTaskTest extends J
897                  assertSame(f, f.fork());
898                  assertTrue(getSurplusQueuedTaskCount() > 0);
899                  helpQuiesce();
900 +                assertEquals(0, getSurplusQueuedTaskCount());
901 +                checkCompletedNormally(f, 21);
902 +                checkCompletedNormally(g, 34);
903 +                checkCompletedNormally(h, 13);
904                  return NoResult;
905              }};
906          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 739 | Line 917 | public class RecursiveTaskTest extends J
917                  FibTask f = new FibTask(8);
918                  assertSame(f, f.fork());
919                  assertSame(f, peekNextLocalTask());
920 <                assertEquals(21, (int) f.join());
743 <                assertTrue(f.isDone());
920 >                checkCompletesNormally(f, 21);
921                  helpQuiesce();
922 +                checkCompletedNormally(g, 34);
923                  return NoResult;
924              }};
925          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 760 | Line 938 | public class RecursiveTaskTest extends J
938                  assertSame(f, f.fork());
939                  assertSame(f, pollNextLocalTask());
940                  helpQuiesce();
941 <                assertFalse(f.isDone());
941 >                checkNotDone(f);
942 >                checkCompletedNormally(g, 34);
943                  return NoResult;
944              }};
945          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 778 | Line 957 | public class RecursiveTaskTest extends J
957                  assertSame(f, f.fork());
958                  assertSame(f, pollTask());
959                  helpQuiesce();
960 <                assertFalse(f.isDone());
961 <                assertTrue(g.isDone());
960 >                checkNotDone(f);
961 >                checkCompletedNormally(g, 34);
962                  return NoResult;
963              }};
964          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 798 | Line 977 | public class RecursiveTaskTest extends J
977                  assertSame(g, peekNextLocalTask());
978                  assertEquals(21, (int) f.join());
979                  helpQuiesce();
980 <                assertTrue(f.isDone());
980 >                checkCompletedNormally(f, 21);
981 >                checkCompletedNormally(g, 34);
982                  return NoResult;
983              }};
984          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
985      }
986  
987      /**
988 <     * pollNextLocalTask returns least recent unexecuted task
989 <     * without executing it, in async mode
988 >     * pollNextLocalTask returns least recent unexecuted task without
989 >     * executing it, in async mode
990       */
991      public void testPollNextLocalTaskAsync() {
992          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
# Line 817 | Line 997 | public class RecursiveTaskTest extends J
997                  assertSame(f, f.fork());
998                  assertSame(g, pollNextLocalTask());
999                  helpQuiesce();
1000 <                assertTrue(f.isDone());
1001 <                assertFalse(g.isDone());
1000 >                checkCompletedNormally(f, 21);
1001 >                checkNotDone(g);
1002                  return NoResult;
1003              }};
1004          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
1005      }
1006  
1007      /**
1008 <     * pollTask returns an unexecuted task
1009 <     * without executing it, in async mode
1008 >     * pollTask returns an unexecuted task without executing it, in
1009 >     * async mode
1010       */
1011      public void testPollTaskAsync() {
1012          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
# Line 837 | Line 1017 | public class RecursiveTaskTest extends J
1017                  assertSame(f, f.fork());
1018                  assertSame(g, pollTask());
1019                  helpQuiesce();
1020 <                assertTrue(f.isDone());
1021 <                assertFalse(g.isDone());
1020 >                checkCompletedNormally(f, 21);
1021 >                checkNotDone(g);
1022                  return NoResult;
1023              }};
1024          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines