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.15 by jsr166, Mon Sep 13 20:48:58 2010 UTC vs.
Revision 1.26 by jsr166, Tue Nov 23 07:38:40 2010 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.ForkJoinWorkerThread;
13   import java.util.concurrent.RecursiveAction;
14   import java.util.concurrent.TimeUnit;
15 + import java.util.concurrent.TimeoutException;
16 + import static java.util.concurrent.TimeUnit.SECONDS;
17   import java.util.HashSet;
18  
19   public class RecursiveActionTest extends JSR166TestCase {
# Line 39 | Line 42 | public class RecursiveActionTest extends
42  
43      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
44          try {
45 <            assertTrue(pool.invoke(a) == null);
45 >            checkNotDone(a);
46 >
47 >            assertNull(pool.invoke(a));
48 >
49 >            checkCompletedNormally(a);
50          } finally {
51              joinPool(pool);
52          }
53      }
54  
55 +    void checkNotDone(RecursiveAction a) {
56 +        assertFalse(a.isDone());
57 +        assertFalse(a.isCompletedNormally());
58 +        assertFalse(a.isCompletedAbnormally());
59 +        assertFalse(a.isCancelled());
60 +        assertNull(a.getException());
61 +        assertNull(a.getRawResult());
62 +
63 +        if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) {
64 +            Thread.currentThread().interrupt();
65 +            try {
66 +                a.get();
67 +                shouldThrow();
68 +            } catch (InterruptedException success) {
69 +            } catch (Throwable fail) { threadUnexpectedException(fail); }
70 +
71 +            Thread.currentThread().interrupt();
72 +            try {
73 +                a.get(5L, SECONDS);
74 +                shouldThrow();
75 +            } catch (InterruptedException success) {
76 +            } catch (Throwable fail) { threadUnexpectedException(fail); }
77 +        }
78 +
79 +        try {
80 +            a.get(0L, SECONDS);
81 +            shouldThrow();
82 +        } catch (TimeoutException success) {
83 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
84 +    }
85 +
86 +    void checkCompletedNormally(RecursiveAction a) {
87 +        assertTrue(a.isDone());
88 +        assertFalse(a.isCancelled());
89 +        assertTrue(a.isCompletedNormally());
90 +        assertFalse(a.isCompletedAbnormally());
91 +        assertNull(a.getException());
92 +        assertNull(a.getRawResult());
93 +        assertNull(a.join());
94 +        assertFalse(a.cancel(false));
95 +        assertFalse(a.cancel(true));
96 +        try {
97 +            assertNull(a.get());
98 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
99 +        try {
100 +            assertNull(a.get(5L, SECONDS));
101 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
102 +    }
103 +
104 +    void checkCancelled(RecursiveAction a) {
105 +        assertTrue(a.isDone());
106 +        assertTrue(a.isCancelled());
107 +        assertFalse(a.isCompletedNormally());
108 +        assertTrue(a.isCompletedAbnormally());
109 +        assertTrue(a.getException() instanceof CancellationException);
110 +        assertNull(a.getRawResult());
111 +
112 +        try {
113 +            a.join();
114 +            shouldThrow();
115 +        } catch (CancellationException success) {
116 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
117 +
118 +        try {
119 +            a.get();
120 +            shouldThrow();
121 +        } catch (CancellationException success) {
122 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
123 +
124 +        try {
125 +            a.get(5L, SECONDS);
126 +            shouldThrow();
127 +        } catch (CancellationException success) {
128 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
129 +    }
130 +
131 +    void checkCompletedAbnormally(RecursiveAction a, Throwable t) {
132 +        assertTrue(a.isDone());
133 +        assertFalse(a.isCancelled());
134 +        assertFalse(a.isCompletedNormally());
135 +        assertTrue(a.isCompletedAbnormally());
136 +        assertSame(t, a.getException());
137 +        assertNull(a.getRawResult());
138 +        assertFalse(a.cancel(false));
139 +        assertFalse(a.cancel(true));
140 +
141 +        try {
142 +            a.join();
143 +            shouldThrow();
144 +        } catch (Throwable expected) {
145 +            assertSame(t, expected);
146 +        }
147 +
148 +        try {
149 +            a.get();
150 +            shouldThrow();
151 +        } catch (ExecutionException success) {
152 +            assertSame(t, success.getCause());
153 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
154 +
155 +        try {
156 +            a.get(5L, SECONDS);
157 +            shouldThrow();
158 +        } catch (ExecutionException success) {
159 +            assertSame(t, success.getCause());
160 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
161 +    }
162 +
163      static final class FJException extends RuntimeException {
164          FJException() { super(); }
165      }
166  
167      // A simple recursive action for testing
168 <    static final class FibAction extends RecursiveAction {
168 >    final class FibAction extends CheckedRecursiveAction {
169          final int number;
170          int result;
171          FibAction(int n) { number = n; }
172 <        public void compute() {
172 >        public void realCompute() {
173              int n = number;
174              if (n <= 1)
175                  result = n;
# Line 91 | Line 206 | public class RecursiveActionTest extends
206       * completed tasks. getRawResult of a RecursiveAction returns null;
207       */
208      public void testInvoke() {
209 <        RecursiveAction a = new RecursiveAction() {
210 <            public void compute() {
209 >        RecursiveAction a = new CheckedRecursiveAction() {
210 >            public void realCompute() {
211                  FibAction f = new FibAction(8);
212 <                f.invoke();
213 <                threadAssertTrue(f.result == 21);
214 <                threadAssertTrue(f.isDone());
100 <                threadAssertFalse(f.isCancelled());
101 <                threadAssertFalse(f.isCompletedAbnormally());
102 <                threadAssertTrue(f.getRawResult() == null);
212 >                assertNull(f.invoke());
213 >                assertEquals(21, f.result);
214 >                checkCompletedNormally(f);
215              }};
216          testInvokeOnPool(mainPool(), a);
217      }
# Line 110 | Line 222 | public class RecursiveActionTest extends
222       * completed tasks
223       */
224      public void testQuietlyInvoke() {
225 <        RecursiveAction a = new RecursiveAction() {
226 <            public void compute() {
225 >        RecursiveAction a = new CheckedRecursiveAction() {
226 >            public void realCompute() {
227                  FibAction f = new FibAction(8);
228                  f.quietlyInvoke();
229 <                threadAssertTrue(f.result == 21);
230 <                threadAssertTrue(f.isDone());
119 <                threadAssertFalse(f.isCancelled());
120 <                threadAssertFalse(f.isCompletedAbnormally());
121 <                threadAssertTrue(f.getRawResult() == null);
229 >                assertEquals(21, f.result);
230 >                checkCompletedNormally(f);
231              }};
232          testInvokeOnPool(mainPool(), a);
233      }
# Line 127 | Line 236 | public class RecursiveActionTest extends
236       * join of a forked task returns when task completes
237       */
238      public void testForkJoin() {
239 <        RecursiveAction a = new RecursiveAction() {
240 <            public void compute() {
239 >        RecursiveAction a = new CheckedRecursiveAction() {
240 >            public void realCompute() {
241                  FibAction f = new FibAction(8);
242 <                f.fork();
243 <                f.join();
244 <                threadAssertTrue(f.result == 21);
245 <                threadAssertTrue(f.isDone());
137 <                threadAssertTrue(f.getRawResult() == null);
242 >                assertSame(f, f.fork());
243 >                assertNull(f.join());
244 >                assertEquals(21, f.result);
245 >                checkCompletedNormally(f);
246              }};
247          testInvokeOnPool(mainPool(), a);
248      }
249  
250      /**
251 <     * get of a forked task returns when task completes
251 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
252       */
253 <    public void testForkGet() {
254 <        RecursiveAction a = new RecursiveAction() {
255 <            public void compute() {
253 >    public void testJoinIgnoresInterrupts() {
254 >        RecursiveAction a = new CheckedRecursiveAction() {
255 >            public void realCompute() {
256 >                FibAction f = new FibAction(8);
257 >
258 >                // test join()
259 >                assertSame(f, f.fork());
260 >                Thread.currentThread().interrupt();
261 >                assertNull(f.join());
262 >                Thread.interrupted();
263 >                assertEquals(21, f.result);
264 >                checkCompletedNormally(f);
265 >
266 >                f.reinitialize();
267 >                f.cancel(true);
268 >                assertSame(f, f.fork());
269 >                Thread.currentThread().interrupt();
270                  try {
271 <                    FibAction f = new FibAction(8);
272 <                    f.fork();
273 <                    f.get();
274 <                    threadAssertTrue(f.result == 21);
275 <                    threadAssertTrue(f.isDone());
154 <                } catch (Exception ex) {
155 <                    unexpectedException(ex);
271 >                    f.join();
272 >                    shouldThrow();
273 >                } catch (CancellationException success) {
274 >                    Thread.interrupted();
275 >                    checkCancelled(f);
276                  }
277 +
278 +                f.reinitialize();
279 +                f.completeExceptionally(new FJException());
280 +                assertSame(f, f.fork());
281 +                Thread.currentThread().interrupt();
282 +                try {
283 +                    f.join();
284 +                    shouldThrow();
285 +                } catch (FJException success) {
286 +                    Thread.interrupted();
287 +                    checkCompletedAbnormally(f, success);
288 +                }
289 +
290 +                // test quietlyJoin()
291 +                f.reinitialize();
292 +                assertSame(f, f.fork());
293 +                Thread.currentThread().interrupt();
294 +                f.quietlyJoin();
295 +                Thread.interrupted();
296 +                assertEquals(21, f.result);
297 +                checkCompletedNormally(f);
298 +
299 +                f.reinitialize();
300 +                f.cancel(true);
301 +                assertSame(f, f.fork());
302 +                Thread.currentThread().interrupt();
303 +                f.quietlyJoin();
304 +                Thread.interrupted();
305 +                checkCancelled(f);
306 +
307 +                f.reinitialize();
308 +                f.completeExceptionally(new FJException());
309 +                assertSame(f, f.fork());
310 +                Thread.currentThread().interrupt();
311 +                f.quietlyJoin();
312 +                Thread.interrupted();
313 +                checkCompletedAbnormally(f, f.getException());
314              }};
315          testInvokeOnPool(mainPool(), a);
316 +        a.reinitialize();
317 +        testInvokeOnPool(singletonPool(), a);
318      }
319  
320      /**
321 <     * timed get of a forked task returns when task completes
321 >     * join/quietlyJoin of a forked task when not in ForkJoinPool
322 >     * succeeds in the presence of interrupts
323       */
324 <    public void testForkTimedGet() {
325 <        RecursiveAction a = new RecursiveAction() {
326 <            public void compute() {
324 >    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
325 >        final SynchronousQueue<FibAction[]> sq =
326 >            new SynchronousQueue<FibAction[]>();
327 >        RecursiveAction a = new CheckedRecursiveAction() {
328 >            public void realCompute() throws InterruptedException {
329 >                FibAction[] fibActions = new FibAction[6];
330 >                for (int i = 0; i < fibActions.length; i++)
331 >                    fibActions[i] = new FibAction(8);
332 >
333 >                fibActions[1].cancel(false);
334 >                fibActions[2].completeExceptionally(new FJException());
335 >                fibActions[4].cancel(true);
336 >                fibActions[5].completeExceptionally(new FJException());
337 >
338 >                for (int i = 0; i < fibActions.length; i++)
339 >                    fibActions[i].fork();
340 >
341 >                sq.put(fibActions);
342 >
343 >                helpQuiesce();
344 >            }};
345 >
346 >        Runnable r = new CheckedRunnable() {
347 >            public void realRun() throws InterruptedException {
348 >                FibAction[] fibActions = sq.take();
349 >                FibAction f;
350 >
351 >                // test join() ------------
352 >
353 >                f = fibActions[0];
354 >                assertFalse(f.inForkJoinPool());
355 >                Thread.currentThread().interrupt();
356 >                assertNull(f.join());
357 >                assertTrue(Thread.interrupted());
358 >                assertEquals(21, f.result);
359 >                checkCompletedNormally(f);
360 >
361 >                f = fibActions[1];
362 >                Thread.currentThread().interrupt();
363                  try {
364 <                    FibAction f = new FibAction(8);
365 <                    f.fork();
366 <                    f.get(5L, TimeUnit.SECONDS);
367 <                    threadAssertTrue(f.result == 21);
368 <                    threadAssertTrue(f.isDone());
173 <                } catch (Exception ex) {
174 <                    unexpectedException(ex);
364 >                    f.join();
365 >                    shouldThrow();
366 >                } catch (CancellationException success) {
367 >                    assertTrue(Thread.interrupted());
368 >                    checkCancelled(f);
369                  }
370 +
371 +                f = fibActions[2];
372 +                Thread.currentThread().interrupt();
373 +                try {
374 +                    f.join();
375 +                    shouldThrow();
376 +                } catch (FJException success) {
377 +                    assertTrue(Thread.interrupted());
378 +                    checkCompletedAbnormally(f, success);
379 +                }
380 +
381 +                // test quietlyJoin() ---------
382 +
383 +                f = fibActions[3];
384 +                Thread.currentThread().interrupt();
385 +                f.quietlyJoin();
386 +                assertTrue(Thread.interrupted());
387 +                assertEquals(21, f.result);
388 +                checkCompletedNormally(f);
389 +
390 +                f = fibActions[4];
391 +                Thread.currentThread().interrupt();
392 +                f.quietlyJoin();
393 +                assertTrue(Thread.interrupted());
394 +                checkCancelled(f);
395 +
396 +                f = fibActions[5];
397 +                Thread.currentThread().interrupt();
398 +                f.quietlyJoin();
399 +                assertTrue(Thread.interrupted());
400 +                assertTrue(f.getException() instanceof FJException);
401 +                checkCompletedAbnormally(f, f.getException());
402 +            }};
403 +
404 +        Thread t;
405 +
406 +        t = newStartedThread(r);
407 +        testInvokeOnPool(mainPool(), a);
408 +        awaitTermination(t, LONG_DELAY_MS);
409 +
410 +        a.reinitialize();
411 +        t = newStartedThread(r);
412 +        testInvokeOnPool(singletonPool(), a);
413 +        awaitTermination(t, LONG_DELAY_MS);
414 +    }
415 +
416 +    /**
417 +     * get of a forked task returns when task completes
418 +     */
419 +    public void testForkGet() {
420 +        RecursiveAction a = new CheckedRecursiveAction() {
421 +            public void realCompute() throws Exception {
422 +                FibAction f = new FibAction(8);
423 +                assertSame(f, f.fork());
424 +                assertNull(f.get());
425 +                assertEquals(21, f.result);
426 +                checkCompletedNormally(f);
427 +            }};
428 +        testInvokeOnPool(mainPool(), a);
429 +    }
430 +
431 +    /**
432 +     * timed get of a forked task returns when task completes
433 +     */
434 +    public void testForkTimedGet() {
435 +        RecursiveAction a = new CheckedRecursiveAction() {
436 +            public void realCompute() throws Exception {
437 +                FibAction f = new FibAction(8);
438 +                assertSame(f, f.fork());
439 +                assertNull(f.get(5L, SECONDS));
440 +                assertEquals(21, f.result);
441 +                checkCompletedNormally(f);
442              }};
443          testInvokeOnPool(mainPool(), a);
444      }
# Line 181 | Line 447 | public class RecursiveActionTest extends
447       * timed get with null time unit throws NPE
448       */
449      public void testForkTimedGetNPE() {
450 <        RecursiveAction a = new RecursiveAction() {
451 <            public void compute() {
450 >        RecursiveAction a = new CheckedRecursiveAction() {
451 >            public void realCompute() throws Exception {
452 >                FibAction f = new FibAction(8);
453 >                assertSame(f, f.fork());
454                  try {
187                    FibAction f = new FibAction(8);
188                    f.fork();
455                      f.get(5L, null);
456                      shouldThrow();
457 <                } catch (NullPointerException success) {
192 <                } catch (Exception ex) {
193 <                    unexpectedException(ex);
194 <                }
457 >                } catch (NullPointerException success) {}
458              }};
459          testInvokeOnPool(mainPool(), a);
460      }
# Line 200 | Line 463 | public class RecursiveActionTest extends
463       * quietlyJoin of a forked task returns when task completes
464       */
465      public void testForkQuietlyJoin() {
466 <        RecursiveAction a = new RecursiveAction() {
467 <            public void compute() {
466 >        RecursiveAction a = new CheckedRecursiveAction() {
467 >            public void realCompute() {
468                  FibAction f = new FibAction(8);
469 <                f.fork();
469 >                assertSame(f, f.fork());
470                  f.quietlyJoin();
471 <                threadAssertTrue(f.result == 21);
472 <                threadAssertTrue(f.isDone());
471 >                assertEquals(21, f.result);
472 >                checkCompletedNormally(f);
473              }};
474          testInvokeOnPool(mainPool(), a);
475      }
# Line 217 | Line 480 | public class RecursiveActionTest extends
480       * getQueuedTaskCount returns 0 when quiescent
481       */
482      public void testForkHelpQuiesce() {
483 <        RecursiveAction a = new RecursiveAction() {
484 <            public void compute() {
483 >        RecursiveAction a = new CheckedRecursiveAction() {
484 >            public void realCompute() {
485                  FibAction f = new FibAction(8);
486 <                f.fork();
486 >                assertSame(f, f.fork());
487                  f.helpQuiesce();
488 <                threadAssertTrue(f.result == 21);
489 <                threadAssertTrue(f.isDone());
490 <                threadAssertTrue(getQueuedTaskCount() == 0);
488 >                assertEquals(21, f.result);
489 >                assertEquals(0, getQueuedTaskCount());
490 >                checkCompletedNormally(f);
491              }};
492          testInvokeOnPool(mainPool(), a);
493      }
# Line 234 | Line 497 | public class RecursiveActionTest extends
497       * invoke task throws exception when task completes abnormally
498       */
499      public void testAbnormalInvoke() {
500 <        RecursiveAction a = new RecursiveAction() {
501 <            public void compute() {
500 >        RecursiveAction a = new CheckedRecursiveAction() {
501 >            public void realCompute() {
502 >                FailingFibAction f = new FailingFibAction(8);
503                  try {
240                    FailingFibAction f = new FailingFibAction(8);
504                      f.invoke();
505                      shouldThrow();
506                  } catch (FJException success) {
507 +                    checkCompletedAbnormally(f, success);
508                  }
509              }};
510          testInvokeOnPool(mainPool(), a);
# Line 250 | Line 514 | public class RecursiveActionTest extends
514       * quietlyInvoke task returns when task completes abnormally
515       */
516      public void testAbnormalQuietlyInvoke() {
517 <        RecursiveAction a = new RecursiveAction() {
518 <            public void compute() {
517 >        RecursiveAction a = new CheckedRecursiveAction() {
518 >            public void realCompute() {
519                  FailingFibAction f = new FailingFibAction(8);
520                  f.quietlyInvoke();
521 <                threadAssertTrue(f.isDone());
521 >                assertTrue(f.getException() instanceof FJException);
522 >                checkCompletedAbnormally(f, f.getException());
523              }};
524          testInvokeOnPool(mainPool(), a);
525      }
# Line 263 | Line 528 | public class RecursiveActionTest extends
528       * join of a forked task throws exception when task completes abnormally
529       */
530      public void testAbnormalForkJoin() {
531 <        RecursiveAction a = new RecursiveAction() {
532 <            public void compute() {
531 >        RecursiveAction a = new CheckedRecursiveAction() {
532 >            public void realCompute() {
533 >                FailingFibAction f = new FailingFibAction(8);
534 >                assertSame(f, f.fork());
535                  try {
269                    FailingFibAction f = new FailingFibAction(8);
270                    f.fork();
536                      f.join();
537                      shouldThrow();
538                  } catch (FJException success) {
539 +                    checkCompletedAbnormally(f, success);
540                  }
541              }};
542          testInvokeOnPool(mainPool(), a);
# Line 280 | Line 546 | public class RecursiveActionTest extends
546       * get of a forked task throws exception when task completes abnormally
547       */
548      public void testAbnormalForkGet() {
549 <        RecursiveAction a = new RecursiveAction() {
550 <            public void compute() {
549 >        RecursiveAction a = new CheckedRecursiveAction() {
550 >            public void realCompute() throws Exception {
551 >                FailingFibAction f = new FailingFibAction(8);
552 >                assertSame(f, f.fork());
553                  try {
286                    FailingFibAction f = new FailingFibAction(8);
287                    f.fork();
554                      f.get();
555                      shouldThrow();
556                  } catch (ExecutionException success) {
557 <                } catch (Exception ex) {
558 <                    unexpectedException(ex);
557 >                    Throwable cause = success.getCause();
558 >                    assertTrue(cause instanceof FJException);
559 >                    checkCompletedAbnormally(f, cause);
560                  }
561              }};
562          testInvokeOnPool(mainPool(), a);
# Line 299 | Line 566 | public class RecursiveActionTest extends
566       * timed get of a forked task throws exception when task completes abnormally
567       */
568      public void testAbnormalForkTimedGet() {
569 <        RecursiveAction a = new RecursiveAction() {
570 <            public void compute() {
569 >        RecursiveAction a = new CheckedRecursiveAction() {
570 >            public void realCompute() throws Exception {
571 >                FailingFibAction f = new FailingFibAction(8);
572 >                assertSame(f, f.fork());
573                  try {
305                    FailingFibAction f = new FailingFibAction(8);
306                    f.fork();
574                      f.get(5L, TimeUnit.SECONDS);
575                      shouldThrow();
576                  } catch (ExecutionException success) {
577 <                } catch (Exception ex) {
578 <                    unexpectedException(ex);
577 >                    Throwable cause = success.getCause();
578 >                    assertTrue(cause instanceof FJException);
579 >                    checkCompletedAbnormally(f, cause);
580                  }
581              }};
582          testInvokeOnPool(mainPool(), a);
# Line 318 | Line 586 | public class RecursiveActionTest extends
586       * quietlyJoin of a forked task returns when task completes abnormally
587       */
588      public void testAbnormalForkQuietlyJoin() {
589 <        RecursiveAction a = new RecursiveAction() {
590 <            public void compute() {
589 >        RecursiveAction a = new CheckedRecursiveAction() {
590 >            public void realCompute() {
591                  FailingFibAction f = new FailingFibAction(8);
592 <                f.fork();
592 >                assertSame(f, f.fork());
593                  f.quietlyJoin();
594 <                threadAssertTrue(f.isDone());
595 <                threadAssertTrue(f.isCompletedAbnormally());
328 <                threadAssertTrue(f.getException() instanceof FJException);
594 >                assertTrue(f.getException() instanceof FJException);
595 >                checkCompletedAbnormally(f, f.getException());
596              }};
597          testInvokeOnPool(mainPool(), a);
598      }
# Line 334 | Line 601 | public class RecursiveActionTest extends
601       * invoke task throws exception when task cancelled
602       */
603      public void testCancelledInvoke() {
604 <        RecursiveAction a = new RecursiveAction() {
605 <            public void compute() {
604 >        RecursiveAction a = new CheckedRecursiveAction() {
605 >            public void realCompute() {
606 >                FibAction f = new FibAction(8);
607 >                assertTrue(f.cancel(true));
608                  try {
340                    FibAction f = new FibAction(8);
341                    f.cancel(true);
609                      f.invoke();
610                      shouldThrow();
611                  } catch (CancellationException success) {
612 +                    checkCancelled(f);
613                  }
614              }};
615          testInvokeOnPool(mainPool(), a);
# Line 351 | Line 619 | public class RecursiveActionTest extends
619       * join of a forked task throws exception when task cancelled
620       */
621      public void testCancelledForkJoin() {
622 <        RecursiveAction a = new RecursiveAction() {
623 <            public void compute() {
622 >        RecursiveAction a = new CheckedRecursiveAction() {
623 >            public void realCompute() {
624 >                FibAction f = new FibAction(8);
625 >                assertTrue(f.cancel(true));
626 >                assertSame(f, f.fork());
627                  try {
357                    FibAction f = new FibAction(8);
358                    f.cancel(true);
359                    f.fork();
628                      f.join();
629                      shouldThrow();
630                  } catch (CancellationException success) {
631 +                    checkCancelled(f);
632                  }
633              }};
634          testInvokeOnPool(mainPool(), a);
# Line 369 | Line 638 | public class RecursiveActionTest extends
638       * get of a forked task throws exception when task cancelled
639       */
640      public void testCancelledForkGet() {
641 <        RecursiveAction a = new RecursiveAction() {
642 <            public void compute() {
641 >        RecursiveAction a = new CheckedRecursiveAction() {
642 >            public void realCompute() throws Exception {
643 >                FibAction f = new FibAction(8);
644 >                assertTrue(f.cancel(true));
645 >                assertSame(f, f.fork());
646                  try {
375                    FibAction f = new FibAction(8);
376                    f.cancel(true);
377                    f.fork();
647                      f.get();
648                      shouldThrow();
649                  } catch (CancellationException success) {
650 <                } catch (Exception ex) {
382 <                    unexpectedException(ex);
650 >                    checkCancelled(f);
651                  }
652              }};
653          testInvokeOnPool(mainPool(), a);
# Line 389 | Line 657 | public class RecursiveActionTest extends
657       * timed get of a forked task throws exception when task cancelled
658       */
659      public void testCancelledForkTimedGet() {
660 <        RecursiveAction a = new RecursiveAction() {
661 <            public void compute() {
660 >        RecursiveAction a = new CheckedRecursiveAction() {
661 >            public void realCompute() throws Exception {
662 >                FibAction f = new FibAction(8);
663 >                assertTrue(f.cancel(true));
664 >                assertSame(f, f.fork());
665                  try {
666 <                    FibAction f = new FibAction(8);
396 <                    f.cancel(true);
397 <                    f.fork();
398 <                    f.get(5L, TimeUnit.SECONDS);
666 >                    f.get(5L, SECONDS);
667                      shouldThrow();
668                  } catch (CancellationException success) {
669 <                } catch (Exception ex) {
402 <                    unexpectedException(ex);
669 >                    checkCancelled(f);
670                  }
671              }};
672          testInvokeOnPool(mainPool(), a);
# Line 409 | Line 676 | public class RecursiveActionTest extends
676       * quietlyJoin of a forked task returns when task cancelled
677       */
678      public void testCancelledForkQuietlyJoin() {
679 <        RecursiveAction a = new RecursiveAction() {
680 <            public void compute() {
679 >        RecursiveAction a = new CheckedRecursiveAction() {
680 >            public void realCompute() {
681                  FibAction f = new FibAction(8);
682 <                f.cancel(true);
683 <                f.fork();
682 >                assertTrue(f.cancel(true));
683 >                assertSame(f, f.fork());
684                  f.quietlyJoin();
685 <                threadAssertTrue(f.isDone());
419 <                threadAssertTrue(f.isCompletedAbnormally());
420 <                threadAssertTrue(f.getException() instanceof CancellationException);
685 >                checkCancelled(f);
686              }};
687          testInvokeOnPool(mainPool(), a);
688      }
# Line 427 | Line 692 | public class RecursiveActionTest extends
692       */
693      public void testGetPool() {
694          final ForkJoinPool mainPool = mainPool();
695 <        RecursiveAction a = new RecursiveAction() {
696 <            public void compute() {
697 <                threadAssertTrue(getPool() == mainPool);
695 >        RecursiveAction a = new CheckedRecursiveAction() {
696 >            public void realCompute() {
697 >                assertSame(mainPool, getPool());
698              }};
699          testInvokeOnPool(mainPool, a);
700      }
# Line 438 | Line 703 | public class RecursiveActionTest extends
703       * getPool of non-FJ task returns null
704       */
705      public void testGetPool2() {
706 <        RecursiveAction a = new RecursiveAction() {
707 <            public void compute() {
708 <                threadAssertTrue(getPool() == null);
706 >        RecursiveAction a = new CheckedRecursiveAction() {
707 >            public void realCompute() {
708 >                assertNull(getPool());
709              }};
710 <        a.invoke();
710 >        assertNull(a.invoke());
711      }
712  
713      /**
714       * inForkJoinPool of executing task returns true
715       */
716      public void testInForkJoinPool() {
717 <        RecursiveAction a = new RecursiveAction() {
718 <            public void compute() {
719 <                threadAssertTrue(inForkJoinPool());
717 >        RecursiveAction a = new CheckedRecursiveAction() {
718 >            public void realCompute() {
719 >                assertTrue(inForkJoinPool());
720              }};
721          testInvokeOnPool(mainPool(), a);
722      }
# Line 460 | Line 725 | public class RecursiveActionTest extends
725       * inForkJoinPool of non-FJ task returns false
726       */
727      public void testInForkJoinPool2() {
728 <        RecursiveAction a = new RecursiveAction() {
729 <            public void compute() {
730 <                threadAssertTrue(!inForkJoinPool());
728 >        RecursiveAction a = new CheckedRecursiveAction() {
729 >            public void realCompute() {
730 >                assertFalse(inForkJoinPool());
731              }};
732 <        a.invoke();
732 >        assertNull(a.invoke());
733      }
734  
735      /**
# Line 472 | Line 737 | public class RecursiveActionTest extends
737       */
738      public void testWorkerGetPool() {
739          final ForkJoinPool mainPool = mainPool();
740 <        RecursiveAction a = new RecursiveAction() {
741 <            public void compute() {
740 >        RecursiveAction a = new CheckedRecursiveAction() {
741 >            public void realCompute() {
742                  ForkJoinWorkerThread w =
743                      (ForkJoinWorkerThread) Thread.currentThread();
744 <                threadAssertTrue(w.getPool() == mainPool);
744 >                assertSame(mainPool, w.getPool());
745              }};
746          testInvokeOnPool(mainPool, a);
747      }
# Line 486 | Line 751 | public class RecursiveActionTest extends
751       */
752      public void testWorkerGetPoolIndex() {
753          final ForkJoinPool mainPool = mainPool();
754 <        RecursiveAction a = new RecursiveAction() {
755 <            public void compute() {
754 >        RecursiveAction a = new CheckedRecursiveAction() {
755 >            public void realCompute() {
756                  ForkJoinWorkerThread w =
757                      (ForkJoinWorkerThread)(Thread.currentThread());
758 <                int idx = w.getPoolIndex();
759 <                threadAssertTrue(idx >= 0);
495 <                threadAssertTrue(idx < mainPool.getPoolSize());
758 >                assertTrue(w.getPoolIndex() >= 0);
759 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
760              }};
761          testInvokeOnPool(mainPool, a);
762      }
# Line 502 | Line 766 | public class RecursiveActionTest extends
766       * setRawResult(null) succeeds
767       */
768      public void testSetRawResult() {
769 <        RecursiveAction a = new RecursiveAction() {
770 <            public void compute() {
769 >        RecursiveAction a = new CheckedRecursiveAction() {
770 >            public void realCompute() {
771                  setRawResult(null);
772 +                assertNull(getRawResult());
773              }};
774 <        a.invoke();
774 >        assertNull(a.invoke());
775      }
776  
777      /**
778       * A reinitialized task may be re-invoked
779       */
780      public void testReinitialize() {
781 <        RecursiveAction a = new RecursiveAction() {
782 <            public void compute() {
781 >        RecursiveAction a = new CheckedRecursiveAction() {
782 >            public void realCompute() {
783                  FibAction f = new FibAction(8);
784 <                f.invoke();
785 <                threadAssertTrue(f.result == 21);
786 <                threadAssertTrue(f.isDone());
787 <                threadAssertFalse(f.isCancelled());
788 <                threadAssertFalse(f.isCompletedAbnormally());
789 <                f.reinitialize();
790 <                f.invoke();
791 <                threadAssertTrue(f.result == 21);
784 >                checkNotDone(f);
785 >
786 >                for (int i = 0; i < 3; i++) {
787 >                    assertNull(f.invoke());
788 >                    assertEquals(21, f.result);
789 >                    checkCompletedNormally(f);
790 >                    f.reinitialize();
791 >                    checkNotDone(f);
792 >                }
793              }};
794          testInvokeOnPool(mainPool(), a);
795      }
# Line 532 | Line 798 | public class RecursiveActionTest extends
798       * invoke task throws exception after invoking completeExceptionally
799       */
800      public void testCompleteExceptionally() {
801 <        RecursiveAction a = new RecursiveAction() {
802 <            public void compute() {
801 >        RecursiveAction a = new CheckedRecursiveAction() {
802 >            public void realCompute() {
803 >                FibAction f = new FibAction(8);
804 >                f.completeExceptionally(new FJException());
805                  try {
538                    FibAction f = new FibAction(8);
539                    f.completeExceptionally(new FJException());
806                      f.invoke();
807                      shouldThrow();
808                  } catch (FJException success) {
809 +                    checkCompletedAbnormally(f, success);
810                  }
811              }};
812          testInvokeOnPool(mainPool(), a);
# Line 549 | Line 816 | public class RecursiveActionTest extends
816       * invoke task suppresses execution invoking complete
817       */
818      public void testComplete() {
819 <        RecursiveAction a = new RecursiveAction() {
820 <            public void compute() {
819 >        RecursiveAction a = new CheckedRecursiveAction() {
820 >            public void realCompute() {
821                  FibAction f = new FibAction(8);
822                  f.complete(null);
823 <                f.invoke();
824 <                threadAssertTrue(f.isDone());
825 <                threadAssertTrue(f.result == 0);
823 >                assertNull(f.invoke());
824 >                assertEquals(0, f.result);
825 >                checkCompletedNormally(f);
826              }};
827          testInvokeOnPool(mainPool(), a);
828      }
# Line 564 | Line 831 | public class RecursiveActionTest extends
831       * invokeAll(t1, t2) invokes all task arguments
832       */
833      public void testInvokeAll2() {
834 <        RecursiveAction a = new RecursiveAction() {
835 <            public void compute() {
834 >        RecursiveAction a = new CheckedRecursiveAction() {
835 >            public void realCompute() {
836                  FibAction f = new FibAction(8);
837                  FibAction g = new FibAction(9);
838                  invokeAll(f, g);
839 <                threadAssertTrue(f.isDone());
840 <                threadAssertTrue(f.result == 21);
841 <                threadAssertTrue(g.isDone());
842 <                threadAssertTrue(g.result == 34);
839 >                checkCompletedNormally(f);
840 >                assertEquals(21, f.result);
841 >                checkCompletedNormally(g);
842 >                assertEquals(34, g.result);
843              }};
844          testInvokeOnPool(mainPool(), a);
845      }
# Line 581 | Line 848 | public class RecursiveActionTest extends
848       * invokeAll(tasks) with 1 argument invokes task
849       */
850      public void testInvokeAll1() {
851 <        RecursiveAction a = new RecursiveAction() {
852 <            public void compute() {
851 >        RecursiveAction a = new CheckedRecursiveAction() {
852 >            public void realCompute() {
853                  FibAction f = new FibAction(8);
854                  invokeAll(f);
855 <                threadAssertTrue(f.isDone());
856 <                threadAssertTrue(f.result == 21);
855 >                checkCompletedNormally(f);
856 >                assertEquals(21, f.result);
857              }};
858          testInvokeOnPool(mainPool(), a);
859      }
# Line 595 | Line 862 | public class RecursiveActionTest extends
862       * invokeAll(tasks) with > 2 argument invokes tasks
863       */
864      public void testInvokeAll3() {
865 <        RecursiveAction a = new RecursiveAction() {
866 <            public void compute() {
865 >        RecursiveAction a = new CheckedRecursiveAction() {
866 >            public void realCompute() {
867                  FibAction f = new FibAction(8);
868                  FibAction g = new FibAction(9);
869                  FibAction h = new FibAction(7);
870                  invokeAll(f, g, h);
871 <                threadAssertTrue(f.isDone());
872 <                threadAssertTrue(f.result == 21);
873 <                threadAssertTrue(g.isDone());
874 <                threadAssertTrue(g.result == 34);
875 <                threadAssertTrue(h.isDone());
876 <                threadAssertTrue(h.result == 13);
871 >                assertTrue(f.isDone());
872 >                assertTrue(g.isDone());
873 >                assertTrue(h.isDone());
874 >                checkCompletedNormally(f);
875 >                assertEquals(21, f.result);
876 >                checkCompletedNormally(g);
877 >                assertEquals(34, g.result);
878 >                checkCompletedNormally(g);
879 >                assertEquals(13, h.result);
880              }};
881          testInvokeOnPool(mainPool(), a);
882      }
# Line 615 | Line 885 | public class RecursiveActionTest extends
885       * invokeAll(collection) invokes all tasks in the collection
886       */
887      public void testInvokeAllCollection() {
888 <        RecursiveAction a = new RecursiveAction() {
889 <            public void compute() {
888 >        RecursiveAction a = new CheckedRecursiveAction() {
889 >            public void realCompute() {
890                  FibAction f = new FibAction(8);
891                  FibAction g = new FibAction(9);
892                  FibAction h = new FibAction(7);
# Line 625 | Line 895 | public class RecursiveActionTest extends
895                  set.add(g);
896                  set.add(h);
897                  invokeAll(set);
898 <                threadAssertTrue(f.isDone());
899 <                threadAssertTrue(f.result == 21);
900 <                threadAssertTrue(g.isDone());
901 <                threadAssertTrue(g.result == 34);
902 <                threadAssertTrue(h.isDone());
903 <                threadAssertTrue(h.result == 13);
898 >                assertTrue(f.isDone());
899 >                assertTrue(g.isDone());
900 >                assertTrue(h.isDone());
901 >                checkCompletedNormally(f);
902 >                assertEquals(21, f.result);
903 >                checkCompletedNormally(g);
904 >                assertEquals(34, g.result);
905 >                checkCompletedNormally(g);
906 >                assertEquals(13, h.result);
907              }};
908          testInvokeOnPool(mainPool(), a);
909      }
# Line 640 | Line 913 | public class RecursiveActionTest extends
913       * invokeAll(tasks) with any null task throws NPE
914       */
915      public void testInvokeAllNPE() {
916 <        RecursiveAction a = new RecursiveAction() {
917 <            public void compute() {
916 >        RecursiveAction a = new CheckedRecursiveAction() {
917 >            public void realCompute() {
918 >                FibAction f = new FibAction(8);
919 >                FibAction g = new FibAction(9);
920 >                FibAction h = null;
921                  try {
646                    FibAction f = new FibAction(8);
647                    FibAction g = new FibAction(9);
648                    FibAction h = null;
922                      invokeAll(f, g, h);
923                      shouldThrow();
924 <                } catch (NullPointerException success) {
652 <                }
924 >                } catch (NullPointerException success) {}
925              }};
926          testInvokeOnPool(mainPool(), a);
927      }
# Line 658 | Line 930 | public class RecursiveActionTest extends
930       * invokeAll(t1, t2) throw exception if any task does
931       */
932      public void testAbnormalInvokeAll2() {
933 <        RecursiveAction a = new RecursiveAction() {
934 <            public void compute() {
933 >        RecursiveAction a = new CheckedRecursiveAction() {
934 >            public void realCompute() {
935 >                FibAction f = new FibAction(8);
936 >                FailingFibAction g = new FailingFibAction(9);
937                  try {
664                    FibAction f = new FibAction(8);
665                    FailingFibAction g = new FailingFibAction(9);
938                      invokeAll(f, g);
939                      shouldThrow();
940                  } catch (FJException success) {
941 +                    checkCompletedAbnormally(g, success);
942                  }
943              }};
944          testInvokeOnPool(mainPool(), a);
# Line 675 | Line 948 | public class RecursiveActionTest extends
948       * invokeAll(tasks) with 1 argument throws exception if task does
949       */
950      public void testAbnormalInvokeAll1() {
951 <        RecursiveAction a = new RecursiveAction() {
952 <            public void compute() {
951 >        RecursiveAction a = new CheckedRecursiveAction() {
952 >            public void realCompute() {
953 >                FailingFibAction g = new FailingFibAction(9);
954                  try {
681                    FailingFibAction g = new FailingFibAction(9);
955                      invokeAll(g);
956                      shouldThrow();
957                  } catch (FJException success) {
958 +                    checkCompletedAbnormally(g, success);
959                  }
960              }};
961          testInvokeOnPool(mainPool(), a);
# Line 691 | Line 965 | public class RecursiveActionTest extends
965       * invokeAll(tasks) with > 2 argument throws exception if any task does
966       */
967      public void testAbnormalInvokeAll3() {
968 <        RecursiveAction a = new RecursiveAction() {
969 <            public void compute() {
968 >        RecursiveAction a = new CheckedRecursiveAction() {
969 >            public void realCompute() {
970 >                FibAction f = new FibAction(8);
971 >                FailingFibAction g = new FailingFibAction(9);
972 >                FibAction h = new FibAction(7);
973                  try {
697                    FibAction f = new FibAction(8);
698                    FailingFibAction g = new FailingFibAction(9);
699                    FibAction h = new FibAction(7);
974                      invokeAll(f, g, h);
975                      shouldThrow();
976                  } catch (FJException success) {
977 +                    checkCompletedAbnormally(g, success);
978                  }
979              }};
980          testInvokeOnPool(mainPool(), a);
# Line 709 | Line 984 | public class RecursiveActionTest extends
984       * invokeAll(collection) throws exception if any task does
985       */
986      public void testAbnormalInvokeAllCollection() {
987 <        RecursiveAction a = new RecursiveAction() {
988 <            public void compute() {
987 >        RecursiveAction a = new CheckedRecursiveAction() {
988 >            public void realCompute() {
989 >                FailingFibAction f = new FailingFibAction(8);
990 >                FibAction g = new FibAction(9);
991 >                FibAction h = new FibAction(7);
992 >                HashSet set = new HashSet();
993 >                set.add(f);
994 >                set.add(g);
995 >                set.add(h);
996                  try {
715                    FailingFibAction f = new FailingFibAction(8);
716                    FibAction g = new FibAction(9);
717                    FibAction h = new FibAction(7);
718                    HashSet set = new HashSet();
719                    set.add(f);
720                    set.add(g);
721                    set.add(h);
997                      invokeAll(set);
998                      shouldThrow();
999                  } catch (FJException success) {
1000 +                    checkCompletedAbnormally(f, success);
1001                  }
1002              }};
1003          testInvokeOnPool(mainPool(), a);
# Line 732 | Line 1008 | public class RecursiveActionTest extends
1008       * and suppresses execution
1009       */
1010      public void testTryUnfork() {
1011 <        RecursiveAction a = new RecursiveAction() {
1012 <            public void compute() {
1011 >        RecursiveAction a = new CheckedRecursiveAction() {
1012 >            public void realCompute() {
1013                  FibAction g = new FibAction(9);
1014 <                g.fork();
1014 >                assertSame(g, g.fork());
1015                  FibAction f = new FibAction(8);
1016 <                f.fork();
1017 <                threadAssertTrue(f.tryUnfork());
1016 >                assertSame(f, f.fork());
1017 >                assertTrue(f.tryUnfork());
1018                  helpQuiesce();
1019 <                threadAssertFalse(f.isDone());
1020 <                threadAssertTrue(g.isDone());
1019 >                checkNotDone(f);
1020 >                checkCompletedNormally(g);
1021              }};
1022          testInvokeOnPool(singletonPool(), a);
1023      }
# Line 751 | Line 1027 | public class RecursiveActionTest extends
1027       * there are more tasks than threads
1028       */
1029      public void testGetSurplusQueuedTaskCount() {
1030 <        RecursiveAction a = new RecursiveAction() {
1031 <            public void compute() {
1030 >        RecursiveAction a = new CheckedRecursiveAction() {
1031 >            public void realCompute() {
1032                  FibAction h = new FibAction(7);
1033 <                h.fork();
1033 >                assertSame(h, h.fork());
1034                  FibAction g = new FibAction(9);
1035 <                g.fork();
1035 >                assertSame(g, g.fork());
1036                  FibAction f = new FibAction(8);
1037 <                f.fork();
1038 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
1037 >                assertSame(f, f.fork());
1038 >                assertTrue(getSurplusQueuedTaskCount() > 0);
1039                  helpQuiesce();
1040 +                assertEquals(0, getSurplusQueuedTaskCount());
1041 +                checkCompletedNormally(f);
1042 +                checkCompletedNormally(g);
1043 +                checkCompletedNormally(h);
1044              }};
1045          testInvokeOnPool(singletonPool(), a);
1046      }
# Line 769 | Line 1049 | public class RecursiveActionTest extends
1049       * peekNextLocalTask returns most recent unexecuted task.
1050       */
1051      public void testPeekNextLocalTask() {
1052 <        RecursiveAction a = new RecursiveAction() {
1053 <            public void compute() {
1052 >        RecursiveAction a = new CheckedRecursiveAction() {
1053 >            public void realCompute() {
1054                  FibAction g = new FibAction(9);
1055 <                g.fork();
1055 >                assertSame(g, g.fork());
1056                  FibAction f = new FibAction(8);
1057 <                f.fork();
1058 <                threadAssertTrue(peekNextLocalTask() == f);
1059 <                f.join();
1060 <                threadAssertTrue(f.isDone());
1057 >                assertSame(f, f.fork());
1058 >                assertSame(f, peekNextLocalTask());
1059 >                assertNull(f.join());
1060 >                checkCompletedNormally(f);
1061                  helpQuiesce();
1062 +                checkCompletedNormally(f);
1063 +                checkCompletedNormally(g);
1064              }};
1065          testInvokeOnPool(singletonPool(), a);
1066      }
# Line 788 | Line 1070 | public class RecursiveActionTest extends
1070       * without executing it
1071       */
1072      public void testPollNextLocalTask() {
1073 <        RecursiveAction a = new RecursiveAction() {
1074 <            public void compute() {
1073 >        RecursiveAction a = new CheckedRecursiveAction() {
1074 >            public void realCompute() {
1075                  FibAction g = new FibAction(9);
1076 <                g.fork();
1076 >                assertSame(g, g.fork());
1077                  FibAction f = new FibAction(8);
1078 <                f.fork();
1079 <                threadAssertTrue(pollNextLocalTask() == f);
1078 >                assertSame(f, f.fork());
1079 >                assertSame(f, pollNextLocalTask());
1080                  helpQuiesce();
1081 <                threadAssertFalse(f.isDone());
1081 >                checkNotDone(f);
1082 >                checkCompletedNormally(g);
1083              }};
1084          testInvokeOnPool(singletonPool(), a);
1085      }
1086  
1087      /**
1088 <     * pollTask returns an unexecuted task
806 <     * without executing it
1088 >     * pollTask returns an unexecuted task without executing it
1089       */
1090      public void testPollTask() {
1091 <        RecursiveAction a = new RecursiveAction() {
1092 <            public void compute() {
1091 >        RecursiveAction a = new CheckedRecursiveAction() {
1092 >            public void realCompute() {
1093                  FibAction g = new FibAction(9);
1094 <                g.fork();
1094 >                assertSame(g, g.fork());
1095                  FibAction f = new FibAction(8);
1096 <                f.fork();
1097 <                threadAssertTrue(pollTask() == f);
1096 >                assertSame(f, f.fork());
1097 >                assertSame(f, pollTask());
1098                  helpQuiesce();
1099 <                threadAssertFalse(f.isDone());
1100 <                threadAssertTrue(g.isDone());
1099 >                checkNotDone(f);
1100 >                checkCompletedNormally(g);
1101              }};
1102          testInvokeOnPool(singletonPool(), a);
1103      }
# Line 824 | Line 1106 | public class RecursiveActionTest extends
1106       * peekNextLocalTask returns least recent unexecuted task in async mode
1107       */
1108      public void testPeekNextLocalTaskAsync() {
1109 <        RecursiveAction a = new RecursiveAction() {
1110 <            public void compute() {
1109 >        RecursiveAction a = new CheckedRecursiveAction() {
1110 >            public void realCompute() {
1111                  FibAction g = new FibAction(9);
1112 <                g.fork();
1112 >                assertSame(g, g.fork());
1113                  FibAction f = new FibAction(8);
1114 <                f.fork();
1115 <                threadAssertTrue(peekNextLocalTask() == g);
1116 <                f.join();
1114 >                assertSame(f, f.fork());
1115 >                assertSame(g, peekNextLocalTask());
1116 >                assertNull(f.join());
1117                  helpQuiesce();
1118 <                threadAssertTrue(f.isDone());
1118 >                checkCompletedNormally(f);
1119 >                checkCompletedNormally(g);
1120              }};
1121          testInvokeOnPool(asyncSingletonPool(), a);
1122      }
1123  
1124      /**
1125 <     * pollNextLocalTask returns least recent unexecuted task
1126 <     * without executing it, in async mode
1125 >     * pollNextLocalTask returns least recent unexecuted task without
1126 >     * executing it, in async mode
1127       */
1128      public void testPollNextLocalTaskAsync() {
1129 <        RecursiveAction a = new RecursiveAction() {
1130 <            public void compute() {
1129 >        RecursiveAction a = new CheckedRecursiveAction() {
1130 >            public void realCompute() {
1131                  FibAction g = new FibAction(9);
1132 <                g.fork();
1132 >                assertSame(g, g.fork());
1133                  FibAction f = new FibAction(8);
1134 <                f.fork();
1135 <                threadAssertTrue(pollNextLocalTask() == g);
1134 >                assertSame(f, f.fork());
1135 >                assertSame(g, pollNextLocalTask());
1136                  helpQuiesce();
1137 <                threadAssertTrue(f.isDone());
1138 <                threadAssertFalse(g.isDone());
1137 >                checkCompletedNormally(f);
1138 >                checkNotDone(g);
1139              }};
1140          testInvokeOnPool(asyncSingletonPool(), a);
1141      }
1142  
1143      /**
1144 <     * pollTask returns an unexecuted task
1145 <     * without executing it, in async mode
1144 >     * pollTask returns an unexecuted task without executing it, in
1145 >     * async mode
1146       */
1147      public void testPollTaskAsync() {
1148 <        RecursiveAction a = new RecursiveAction() {
1149 <            public void compute() {
1148 >        RecursiveAction a = new CheckedRecursiveAction() {
1149 >            public void realCompute() {
1150                  FibAction g = new FibAction(9);
1151 <                g.fork();
1151 >                assertSame(g, g.fork());
1152                  FibAction f = new FibAction(8);
1153 <                f.fork();
1154 <                threadAssertTrue(pollTask() == g);
1153 >                assertSame(f, f.fork());
1154 >                assertSame(g, pollTask());
1155                  helpQuiesce();
1156 <                threadAssertTrue(f.isDone());
1157 <                threadAssertFalse(g.isDone());
1156 >                checkCompletedNormally(f);
1157 >                checkNotDone(g);
1158              }};
1159          testInvokeOnPool(asyncSingletonPool(), a);
1160      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines