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.34 by jsr166, Wed Oct 7 00:15:23 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
7 > import static java.util.concurrent.TimeUnit.SECONDS;
8 >
9 > import java.util.HashSet;
10   import java.util.concurrent.CancellationException;
11   import java.util.concurrent.ExecutionException;
12   import java.util.concurrent.ForkJoinPool;
13 + import java.util.concurrent.ForkJoinTask;
14   import java.util.concurrent.RecursiveTask;
15 < import java.util.concurrent.TimeUnit;
16 < import java.util.HashSet;
15 > import java.util.concurrent.TimeoutException;
16 >
17 > import junit.framework.Test;
18 > import junit.framework.TestSuite;
19  
20   public class RecursiveTaskTest extends JSR166TestCase {
21  
22      public static void main(String[] args) {
23 <        junit.textui.TestRunner.run(suite());
23 >        main(suite(), args);
24      }
25      public static Test suite() {
26          return new TestSuite(RecursiveTaskTest.class);
# Line 36 | Line 41 | public class RecursiveTaskTest extends J
41      }
42  
43      private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) {
44 <        try {
45 <            assertFalse(a.isDone());
41 <            assertFalse(a.isCompletedNormally());
42 <            assertFalse(a.isCompletedAbnormally());
43 <            assertFalse(a.isCancelled());
44 >        try (PoolCleaner cleaner = cleaner(pool)) {
45 >            checkNotDone(a);
46  
47              T result = pool.invoke(a);
48  
49 <            assertTrue(a.isDone());
48 <            assertTrue(a.isCompletedNormally());
49 <            assertFalse(a.isCompletedAbnormally());
50 <            assertFalse(a.isCancelled());
51 <            assertNull(a.getException());
49 >            checkCompletedNormally(a, result);
50              return result;
53        } finally {
54            joinPool(pool);
51          }
52      }
53  
54 <    static final class FJException extends RuntimeException {
55 <        FJException() { super(); }
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 (! ForkJoinTask.inForkJoinPool()) {
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.getClass(), a.getException().getClass());
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.getClass(), expected.getClass());
165 >        }
166 >
167 >        try {
168 >            a.get();
169 >            shouldThrow();
170 >        } catch (ExecutionException success) {
171 >            assertSame(t.getClass(), success.getCause().getClass());
172 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
173 >
174 >        try {
175 >            a.get(5L, SECONDS);
176 >            shouldThrow();
177 >        } catch (ExecutionException success) {
178 >            assertSame(t.getClass(), success.getCause().getClass());
179 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
180 >    }
181 >
182 >    public static final class FJException extends RuntimeException {
183 >        public FJException() { super(); }
184      }
185  
186      // An invalid return value for Fib
# 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));
319      }
320  
200
321      /**
322       * helpQuiesce returns when tasks are complete.
323       * getQueuedTaskCount returns 0 when quiescent
# Line 207 | Line 327 | public class RecursiveTaskTest extends J
327              public Integer realCompute() {
328                  FibTask f = new FibTask(8);
329                  assertSame(f, f.fork());
330 <                f.helpQuiesce();
331 <                Integer r = f.getRawResult();
332 <                assertEquals(21, (int) r);
213 <                assertTrue(f.isDone());
330 >                helpQuiesce();
331 >                while (!f.isDone()) // wait out race
332 >                    ;
333                  assertEquals(0, getQueuedTaskCount());
334 <                return r;
334 >                checkCompletedNormally(f, 21);
335 >                return NoResult;
336              }};
337 <        assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
337 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
338      }
339  
220
340      /**
341       * invoke task throws exception when task completes abnormally
342       */
# 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));
763      }
764  
765 +    /**
766 +     * invokeAll(tasks) with any null task throws NPE
767 +     */
768 +    public void testInvokeAllNPE() {
769 +        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
770 +            public Integer realCompute() {
771 +                FibTask f = new FibTask(8);
772 +                FibTask g = new FibTask(9);
773 +                FibTask h = null;
774 +                try {
775 +                    invokeAll(f, g, h);
776 +                    shouldThrow();
777 +                } catch (NullPointerException success) {}
778 +                return NoResult;
779 +            }};
780 +        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
781 +    }
782  
783      /**
784       * invokeAll(t1, t2) throw exception if any task does
# Line 622 | Line 791 | public class RecursiveTaskTest extends J
791                  try {
792                      invokeAll(f, g);
793                      shouldThrow();
794 <                    return NoResult;
795 <                } catch (FJException success) {}
794 >                } catch (FJException success) {
795 >                    checkCompletedAbnormally(g, success);
796 >                }
797                  return NoResult;
798              }};
799          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 639 | Line 809 | public class RecursiveTaskTest extends J
809                  try {
810                      invokeAll(g);
811                      shouldThrow();
812 <                    return NoResult;
813 <                } catch (FJException success) {}
812 >                } catch (FJException success) {
813 >                    checkCompletedAbnormally(g, success);
814 >                }
815                  return NoResult;
816              }};
817          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 658 | Line 829 | public class RecursiveTaskTest extends J
829                  try {
830                      invokeAll(f, g, h);
831                      shouldThrow();
832 <                    return NoResult;
833 <                } catch (FJException success) {}
832 >                } catch (FJException success) {
833 >                    checkCompletedAbnormally(g, success);
834 >                }
835                  return NoResult;
836              }};
837          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 681 | Line 853 | public class RecursiveTaskTest extends J
853                  try {
854                      invokeAll(set);
855                      shouldThrow();
856 <                    return NoResult;
857 <                } catch (FJException success) {}
856 >                } catch (FJException success) {
857 >                    checkCompletedAbnormally(f, success);
858 >                }
859                  return NoResult;
860              }};
861          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
# Line 701 | Line 874 | public class RecursiveTaskTest extends J
874                  assertSame(f, f.fork());
875                  assertTrue(f.tryUnfork());
876                  helpQuiesce();
877 <                assertFalse(f.isDone());
878 <                assertTrue(g.isDone());
877 >                checkNotDone(f);
878 >                checkCompletedNormally(g, 34);
879                  return NoResult;
880              }};
881          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 723 | Line 896 | public class RecursiveTaskTest extends J
896                  assertSame(f, f.fork());
897                  assertTrue(getSurplusQueuedTaskCount() > 0);
898                  helpQuiesce();
899 +                assertEquals(0, getSurplusQueuedTaskCount());
900 +                checkCompletedNormally(f, 21);
901 +                checkCompletedNormally(g, 34);
902 +                checkCompletedNormally(h, 13);
903                  return NoResult;
904              }};
905          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 739 | Line 916 | public class RecursiveTaskTest extends J
916                  FibTask f = new FibTask(8);
917                  assertSame(f, f.fork());
918                  assertSame(f, peekNextLocalTask());
919 <                assertEquals(21, (int) f.join());
743 <                assertTrue(f.isDone());
919 >                checkCompletesNormally(f, 21);
920                  helpQuiesce();
921 +                checkCompletedNormally(g, 34);
922                  return NoResult;
923              }};
924          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 760 | Line 937 | public class RecursiveTaskTest extends J
937                  assertSame(f, f.fork());
938                  assertSame(f, pollNextLocalTask());
939                  helpQuiesce();
940 <                assertFalse(f.isDone());
940 >                checkNotDone(f);
941 >                checkCompletedNormally(g, 34);
942                  return NoResult;
943              }};
944          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 778 | Line 956 | public class RecursiveTaskTest extends J
956                  assertSame(f, f.fork());
957                  assertSame(f, pollTask());
958                  helpQuiesce();
959 <                assertFalse(f.isDone());
960 <                assertTrue(g.isDone());
959 >                checkNotDone(f);
960 >                checkCompletedNormally(g, 34);
961                  return NoResult;
962              }};
963          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
# Line 798 | Line 976 | public class RecursiveTaskTest extends J
976                  assertSame(g, peekNextLocalTask());
977                  assertEquals(21, (int) f.join());
978                  helpQuiesce();
979 <                assertTrue(f.isDone());
979 >                checkCompletedNormally(f, 21);
980 >                checkCompletedNormally(g, 34);
981                  return NoResult;
982              }};
983          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
984      }
985  
986      /**
987 <     * pollNextLocalTask returns least recent unexecuted task
988 <     * without executing it, in async mode
987 >     * pollNextLocalTask returns least recent unexecuted task without
988 >     * executing it, in async mode
989       */
990      public void testPollNextLocalTaskAsync() {
991          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
# Line 817 | Line 996 | public class RecursiveTaskTest extends J
996                  assertSame(f, f.fork());
997                  assertSame(g, pollNextLocalTask());
998                  helpQuiesce();
999 <                assertTrue(f.isDone());
1000 <                assertFalse(g.isDone());
999 >                checkCompletedNormally(f, 21);
1000 >                checkNotDone(g);
1001                  return NoResult;
1002              }};
1003          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
1004      }
1005  
1006      /**
1007 <     * pollTask returns an unexecuted task
1008 <     * without executing it, in async mode
1007 >     * pollTask returns an unexecuted task without executing it, in
1008 >     * async mode
1009       */
1010      public void testPollTaskAsync() {
1011          RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
# Line 837 | Line 1016 | public class RecursiveTaskTest extends J
1016                  assertSame(f, f.fork());
1017                  assertSame(g, pollTask());
1018                  helpQuiesce();
1019 <                assertTrue(f.isDone());
1020 <                assertFalse(g.isDone());
1019 >                checkCompletedNormally(f, 21);
1020 >                checkNotDone(g);
1021                  return NoResult;
1022              }};
1023          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines