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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.18 by jsr166, Thu Sep 16 00:52:49 2010 UTC vs.
Revision 1.29 by dl, Tue Feb 22 01:18:59 2011 UTC

# Line 6 | Line 6
6  
7   import junit.framework.*;
8   import java.util.concurrent.CancellationException;
9 + import java.util.concurrent.SynchronousQueue;
10   import java.util.concurrent.ExecutionException;
11   import java.util.concurrent.ForkJoinPool;
12 + import java.util.concurrent.ForkJoinTask;
13   import java.util.concurrent.ForkJoinWorkerThread;
14   import java.util.concurrent.RecursiveAction;
15   import java.util.concurrent.TimeUnit;
16 + import java.util.concurrent.TimeoutException;
17 + import static java.util.concurrent.TimeUnit.SECONDS;
18   import java.util.HashSet;
19  
20   public class RecursiveActionTest extends JSR166TestCase {
# Line 39 | Line 43 | public class RecursiveActionTest extends
43  
44      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
45          try {
46 <            assertFalse(a.isDone());
43 <            assertFalse(a.isCompletedNormally());
44 <            assertFalse(a.isCompletedAbnormally());
45 <            assertFalse(a.isCancelled());
46 <            assertNull(a.getException());
46 >            checkNotDone(a);
47  
48              assertNull(pool.invoke(a));
49  
50 <            assertTrue(a.isDone());
51 <            assertTrue(a.isCompletedNormally());
52 <            assertFalse(a.isCompletedAbnormally());
53 <            assertFalse(a.isCancelled());
54 <            assertNull(a.getException());
50 >            checkCompletedNormally(a);
51          } finally {
52              joinPool(pool);
53          }
54      }
55  
56 <    static final class FJException extends RuntimeException {
57 <        FJException() { super(); }
56 >    void checkNotDone(RecursiveAction a) {
57 >        assertFalse(a.isDone());
58 >        assertFalse(a.isCompletedNormally());
59 >        assertFalse(a.isCompletedAbnormally());
60 >        assertFalse(a.isCancelled());
61 >        assertNull(a.getException());
62 >        assertNull(a.getRawResult());
63 >
64 >        if (! ForkJoinTask.inForkJoinPool()) {
65 >            Thread.currentThread().interrupt();
66 >            try {
67 >                a.get();
68 >                shouldThrow();
69 >            } catch (InterruptedException success) {
70 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
71 >
72 >            Thread.currentThread().interrupt();
73 >            try {
74 >                a.get(5L, SECONDS);
75 >                shouldThrow();
76 >            } catch (InterruptedException success) {
77 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
78 >        }
79 >
80 >        try {
81 >            a.get(0L, SECONDS);
82 >            shouldThrow();
83 >        } catch (TimeoutException success) {
84 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
85 >    }
86 >
87 >    void checkCompletedNormally(RecursiveAction a) {
88 >        assertTrue(a.isDone());
89 >        assertFalse(a.isCancelled());
90 >        assertTrue(a.isCompletedNormally());
91 >        assertFalse(a.isCompletedAbnormally());
92 >        assertNull(a.getException());
93 >        assertNull(a.getRawResult());
94 >        assertNull(a.join());
95 >        assertFalse(a.cancel(false));
96 >        assertFalse(a.cancel(true));
97 >        try {
98 >            assertNull(a.get());
99 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
100 >        try {
101 >            assertNull(a.get(5L, SECONDS));
102 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
103 >    }
104 >
105 >    void checkCancelled(RecursiveAction 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(RecursiveAction a, Throwable t) {
133 >        assertTrue(a.isDone());
134 >        assertFalse(a.isCancelled());
135 >        assertFalse(a.isCompletedNormally());
136 >        assertTrue(a.isCompletedAbnormally());
137 >        assertSame(t.getClass(), a.getException().getClass());
138 >        assertNull(a.getRawResult());
139 >        assertFalse(a.cancel(false));
140 >        assertFalse(a.cancel(true));
141 >
142 >        try {
143 >            a.join();
144 >            shouldThrow();
145 >        } catch (Throwable expected) {
146 >            assertSame(expected.getClass(), t.getClass());
147 >        }
148 >
149 >        try {
150 >            a.get();
151 >            shouldThrow();
152 >        } catch (ExecutionException success) {
153 >            assertSame(t.getClass(), success.getCause().getClass());
154 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
155 >
156 >        try {
157 >            a.get(5L, SECONDS);
158 >            shouldThrow();
159 >        } catch (ExecutionException success) {
160 >            assertSame(t.getClass(), success.getCause().getClass());
161 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
162 >    }
163 >
164 >    public static final class FJException extends RuntimeException {
165 >        public FJException() { super(); }
166 >        public FJException(Throwable cause) { super(cause); }
167      }
168  
169      // A simple recursive action for testing
# Line 108 | Line 213 | public class RecursiveActionTest extends
213                  FibAction f = new FibAction(8);
214                  assertNull(f.invoke());
215                  assertEquals(21, f.result);
216 <                assertTrue(f.isDone());
112 <                assertFalse(f.isCancelled());
113 <                assertFalse(f.isCompletedAbnormally());
114 <                assertNull(f.getRawResult());
216 >                checkCompletedNormally(f);
217              }};
218          testInvokeOnPool(mainPool(), a);
219      }
# Line 127 | Line 229 | public class RecursiveActionTest extends
229                  FibAction f = new FibAction(8);
230                  f.quietlyInvoke();
231                  assertEquals(21, f.result);
232 <                assertTrue(f.isDone());
131 <                assertFalse(f.isCancelled());
132 <                assertFalse(f.isCompletedAbnormally());
133 <                assertNull(f.getRawResult());
232 >                checkCompletedNormally(f);
233              }};
234          testInvokeOnPool(mainPool(), a);
235      }
# Line 145 | Line 244 | public class RecursiveActionTest extends
244                  assertSame(f, f.fork());
245                  assertNull(f.join());
246                  assertEquals(21, f.result);
247 <                assertTrue(f.isDone());
248 <                assertNull(f.getRawResult());
247 >                checkCompletedNormally(f);
248 >            }};
249 >        testInvokeOnPool(mainPool(), a);
250 >    }
251 >
252 >    /**
253 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
254 >     */
255 >    public void testJoinIgnoresInterrupts() {
256 >        RecursiveAction a = new CheckedRecursiveAction() {
257 >            public void realCompute() {
258 >                FibAction f = new FibAction(8);
259 >                final Thread myself = Thread.currentThread();
260 >
261 >                // test join()
262 >                assertSame(f, f.fork());
263 >                myself.interrupt();
264 >                assertTrue(myself.isInterrupted());
265 >                assertNull(f.join());
266 >                Thread.interrupted();
267 >                assertEquals(21, f.result);
268 >                checkCompletedNormally(f);
269 >
270 >                f.reinitialize();
271 >                f.cancel(true);
272 >                assertSame(f, f.fork());
273 >                myself.interrupt();
274 >                assertTrue(myself.isInterrupted());
275 >                try {
276 >                    f.join();
277 >                    shouldThrow();
278 >                } catch (CancellationException success) {
279 >                    Thread.interrupted();
280 >                    checkCancelled(f);
281 >                }
282 >
283 >                f.reinitialize();
284 >                f.completeExceptionally(new FJException());
285 >                assertSame(f, f.fork());
286 >                myself.interrupt();
287 >                assertTrue(myself.isInterrupted());
288 >                try {
289 >                    f.join();
290 >                    shouldThrow();
291 >                } catch (FJException success) {
292 >                    Thread.interrupted();
293 >                    checkCompletedAbnormally(f, success);
294 >                }
295 >
296 >                // test quietlyJoin()
297 >                f.reinitialize();
298 >                assertSame(f, f.fork());
299 >                myself.interrupt();
300 >                assertTrue(myself.isInterrupted());
301 >                f.quietlyJoin();
302 >                Thread.interrupted();
303 >                assertEquals(21, f.result);
304 >                checkCompletedNormally(f);
305 >
306 >                f.reinitialize();
307 >                f.cancel(true);
308 >                assertSame(f, f.fork());
309 >                myself.interrupt();
310 >                assertTrue(myself.isInterrupted());
311 >                f.quietlyJoin();
312 >                Thread.interrupted();
313 >                checkCancelled(f);
314 >
315 >                f.reinitialize();
316 >                f.completeExceptionally(new FJException());
317 >                assertSame(f, f.fork());
318 >                myself.interrupt();
319 >                assertTrue(myself.isInterrupted());
320 >                f.quietlyJoin();
321 >                Thread.interrupted();
322 >                checkCompletedAbnormally(f, f.getException());
323 >            }};
324 >        testInvokeOnPool(mainPool(), a);
325 >        a.reinitialize();
326 >        testInvokeOnPool(singletonPool(), a);
327 >    }
328 >
329 >    /**
330 >     * join/quietlyJoin of a forked task when not in ForkJoinPool
331 >     * succeeds in the presence of interrupts
332 >     */
333 >    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
334 >        final SynchronousQueue<FibAction[]> sq =
335 >            new SynchronousQueue<FibAction[]>();
336 >        RecursiveAction a = new CheckedRecursiveAction() {
337 >            public void realCompute() throws InterruptedException {
338 >                FibAction[] fibActions = new FibAction[6];
339 >                for (int i = 0; i < fibActions.length; i++)
340 >                    fibActions[i] = new FibAction(8);
341 >
342 >                fibActions[1].cancel(false);
343 >                fibActions[2].completeExceptionally(new FJException());
344 >                fibActions[4].cancel(true);
345 >                fibActions[5].completeExceptionally(new FJException());
346 >
347 >                for (int i = 0; i < fibActions.length; i++)
348 >                    fibActions[i].fork();
349 >
350 >                sq.put(fibActions);
351 >
352 >                helpQuiesce();
353 >            }};
354 >
355 >        Runnable r = new CheckedRunnable() {
356 >            public void realRun() throws InterruptedException {
357 >                FibAction[] fibActions = sq.take();
358 >                FibAction f;
359 >                final Thread myself = Thread.currentThread();
360 >
361 >                // test join() ------------
362 >
363 >                f = fibActions[0];
364 >                assertFalse(ForkJoinTask.inForkJoinPool());
365 >                myself.interrupt();
366 >                assertTrue(myself.isInterrupted());
367 >                assertNull(f.join());
368 >                assertTrue(Thread.interrupted());
369 >                assertEquals(21, f.result);
370 >                checkCompletedNormally(f);
371 >
372 >                f = fibActions[1];
373 >                myself.interrupt();
374 >                assertTrue(myself.isInterrupted());
375 >                try {
376 >                    f.join();
377 >                    shouldThrow();
378 >                } catch (CancellationException success) {
379 >                    assertTrue(Thread.interrupted());
380 >                    checkCancelled(f);
381 >                }
382 >
383 >                f = fibActions[2];
384 >                myself.interrupt();
385 >                assertTrue(myself.isInterrupted());
386 >                try {
387 >                    f.join();
388 >                    shouldThrow();
389 >                } catch (FJException success) {
390 >                    assertTrue(Thread.interrupted());
391 >                    checkCompletedAbnormally(f, success);
392 >                }
393 >
394 >                // test quietlyJoin() ---------
395 >
396 >                f = fibActions[3];
397 >                myself.interrupt();
398 >                assertTrue(myself.isInterrupted());
399 >                f.quietlyJoin();
400 >                assertTrue(Thread.interrupted());
401 >                assertEquals(21, f.result);
402 >                checkCompletedNormally(f);
403 >
404 >                f = fibActions[4];
405 >                myself.interrupt();
406 >                assertTrue(myself.isInterrupted());
407 >                f.quietlyJoin();
408 >                assertTrue(Thread.interrupted());
409 >                checkCancelled(f);
410 >
411 >                f = fibActions[5];
412 >                myself.interrupt();
413 >                assertTrue(myself.isInterrupted());
414 >                f.quietlyJoin();
415 >                assertTrue(Thread.interrupted());
416 >                assertTrue(f.getException() instanceof FJException);
417 >                checkCompletedAbnormally(f, f.getException());
418              }};
419 +
420 +        Thread t;
421 +
422 +        t = newStartedThread(r);
423          testInvokeOnPool(mainPool(), a);
424 +        awaitTermination(t, LONG_DELAY_MS);
425 +
426 +        a.reinitialize();
427 +        t = newStartedThread(r);
428 +        testInvokeOnPool(singletonPool(), a);
429 +        awaitTermination(t, LONG_DELAY_MS);
430      }
431  
432      /**
# Line 161 | Line 439 | public class RecursiveActionTest extends
439                  assertSame(f, f.fork());
440                  assertNull(f.get());
441                  assertEquals(21, f.result);
442 <                assertTrue(f.isDone());
442 >                checkCompletedNormally(f);
443              }};
444          testInvokeOnPool(mainPool(), a);
445      }
# Line 174 | Line 452 | public class RecursiveActionTest extends
452              public void realCompute() throws Exception {
453                  FibAction f = new FibAction(8);
454                  assertSame(f, f.fork());
455 <                assertNull(f.get(5L, TimeUnit.SECONDS));
455 >                assertNull(f.get(5L, SECONDS));
456                  assertEquals(21, f.result);
457 <                assertTrue(f.isDone());
457 >                checkCompletedNormally(f);
458              }};
459          testInvokeOnPool(mainPool(), a);
460      }
# Line 207 | Line 485 | public class RecursiveActionTest extends
485                  assertSame(f, f.fork());
486                  f.quietlyJoin();
487                  assertEquals(21, f.result);
488 <                assertTrue(f.isDone());
488 >                checkCompletedNormally(f);
489              }};
490          testInvokeOnPool(mainPool(), a);
491      }
# Line 224 | Line 502 | public class RecursiveActionTest extends
502                  assertSame(f, f.fork());
503                  f.helpQuiesce();
504                  assertEquals(21, f.result);
227                assertTrue(f.isDone());
505                  assertEquals(0, getQueuedTaskCount());
506 +                checkCompletedNormally(f);
507              }};
508          testInvokeOnPool(mainPool(), a);
509      }
# Line 241 | Line 519 | public class RecursiveActionTest extends
519                  try {
520                      f.invoke();
521                      shouldThrow();
522 <                } catch (FJException success) {}
522 >                } catch (FJException success) {
523 >                    checkCompletedAbnormally(f, success);
524 >                }
525              }};
526          testInvokeOnPool(mainPool(), a);
527      }
# Line 254 | Line 534 | public class RecursiveActionTest extends
534              public void realCompute() {
535                  FailingFibAction f = new FailingFibAction(8);
536                  f.quietlyInvoke();
537 <                assertTrue(f.isDone());
537 >                assertTrue(f.getException() instanceof FJException);
538 >                checkCompletedAbnormally(f, f.getException());
539              }};
540          testInvokeOnPool(mainPool(), a);
541      }
# Line 270 | Line 551 | public class RecursiveActionTest extends
551                  try {
552                      f.join();
553                      shouldThrow();
554 <                } catch (FJException success) {}
554 >                } catch (FJException success) {
555 >                    checkCompletedAbnormally(f, success);
556 >                }
557              }};
558          testInvokeOnPool(mainPool(), a);
559      }
# Line 286 | Line 569 | public class RecursiveActionTest extends
569                  try {
570                      f.get();
571                      shouldThrow();
572 <                } catch (ExecutionException success) {}
572 >                } catch (ExecutionException success) {
573 >                    Throwable cause = success.getCause();
574 >                    assertTrue(cause instanceof FJException);
575 >                    checkCompletedAbnormally(f, cause);
576 >                }
577              }};
578          testInvokeOnPool(mainPool(), a);
579      }
# Line 302 | Line 589 | public class RecursiveActionTest extends
589                  try {
590                      f.get(5L, TimeUnit.SECONDS);
591                      shouldThrow();
592 <                } catch (ExecutionException success) {}
592 >                } catch (ExecutionException success) {
593 >                    Throwable cause = success.getCause();
594 >                    assertTrue(cause instanceof FJException);
595 >                    checkCompletedAbnormally(f, cause);
596 >                }
597              }};
598          testInvokeOnPool(mainPool(), a);
599      }
# Line 316 | Line 607 | public class RecursiveActionTest extends
607                  FailingFibAction f = new FailingFibAction(8);
608                  assertSame(f, f.fork());
609                  f.quietlyJoin();
319                assertTrue(f.isDone());
320                assertTrue(f.isCompletedAbnormally());
610                  assertTrue(f.getException() instanceof FJException);
611 +                checkCompletedAbnormally(f, f.getException());
612              }};
613          testInvokeOnPool(mainPool(), a);
614      }
# Line 334 | Line 624 | public class RecursiveActionTest extends
624                  try {
625                      f.invoke();
626                      shouldThrow();
627 <                } catch (CancellationException success) {}
627 >                } catch (CancellationException success) {
628 >                    checkCancelled(f);
629 >                }
630              }};
631          testInvokeOnPool(mainPool(), a);
632      }
# Line 351 | Line 643 | public class RecursiveActionTest extends
643                  try {
644                      f.join();
645                      shouldThrow();
646 <                } catch (CancellationException success) {}
646 >                } catch (CancellationException success) {
647 >                    checkCancelled(f);
648 >                }
649              }};
650          testInvokeOnPool(mainPool(), a);
651      }
# Line 368 | Line 662 | public class RecursiveActionTest extends
662                  try {
663                      f.get();
664                      shouldThrow();
665 <                } catch (CancellationException success) {}
665 >                } catch (CancellationException success) {
666 >                    checkCancelled(f);
667 >                }
668              }};
669          testInvokeOnPool(mainPool(), a);
670      }
# Line 383 | Line 679 | public class RecursiveActionTest extends
679                  assertTrue(f.cancel(true));
680                  assertSame(f, f.fork());
681                  try {
682 <                    f.get(5L, TimeUnit.SECONDS);
682 >                    f.get(5L, SECONDS);
683                      shouldThrow();
684 <                } catch (CancellationException success) {}
684 >                } catch (CancellationException success) {
685 >                    checkCancelled(f);
686 >                }
687              }};
688          testInvokeOnPool(mainPool(), a);
689      }
# Line 400 | Line 698 | public class RecursiveActionTest extends
698                  assertTrue(f.cancel(true));
699                  assertSame(f, f.fork());
700                  f.quietlyJoin();
701 <                assertTrue(f.isDone());
404 <                assertTrue(f.isCompletedAbnormally());
405 <                assertTrue(f.isCancelled());
406 <                assertTrue(f.getException() instanceof CancellationException);
701 >                checkCancelled(f);
702              }};
703          testInvokeOnPool(mainPool(), a);
704      }
# Line 475 | Line 770 | public class RecursiveActionTest extends
770          RecursiveAction a = new CheckedRecursiveAction() {
771              public void realCompute() {
772                  ForkJoinWorkerThread w =
773 <                    (ForkJoinWorkerThread)(Thread.currentThread());
774 <                int idx = w.getPoolIndex();
775 <                assertTrue(idx >= 0);
776 <                assertTrue(idx < mainPool.getPoolSize());
773 >                    (ForkJoinWorkerThread) Thread.currentThread();
774 >                assertTrue(w.getPoolIndex() >= 0);
775 >                // pool size can shrink after assigning index, so cannot check
776 >                // assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
777              }};
778          testInvokeOnPool(mainPool, a);
779      }
# Line 491 | Line 786 | public class RecursiveActionTest extends
786          RecursiveAction a = new CheckedRecursiveAction() {
787              public void realCompute() {
788                  setRawResult(null);
789 +                assertNull(getRawResult());
790              }};
791          assertNull(a.invoke());
792      }
# Line 502 | Line 798 | public class RecursiveActionTest extends
798          RecursiveAction a = new CheckedRecursiveAction() {
799              public void realCompute() {
800                  FibAction f = new FibAction(8);
801 <                assertNull(f.invoke());
802 <                assertEquals(21, f.result);
803 <                assertTrue(f.isDone());
804 <                assertFalse(f.isCancelled());
805 <                assertFalse(f.isCompletedAbnormally());
806 <                f.reinitialize();
807 <                assertNull(f.invoke());
808 <                assertEquals(21, f.result);
801 >                checkNotDone(f);
802 >
803 >                for (int i = 0; i < 3; i++) {
804 >                    assertNull(f.invoke());
805 >                    assertEquals(21, f.result);
806 >                    checkCompletedNormally(f);
807 >                    f.reinitialize();
808 >                    checkNotDone(f);
809 >                }
810              }};
811          testInvokeOnPool(mainPool(), a);
812      }
# Line 525 | Line 822 | public class RecursiveActionTest extends
822                  try {
823                      f.invoke();
824                      shouldThrow();
825 <                } catch (FJException success) {}
825 >                } catch (FJException success) {
826 >                    checkCompletedAbnormally(f, success);
827 >                }
828              }};
829          testInvokeOnPool(mainPool(), a);
830      }
# Line 539 | Line 838 | public class RecursiveActionTest extends
838                  FibAction f = new FibAction(8);
839                  f.complete(null);
840                  assertNull(f.invoke());
542                assertTrue(f.isDone());
841                  assertEquals(0, f.result);
842 +                checkCompletedNormally(f);
843              }};
844          testInvokeOnPool(mainPool(), a);
845      }
# Line 554 | Line 853 | public class RecursiveActionTest extends
853                  FibAction f = new FibAction(8);
854                  FibAction g = new FibAction(9);
855                  invokeAll(f, g);
856 <                assertTrue(f.isDone());
856 >                checkCompletedNormally(f);
857                  assertEquals(21, f.result);
858 <                assertTrue(g.isDone());
858 >                checkCompletedNormally(g);
859                  assertEquals(34, g.result);
860              }};
861          testInvokeOnPool(mainPool(), a);
# Line 570 | Line 869 | public class RecursiveActionTest extends
869              public void realCompute() {
870                  FibAction f = new FibAction(8);
871                  invokeAll(f);
872 <                assertTrue(f.isDone());
872 >                checkCompletedNormally(f);
873                  assertEquals(21, f.result);
874              }};
875          testInvokeOnPool(mainPool(), a);
# Line 587 | Line 886 | public class RecursiveActionTest extends
886                  FibAction h = new FibAction(7);
887                  invokeAll(f, g, h);
888                  assertTrue(f.isDone());
590                assertEquals(21, f.result);
889                  assertTrue(g.isDone());
592                assertEquals(34, g.result);
890                  assertTrue(h.isDone());
891 +                checkCompletedNormally(f);
892 +                assertEquals(21, f.result);
893 +                checkCompletedNormally(g);
894 +                assertEquals(34, g.result);
895 +                checkCompletedNormally(g);
896                  assertEquals(13, h.result);
897              }};
898          testInvokeOnPool(mainPool(), a);
# Line 611 | Line 913 | public class RecursiveActionTest extends
913                  set.add(h);
914                  invokeAll(set);
915                  assertTrue(f.isDone());
614                assertEquals(21, f.result);
916                  assertTrue(g.isDone());
616                assertEquals(34, g.result);
917                  assertTrue(h.isDone());
918 +                checkCompletedNormally(f);
919 +                assertEquals(21, f.result);
920 +                checkCompletedNormally(g);
921 +                assertEquals(34, g.result);
922 +                checkCompletedNormally(g);
923                  assertEquals(13, h.result);
924              }};
925          testInvokeOnPool(mainPool(), a);
# Line 649 | Line 954 | public class RecursiveActionTest extends
954                  try {
955                      invokeAll(f, g);
956                      shouldThrow();
957 <                } catch (FJException success) {}
957 >                } catch (FJException success) {
958 >                    checkCompletedAbnormally(g, success);
959 >                }
960              }};
961          testInvokeOnPool(mainPool(), a);
962      }
# Line 664 | Line 971 | public class RecursiveActionTest extends
971                  try {
972                      invokeAll(g);
973                      shouldThrow();
974 <                } catch (FJException success) {}
974 >                } catch (FJException success) {
975 >                    checkCompletedAbnormally(g, success);
976 >                }
977              }};
978          testInvokeOnPool(mainPool(), a);
979      }
# Line 681 | Line 990 | public class RecursiveActionTest extends
990                  try {
991                      invokeAll(f, g, h);
992                      shouldThrow();
993 <                } catch (FJException success) {}
993 >                } catch (FJException success) {
994 >                    checkCompletedAbnormally(g, success);
995 >                }
996              }};
997          testInvokeOnPool(mainPool(), a);
998      }
# Line 702 | Line 1013 | public class RecursiveActionTest extends
1013                  try {
1014                      invokeAll(set);
1015                      shouldThrow();
1016 <                } catch (FJException success) {}
1016 >                } catch (FJException success) {
1017 >                    checkCompletedAbnormally(f, success);
1018 >                }
1019              }};
1020          testInvokeOnPool(mainPool(), a);
1021      }
# Line 720 | Line 1033 | public class RecursiveActionTest extends
1033                  assertSame(f, f.fork());
1034                  assertTrue(f.tryUnfork());
1035                  helpQuiesce();
1036 <                assertFalse(f.isDone());
1037 <                assertTrue(g.isDone());
1036 >                checkNotDone(f);
1037 >                checkCompletedNormally(g);
1038              }};
1039          testInvokeOnPool(singletonPool(), a);
1040      }
# Line 741 | Line 1054 | public class RecursiveActionTest extends
1054                  assertSame(f, f.fork());
1055                  assertTrue(getSurplusQueuedTaskCount() > 0);
1056                  helpQuiesce();
1057 +                assertEquals(0, getSurplusQueuedTaskCount());
1058 +                checkCompletedNormally(f);
1059 +                checkCompletedNormally(g);
1060 +                checkCompletedNormally(h);
1061              }};
1062          testInvokeOnPool(singletonPool(), a);
1063      }
# Line 757 | Line 1074 | public class RecursiveActionTest extends
1074                  assertSame(f, f.fork());
1075                  assertSame(f, peekNextLocalTask());
1076                  assertNull(f.join());
1077 <                assertTrue(f.isDone());
1077 >                checkCompletedNormally(f);
1078                  helpQuiesce();
1079 +                checkCompletedNormally(f);
1080 +                checkCompletedNormally(g);
1081              }};
1082          testInvokeOnPool(singletonPool(), a);
1083      }
# Line 776 | Line 1095 | public class RecursiveActionTest extends
1095                  assertSame(f, f.fork());
1096                  assertSame(f, pollNextLocalTask());
1097                  helpQuiesce();
1098 <                assertFalse(f.isDone());
1098 >                checkNotDone(f);
1099 >                checkCompletedNormally(g);
1100              }};
1101          testInvokeOnPool(singletonPool(), a);
1102      }
1103  
1104      /**
1105 <     * pollTask returns an unexecuted task
786 <     * without executing it
1105 >     * pollTask returns an unexecuted task without executing it
1106       */
1107      public void testPollTask() {
1108          RecursiveAction a = new CheckedRecursiveAction() {
# Line 794 | Line 1113 | public class RecursiveActionTest extends
1113                  assertSame(f, f.fork());
1114                  assertSame(f, pollTask());
1115                  helpQuiesce();
1116 <                assertFalse(f.isDone());
1117 <                assertTrue(g.isDone());
1116 >                checkNotDone(f);
1117 >                checkCompletedNormally(g);
1118              }};
1119          testInvokeOnPool(singletonPool(), a);
1120      }
# Line 813 | Line 1132 | public class RecursiveActionTest extends
1132                  assertSame(g, peekNextLocalTask());
1133                  assertNull(f.join());
1134                  helpQuiesce();
1135 <                assertTrue(f.isDone());
1135 >                checkCompletedNormally(f);
1136 >                checkCompletedNormally(g);
1137              }};
1138          testInvokeOnPool(asyncSingletonPool(), a);
1139      }
1140  
1141      /**
1142 <     * pollNextLocalTask returns least recent unexecuted task
1143 <     * without executing it, in async mode
1142 >     * pollNextLocalTask returns least recent unexecuted task without
1143 >     * executing it, in async mode
1144       */
1145      public void testPollNextLocalTaskAsync() {
1146          RecursiveAction a = new CheckedRecursiveAction() {
# Line 831 | Line 1151 | public class RecursiveActionTest extends
1151                  assertSame(f, f.fork());
1152                  assertSame(g, pollNextLocalTask());
1153                  helpQuiesce();
1154 <                assertTrue(f.isDone());
1155 <                assertFalse(g.isDone());
1154 >                checkCompletedNormally(f);
1155 >                checkNotDone(g);
1156              }};
1157          testInvokeOnPool(asyncSingletonPool(), a);
1158      }
1159  
1160      /**
1161 <     * pollTask returns an unexecuted task
1162 <     * without executing it, in async mode
1161 >     * pollTask returns an unexecuted task without executing it, in
1162 >     * async mode
1163       */
1164      public void testPollTaskAsync() {
1165          RecursiveAction a = new CheckedRecursiveAction() {
# Line 850 | Line 1170 | public class RecursiveActionTest extends
1170                  assertSame(f, f.fork());
1171                  assertSame(g, pollTask());
1172                  helpQuiesce();
1173 <                assertTrue(f.isDone());
1174 <                assertFalse(g.isDone());
1173 >                checkCompletedNormally(f);
1174 >                checkNotDone(g);
1175              }};
1176          testInvokeOnPool(asyncSingletonPool(), a);
1177      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines