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.17 by dl, Wed Sep 15 12:46:57 2010 UTC vs.
Revision 1.28 by jsr166, Wed Dec 1 22:37:51 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.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 <            assertTrue(pool.invoke(a) == null);
46 >            checkNotDone(a);
47 >
48 >            assertNull(pool.invoke(a));
49 >
50 >            checkCompletedNormally(a);
51          } finally {
52              joinPool(pool);
53          }
54      }
55  
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, a.getException());
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(t, expected);
147 +        }
148 +
149 +        try {
150 +            a.get();
151 +            shouldThrow();
152 +        } catch (ExecutionException success) {
153 +            assertSame(t, success.getCause());
154 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
155 +
156 +        try {
157 +            a.get(5L, SECONDS);
158 +            shouldThrow();
159 +        } catch (ExecutionException success) {
160 +            assertSame(t, success.getCause());
161 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
162 +    }
163 +
164      static final class FJException extends RuntimeException {
165          FJException() { super(); }
166      }
167  
168      // A simple recursive action for testing
169 <    static final class FibAction extends RecursiveAction {
169 >    final class FibAction extends CheckedRecursiveAction {
170          final int number;
171          int result;
172          FibAction(int n) { number = n; }
173 <        public void compute() {
173 >        public void realCompute() {
174              int n = number;
175              if (n <= 1)
176                  result = n;
# Line 91 | Line 207 | public class RecursiveActionTest extends
207       * completed tasks. getRawResult of a RecursiveAction returns null;
208       */
209      public void testInvoke() {
210 <        RecursiveAction a = new RecursiveAction() {
211 <            public void compute() {
210 >        RecursiveAction a = new CheckedRecursiveAction() {
211 >            public void realCompute() {
212                  FibAction f = new FibAction(8);
213 <                threadAssertNull(f.invoke());
214 <                threadAssertTrue(f.result == 21);
215 <                threadAssertTrue(f.isDone());
100 <                threadAssertFalse(f.isCancelled());
101 <                threadAssertFalse(f.isCompletedAbnormally());
102 <                threadAssertTrue(f.getRawResult() == null);
213 >                assertNull(f.invoke());
214 >                assertEquals(21, f.result);
215 >                checkCompletedNormally(f);
216              }};
217          testInvokeOnPool(mainPool(), a);
218      }
# Line 110 | Line 223 | public class RecursiveActionTest extends
223       * completed tasks
224       */
225      public void testQuietlyInvoke() {
226 <        RecursiveAction a = new RecursiveAction() {
227 <            public void compute() {
226 >        RecursiveAction a = new CheckedRecursiveAction() {
227 >            public void realCompute() {
228                  FibAction f = new FibAction(8);
229                  f.quietlyInvoke();
230 <                threadAssertTrue(f.result == 21);
231 <                threadAssertTrue(f.isDone());
119 <                threadAssertFalse(f.isCancelled());
120 <                threadAssertFalse(f.isCompletedAbnormally());
121 <                threadAssertTrue(f.getRawResult() == null);
230 >                assertEquals(21, f.result);
231 >                checkCompletedNormally(f);
232              }};
233          testInvokeOnPool(mainPool(), a);
234      }
# Line 127 | Line 237 | public class RecursiveActionTest extends
237       * join of a forked task returns when task completes
238       */
239      public void testForkJoin() {
240 <        RecursiveAction a = new RecursiveAction() {
241 <            public void compute() {
240 >        RecursiveAction a = new CheckedRecursiveAction() {
241 >            public void realCompute() {
242                  FibAction f = new FibAction(8);
243 <                threadAssertSame(f, f.fork());
244 <                threadAssertNull(f.join());
245 <                threadAssertTrue(f.result == 21);
246 <                threadAssertTrue(f.isDone());
137 <                threadAssertTrue(f.getRawResult() == null);
243 >                assertSame(f, f.fork());
244 >                assertNull(f.join());
245 >                assertEquals(21, f.result);
246 >                checkCompletedNormally(f);
247              }};
248          testInvokeOnPool(mainPool(), a);
249      }
250  
251      /**
252 <     * get of a forked task returns when task completes
252 >     * join/quietlyJoin of a forked task succeeds in the presence of interrupts
253       */
254 <    public void testForkGet() {
255 <        RecursiveAction a = new RecursiveAction() {
256 <            public void compute() {
254 >    public void testJoinIgnoresInterrupts() {
255 >        RecursiveAction a = new CheckedRecursiveAction() {
256 >            public void realCompute() {
257 >                FibAction f = new FibAction(8);
258 >                final Thread myself = Thread.currentThread();
259 >
260 >                // test join()
261 >                assertSame(f, f.fork());
262 >                myself.interrupt();
263 >                assertTrue(myself.isInterrupted());
264 >                assertNull(f.join());
265 >                Thread.interrupted();
266 >                assertEquals(21, f.result);
267 >                checkCompletedNormally(f);
268 >
269 >                f.reinitialize();
270 >                f.cancel(true);
271 >                assertSame(f, f.fork());
272 >                myself.interrupt();
273 >                assertTrue(myself.isInterrupted());
274 >                try {
275 >                    f.join();
276 >                    shouldThrow();
277 >                } catch (CancellationException success) {
278 >                    Thread.interrupted();
279 >                    checkCancelled(f);
280 >                }
281 >
282 >                f.reinitialize();
283 >                f.completeExceptionally(new FJException());
284 >                assertSame(f, f.fork());
285 >                myself.interrupt();
286 >                assertTrue(myself.isInterrupted());
287                  try {
288 <                    FibAction f = new FibAction(8);
289 <                    threadAssertSame(f, f.fork());
290 <                    threadAssertNull(f.get());
291 <                    threadAssertTrue(f.result == 21);
292 <                    threadAssertTrue(f.isDone());
154 <                } catch (Exception ex) {
155 <                    unexpectedException(ex);
288 >                    f.join();
289 >                    shouldThrow();
290 >                } catch (FJException success) {
291 >                    Thread.interrupted();
292 >                    checkCompletedAbnormally(f, success);
293                  }
294 +
295 +                // test quietlyJoin()
296 +                f.reinitialize();
297 +                assertSame(f, f.fork());
298 +                myself.interrupt();
299 +                assertTrue(myself.isInterrupted());
300 +                f.quietlyJoin();
301 +                Thread.interrupted();
302 +                assertEquals(21, f.result);
303 +                checkCompletedNormally(f);
304 +
305 +                f.reinitialize();
306 +                f.cancel(true);
307 +                assertSame(f, f.fork());
308 +                myself.interrupt();
309 +                assertTrue(myself.isInterrupted());
310 +                f.quietlyJoin();
311 +                Thread.interrupted();
312 +                checkCancelled(f);
313 +
314 +                f.reinitialize();
315 +                f.completeExceptionally(new FJException());
316 +                assertSame(f, f.fork());
317 +                myself.interrupt();
318 +                assertTrue(myself.isInterrupted());
319 +                f.quietlyJoin();
320 +                Thread.interrupted();
321 +                checkCompletedAbnormally(f, f.getException());
322              }};
323          testInvokeOnPool(mainPool(), a);
324 +        a.reinitialize();
325 +        testInvokeOnPool(singletonPool(), a);
326      }
327  
328      /**
329 <     * timed get of a forked task returns when task completes
329 >     * join/quietlyJoin of a forked task when not in ForkJoinPool
330 >     * succeeds in the presence of interrupts
331       */
332 <    public void testForkTimedGet() {
333 <        RecursiveAction a = new RecursiveAction() {
334 <            public void compute() {
332 >    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
333 >        final SynchronousQueue<FibAction[]> sq =
334 >            new SynchronousQueue<FibAction[]>();
335 >        RecursiveAction a = new CheckedRecursiveAction() {
336 >            public void realCompute() throws InterruptedException {
337 >                FibAction[] fibActions = new FibAction[6];
338 >                for (int i = 0; i < fibActions.length; i++)
339 >                    fibActions[i] = new FibAction(8);
340 >
341 >                fibActions[1].cancel(false);
342 >                fibActions[2].completeExceptionally(new FJException());
343 >                fibActions[4].cancel(true);
344 >                fibActions[5].completeExceptionally(new FJException());
345 >
346 >                for (int i = 0; i < fibActions.length; i++)
347 >                    fibActions[i].fork();
348 >
349 >                sq.put(fibActions);
350 >
351 >                helpQuiesce();
352 >            }};
353 >
354 >        Runnable r = new CheckedRunnable() {
355 >            public void realRun() throws InterruptedException {
356 >                FibAction[] fibActions = sq.take();
357 >                FibAction f;
358 >                final Thread myself = Thread.currentThread();
359 >
360 >                // test join() ------------
361 >
362 >                f = fibActions[0];
363 >                assertFalse(ForkJoinTask.inForkJoinPool());
364 >                myself.interrupt();
365 >                assertTrue(myself.isInterrupted());
366 >                assertNull(f.join());
367 >                assertTrue(Thread.interrupted());
368 >                assertEquals(21, f.result);
369 >                checkCompletedNormally(f);
370 >
371 >                f = fibActions[1];
372 >                myself.interrupt();
373 >                assertTrue(myself.isInterrupted());
374 >                try {
375 >                    f.join();
376 >                    shouldThrow();
377 >                } catch (CancellationException success) {
378 >                    assertTrue(Thread.interrupted());
379 >                    checkCancelled(f);
380 >                }
381 >
382 >                f = fibActions[2];
383 >                myself.interrupt();
384 >                assertTrue(myself.isInterrupted());
385                  try {
386 <                    FibAction f = new FibAction(8);
387 <                    threadAssertSame(f, f.fork());
388 <                    threadAssertNull(f.get(5L, TimeUnit.SECONDS));
389 <                    threadAssertTrue(f.result == 21);
390 <                    threadAssertTrue(f.isDone());
173 <                } catch (Exception ex) {
174 <                    unexpectedException(ex);
386 >                    f.join();
387 >                    shouldThrow();
388 >                } catch (FJException success) {
389 >                    assertTrue(Thread.interrupted());
390 >                    checkCompletedAbnormally(f, success);
391                  }
392 +
393 +                // test quietlyJoin() ---------
394 +
395 +                f = fibActions[3];
396 +                myself.interrupt();
397 +                assertTrue(myself.isInterrupted());
398 +                f.quietlyJoin();
399 +                assertTrue(Thread.interrupted());
400 +                assertEquals(21, f.result);
401 +                checkCompletedNormally(f);
402 +
403 +                f = fibActions[4];
404 +                myself.interrupt();
405 +                assertTrue(myself.isInterrupted());
406 +                f.quietlyJoin();
407 +                assertTrue(Thread.interrupted());
408 +                checkCancelled(f);
409 +
410 +                f = fibActions[5];
411 +                myself.interrupt();
412 +                assertTrue(myself.isInterrupted());
413 +                f.quietlyJoin();
414 +                assertTrue(Thread.interrupted());
415 +                assertTrue(f.getException() instanceof FJException);
416 +                checkCompletedAbnormally(f, f.getException());
417 +            }};
418 +
419 +        Thread t;
420 +
421 +        t = newStartedThread(r);
422 +        testInvokeOnPool(mainPool(), a);
423 +        awaitTermination(t, LONG_DELAY_MS);
424 +
425 +        a.reinitialize();
426 +        t = newStartedThread(r);
427 +        testInvokeOnPool(singletonPool(), a);
428 +        awaitTermination(t, LONG_DELAY_MS);
429 +    }
430 +
431 +    /**
432 +     * get of a forked task returns when task completes
433 +     */
434 +    public void testForkGet() {
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());
440 +                assertEquals(21, f.result);
441 +                checkCompletedNormally(f);
442 +            }};
443 +        testInvokeOnPool(mainPool(), a);
444 +    }
445 +
446 +    /**
447 +     * timed get of a forked task returns when task completes
448 +     */
449 +    public void testForkTimedGet() {
450 +        RecursiveAction a = new CheckedRecursiveAction() {
451 +            public void realCompute() throws Exception {
452 +                FibAction f = new FibAction(8);
453 +                assertSame(f, f.fork());
454 +                assertNull(f.get(5L, SECONDS));
455 +                assertEquals(21, f.result);
456 +                checkCompletedNormally(f);
457              }};
458          testInvokeOnPool(mainPool(), a);
459      }
# Line 181 | Line 462 | public class RecursiveActionTest extends
462       * timed get with null time unit throws NPE
463       */
464      public void testForkTimedGetNPE() {
465 <        RecursiveAction a = new RecursiveAction() {
466 <            public void compute() {
465 >        RecursiveAction a = new CheckedRecursiveAction() {
466 >            public void realCompute() throws Exception {
467 >                FibAction f = new FibAction(8);
468 >                assertSame(f, f.fork());
469                  try {
187                    FibAction f = new FibAction(8);
188                    threadAssertSame(f, f.fork());
470                      f.get(5L, null);
471                      shouldThrow();
472 <                } catch (NullPointerException success) {
192 <                } catch (Exception ex) {
193 <                    unexpectedException(ex);
194 <                }
472 >                } catch (NullPointerException success) {}
473              }};
474          testInvokeOnPool(mainPool(), a);
475      }
# Line 200 | Line 478 | public class RecursiveActionTest extends
478       * quietlyJoin of a forked task returns when task completes
479       */
480      public void testForkQuietlyJoin() {
481 <        RecursiveAction a = new RecursiveAction() {
482 <            public void compute() {
481 >        RecursiveAction a = new CheckedRecursiveAction() {
482 >            public void realCompute() {
483                  FibAction f = new FibAction(8);
484 <                threadAssertSame(f, f.fork());
484 >                assertSame(f, f.fork());
485                  f.quietlyJoin();
486 <                threadAssertTrue(f.result == 21);
487 <                threadAssertTrue(f.isDone());
486 >                assertEquals(21, f.result);
487 >                checkCompletedNormally(f);
488              }};
489          testInvokeOnPool(mainPool(), a);
490      }
# Line 217 | Line 495 | public class RecursiveActionTest extends
495       * getQueuedTaskCount returns 0 when quiescent
496       */
497      public void testForkHelpQuiesce() {
498 <        RecursiveAction a = new RecursiveAction() {
499 <            public void compute() {
498 >        RecursiveAction a = new CheckedRecursiveAction() {
499 >            public void realCompute() {
500                  FibAction f = new FibAction(8);
501 <                threadAssertSame(f, f.fork());
501 >                assertSame(f, f.fork());
502                  f.helpQuiesce();
503 <                threadAssertTrue(f.result == 21);
504 <                threadAssertTrue(f.isDone());
505 <                threadAssertTrue(getQueuedTaskCount() == 0);
503 >                assertEquals(21, f.result);
504 >                assertEquals(0, getQueuedTaskCount());
505 >                checkCompletedNormally(f);
506              }};
507          testInvokeOnPool(mainPool(), a);
508      }
# Line 234 | Line 512 | public class RecursiveActionTest extends
512       * invoke task throws exception when task completes abnormally
513       */
514      public void testAbnormalInvoke() {
515 <        RecursiveAction a = new RecursiveAction() {
516 <            public void compute() {
515 >        RecursiveAction a = new CheckedRecursiveAction() {
516 >            public void realCompute() {
517 >                FailingFibAction f = new FailingFibAction(8);
518                  try {
240                    FailingFibAction f = new FailingFibAction(8);
519                      f.invoke();
520                      shouldThrow();
521                  } catch (FJException success) {
522 +                    checkCompletedAbnormally(f, success);
523                  }
524              }};
525          testInvokeOnPool(mainPool(), a);
# Line 250 | Line 529 | public class RecursiveActionTest extends
529       * quietlyInvoke task returns when task completes abnormally
530       */
531      public void testAbnormalQuietlyInvoke() {
532 <        RecursiveAction a = new RecursiveAction() {
533 <            public void compute() {
532 >        RecursiveAction a = new CheckedRecursiveAction() {
533 >            public void realCompute() {
534                  FailingFibAction f = new FailingFibAction(8);
535                  f.quietlyInvoke();
536 <                threadAssertTrue(f.isDone());
536 >                assertTrue(f.getException() instanceof FJException);
537 >                checkCompletedAbnormally(f, f.getException());
538              }};
539          testInvokeOnPool(mainPool(), a);
540      }
# Line 263 | Line 543 | public class RecursiveActionTest extends
543       * join of a forked task throws exception when task completes abnormally
544       */
545      public void testAbnormalForkJoin() {
546 <        RecursiveAction a = new RecursiveAction() {
547 <            public void compute() {
546 >        RecursiveAction a = new CheckedRecursiveAction() {
547 >            public void realCompute() {
548 >                FailingFibAction f = new FailingFibAction(8);
549 >                assertSame(f, f.fork());
550                  try {
269                    FailingFibAction f = new FailingFibAction(8);
270                    threadAssertSame(f, f.fork());
551                      f.join();
552                      shouldThrow();
553                  } catch (FJException success) {
554 +                    checkCompletedAbnormally(f, success);
555                  }
556              }};
557          testInvokeOnPool(mainPool(), a);
# Line 280 | Line 561 | public class RecursiveActionTest extends
561       * get of a forked task throws exception when task completes abnormally
562       */
563      public void testAbnormalForkGet() {
564 <        RecursiveAction a = new RecursiveAction() {
565 <            public void compute() {
564 >        RecursiveAction a = new CheckedRecursiveAction() {
565 >            public void realCompute() throws Exception {
566 >                FailingFibAction f = new FailingFibAction(8);
567 >                assertSame(f, f.fork());
568                  try {
286                    FailingFibAction f = new FailingFibAction(8);
287                    threadAssertSame(f, f.fork());
569                      f.get();
570                      shouldThrow();
571                  } catch (ExecutionException success) {
572 <                } catch (Exception ex) {
573 <                    unexpectedException(ex);
572 >                    Throwable cause = success.getCause();
573 >                    assertTrue(cause instanceof FJException);
574 >                    checkCompletedAbnormally(f, cause);
575                  }
576              }};
577          testInvokeOnPool(mainPool(), a);
# Line 299 | Line 581 | public class RecursiveActionTest extends
581       * timed get of a forked task throws exception when task completes abnormally
582       */
583      public void testAbnormalForkTimedGet() {
584 <        RecursiveAction a = new RecursiveAction() {
585 <            public void compute() {
584 >        RecursiveAction a = new CheckedRecursiveAction() {
585 >            public void realCompute() throws Exception {
586 >                FailingFibAction f = new FailingFibAction(8);
587 >                assertSame(f, f.fork());
588                  try {
305                    FailingFibAction f = new FailingFibAction(8);
306                    threadAssertSame(f, f.fork());
589                      f.get(5L, TimeUnit.SECONDS);
590                      shouldThrow();
591                  } catch (ExecutionException success) {
592 <                } catch (Exception ex) {
593 <                    unexpectedException(ex);
592 >                    Throwable cause = success.getCause();
593 >                    assertTrue(cause instanceof FJException);
594 >                    checkCompletedAbnormally(f, cause);
595                  }
596              }};
597          testInvokeOnPool(mainPool(), a);
# Line 318 | Line 601 | public class RecursiveActionTest extends
601       * quietlyJoin of a forked task returns when task completes abnormally
602       */
603      public void testAbnormalForkQuietlyJoin() {
604 <        RecursiveAction a = new RecursiveAction() {
605 <            public void compute() {
604 >        RecursiveAction a = new CheckedRecursiveAction() {
605 >            public void realCompute() {
606                  FailingFibAction f = new FailingFibAction(8);
607 <                threadAssertSame(f, f.fork());
607 >                assertSame(f, f.fork());
608                  f.quietlyJoin();
609 <                threadAssertTrue(f.isDone());
610 <                threadAssertTrue(f.isCompletedAbnormally());
328 <                threadAssertTrue(f.getException() instanceof FJException);
609 >                assertTrue(f.getException() instanceof FJException);
610 >                checkCompletedAbnormally(f, f.getException());
611              }};
612          testInvokeOnPool(mainPool(), a);
613      }
# Line 334 | Line 616 | public class RecursiveActionTest extends
616       * invoke task throws exception when task cancelled
617       */
618      public void testCancelledInvoke() {
619 <        RecursiveAction a = new RecursiveAction() {
620 <            public void compute() {
619 >        RecursiveAction a = new CheckedRecursiveAction() {
620 >            public void realCompute() {
621 >                FibAction f = new FibAction(8);
622 >                assertTrue(f.cancel(true));
623                  try {
340                    FibAction f = new FibAction(8);
341                    threadAssertTrue(f.cancel(true));
624                      f.invoke();
625                      shouldThrow();
626                  } catch (CancellationException success) {
627 +                    checkCancelled(f);
628                  }
629              }};
630          testInvokeOnPool(mainPool(), a);
# Line 351 | Line 634 | public class RecursiveActionTest extends
634       * join of a forked task throws exception when task cancelled
635       */
636      public void testCancelledForkJoin() {
637 <        RecursiveAction a = new RecursiveAction() {
638 <            public void compute() {
637 >        RecursiveAction a = new CheckedRecursiveAction() {
638 >            public void realCompute() {
639 >                FibAction f = new FibAction(8);
640 >                assertTrue(f.cancel(true));
641 >                assertSame(f, f.fork());
642                  try {
357                    FibAction f = new FibAction(8);
358                    threadAssertTrue(f.cancel(true));
359                    threadAssertSame(f, f.fork());
643                      f.join();
644                      shouldThrow();
645                  } catch (CancellationException success) {
646 +                    checkCancelled(f);
647                  }
648              }};
649          testInvokeOnPool(mainPool(), a);
# Line 369 | Line 653 | public class RecursiveActionTest extends
653       * get of a forked task throws exception when task cancelled
654       */
655      public void testCancelledForkGet() {
656 <        RecursiveAction a = new RecursiveAction() {
657 <            public void compute() {
656 >        RecursiveAction a = new CheckedRecursiveAction() {
657 >            public void realCompute() throws Exception {
658 >                FibAction f = new FibAction(8);
659 >                assertTrue(f.cancel(true));
660 >                assertSame(f, f.fork());
661                  try {
375                    FibAction f = new FibAction(8);
376                    threadAssertTrue(f.cancel(true));
377                    threadAssertSame(f, f.fork());
662                      f.get();
663                      shouldThrow();
664                  } catch (CancellationException success) {
665 <                } catch (Exception ex) {
382 <                    unexpectedException(ex);
665 >                    checkCancelled(f);
666                  }
667              }};
668          testInvokeOnPool(mainPool(), a);
# Line 389 | Line 672 | public class RecursiveActionTest extends
672       * timed get of a forked task throws exception when task cancelled
673       */
674      public void testCancelledForkTimedGet() {
675 <        RecursiveAction a = new RecursiveAction() {
676 <            public void compute() {
675 >        RecursiveAction a = new CheckedRecursiveAction() {
676 >            public void realCompute() throws Exception {
677 >                FibAction f = new FibAction(8);
678 >                assertTrue(f.cancel(true));
679 >                assertSame(f, f.fork());
680                  try {
681 <                    FibAction f = new FibAction(8);
396 <                    threadAssertTrue(f.cancel(true));
397 <                    threadAssertSame(f, f.fork());
398 <                    f.get(5L, TimeUnit.SECONDS);
681 >                    f.get(5L, SECONDS);
682                      shouldThrow();
683                  } catch (CancellationException success) {
684 <                } catch (Exception ex) {
402 <                    unexpectedException(ex);
684 >                    checkCancelled(f);
685                  }
686              }};
687          testInvokeOnPool(mainPool(), a);
# Line 409 | Line 691 | public class RecursiveActionTest extends
691       * quietlyJoin of a forked task returns when task cancelled
692       */
693      public void testCancelledForkQuietlyJoin() {
694 <        RecursiveAction a = new RecursiveAction() {
695 <            public void compute() {
694 >        RecursiveAction a = new CheckedRecursiveAction() {
695 >            public void realCompute() {
696                  FibAction f = new FibAction(8);
697 <                threadAssertTrue(f.cancel(true));
698 <                threadAssertSame(f, f.fork());
697 >                assertTrue(f.cancel(true));
698 >                assertSame(f, f.fork());
699                  f.quietlyJoin();
700 <                threadAssertTrue(f.isDone());
419 <                threadAssertTrue(f.isCompletedAbnormally());
420 <                threadAssertTrue(f.getException() instanceof CancellationException);
700 >                checkCancelled(f);
701              }};
702          testInvokeOnPool(mainPool(), a);
703      }
# Line 427 | Line 707 | public class RecursiveActionTest extends
707       */
708      public void testGetPool() {
709          final ForkJoinPool mainPool = mainPool();
710 <        RecursiveAction a = new RecursiveAction() {
711 <            final ForkJoinPool p = mainPool;
712 <            public void compute() {
433 <                threadAssertTrue(getPool() == p);
710 >        RecursiveAction a = new CheckedRecursiveAction() {
711 >            public void realCompute() {
712 >                assertSame(mainPool, getPool());
713              }};
714          testInvokeOnPool(mainPool, a);
715      }
# Line 439 | Line 718 | public class RecursiveActionTest extends
718       * getPool of non-FJ task returns null
719       */
720      public void testGetPool2() {
721 <        RecursiveAction a = new RecursiveAction() {
722 <            public void compute() {
723 <                threadAssertTrue(getPool() == null);
721 >        RecursiveAction a = new CheckedRecursiveAction() {
722 >            public void realCompute() {
723 >                assertNull(getPool());
724              }};
725          assertNull(a.invoke());
726      }
# Line 450 | Line 729 | public class RecursiveActionTest extends
729       * inForkJoinPool of executing task returns true
730       */
731      public void testInForkJoinPool() {
732 <        RecursiveAction a = new RecursiveAction() {
733 <            public void compute() {
734 <                threadAssertTrue(inForkJoinPool());
732 >        RecursiveAction a = new CheckedRecursiveAction() {
733 >            public void realCompute() {
734 >                assertTrue(inForkJoinPool());
735              }};
736          testInvokeOnPool(mainPool(), a);
737      }
# Line 461 | Line 740 | public class RecursiveActionTest extends
740       * inForkJoinPool of non-FJ task returns false
741       */
742      public void testInForkJoinPool2() {
743 <        RecursiveAction a = new RecursiveAction() {
744 <            public void compute() {
745 <                threadAssertTrue(!inForkJoinPool());
743 >        RecursiveAction a = new CheckedRecursiveAction() {
744 >            public void realCompute() {
745 >                assertFalse(inForkJoinPool());
746              }};
747          assertNull(a.invoke());
748      }
# Line 473 | Line 752 | public class RecursiveActionTest extends
752       */
753      public void testWorkerGetPool() {
754          final ForkJoinPool mainPool = mainPool();
755 <        RecursiveAction a = new RecursiveAction() {
756 <            public void compute() {
755 >        RecursiveAction a = new CheckedRecursiveAction() {
756 >            public void realCompute() {
757                  ForkJoinWorkerThread w =
758                      (ForkJoinWorkerThread) Thread.currentThread();
759 <                threadAssertTrue(w.getPool() == mainPool);
759 >                assertSame(mainPool, w.getPool());
760              }};
761          testInvokeOnPool(mainPool, a);
762      }
# Line 487 | Line 766 | public class RecursiveActionTest extends
766       */
767      public void testWorkerGetPoolIndex() {
768          final ForkJoinPool mainPool = mainPool();
769 <        RecursiveAction a = new RecursiveAction() {
770 <            public void compute() {
769 >        RecursiveAction a = new CheckedRecursiveAction() {
770 >            public void realCompute() {
771                  ForkJoinWorkerThread w =
772 <                    (ForkJoinWorkerThread)(Thread.currentThread());
773 <                int idx = w.getPoolIndex();
774 <                threadAssertTrue(idx >= 0);
496 <                threadAssertTrue(idx < mainPool.getPoolSize());
772 >                    (ForkJoinWorkerThread) Thread.currentThread();
773 >                assertTrue(w.getPoolIndex() >= 0);
774 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
775              }};
776          testInvokeOnPool(mainPool, a);
777      }
# Line 503 | Line 781 | public class RecursiveActionTest extends
781       * setRawResult(null) succeeds
782       */
783      public void testSetRawResult() {
784 <        RecursiveAction a = new RecursiveAction() {
785 <            public void compute() {
784 >        RecursiveAction a = new CheckedRecursiveAction() {
785 >            public void realCompute() {
786                  setRawResult(null);
787 +                assertNull(getRawResult());
788              }};
789          assertNull(a.invoke());
790      }
# Line 514 | Line 793 | public class RecursiveActionTest extends
793       * A reinitialized task may be re-invoked
794       */
795      public void testReinitialize() {
796 <        RecursiveAction a = new RecursiveAction() {
797 <            public void compute() {
796 >        RecursiveAction a = new CheckedRecursiveAction() {
797 >            public void realCompute() {
798                  FibAction f = new FibAction(8);
799 <                threadAssertNull(f.invoke());
800 <                threadAssertTrue(f.result == 21);
801 <                threadAssertTrue(f.isDone());
802 <                threadAssertFalse(f.isCancelled());
803 <                threadAssertFalse(f.isCompletedAbnormally());
804 <                f.reinitialize();
805 <                threadAssertNull(f.invoke());
806 <                threadAssertTrue(f.result == 21);
799 >                checkNotDone(f);
800 >
801 >                for (int i = 0; i < 3; i++) {
802 >                    assertNull(f.invoke());
803 >                    assertEquals(21, f.result);
804 >                    checkCompletedNormally(f);
805 >                    f.reinitialize();
806 >                    checkNotDone(f);
807 >                }
808              }};
809          testInvokeOnPool(mainPool(), a);
810      }
# Line 533 | Line 813 | public class RecursiveActionTest extends
813       * invoke task throws exception after invoking completeExceptionally
814       */
815      public void testCompleteExceptionally() {
816 <        RecursiveAction a = new RecursiveAction() {
817 <            public void compute() {
816 >        RecursiveAction a = new CheckedRecursiveAction() {
817 >            public void realCompute() {
818 >                FibAction f = new FibAction(8);
819 >                f.completeExceptionally(new FJException());
820                  try {
539                    FibAction f = new FibAction(8);
540                    f.completeExceptionally(new FJException());
821                      f.invoke();
822                      shouldThrow();
823                  } catch (FJException success) {
824 +                    checkCompletedAbnormally(f, success);
825                  }
826              }};
827          testInvokeOnPool(mainPool(), a);
# Line 550 | Line 831 | public class RecursiveActionTest extends
831       * invoke task suppresses execution invoking complete
832       */
833      public void testComplete() {
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                  f.complete(null);
838 <                threadAssertNull(f.invoke());
839 <                threadAssertTrue(f.isDone());
840 <                threadAssertTrue(f.result == 0);
838 >                assertNull(f.invoke());
839 >                assertEquals(0, f.result);
840 >                checkCompletedNormally(f);
841              }};
842          testInvokeOnPool(mainPool(), a);
843      }
# Line 565 | Line 846 | public class RecursiveActionTest extends
846       * invokeAll(t1, t2) invokes all task arguments
847       */
848      public void testInvokeAll2() {
849 <        RecursiveAction a = new RecursiveAction() {
850 <            public void compute() {
849 >        RecursiveAction a = new CheckedRecursiveAction() {
850 >            public void realCompute() {
851                  FibAction f = new FibAction(8);
852                  FibAction g = new FibAction(9);
853                  invokeAll(f, g);
854 <                threadAssertTrue(f.isDone());
855 <                threadAssertTrue(f.result == 21);
856 <                threadAssertTrue(g.isDone());
857 <                threadAssertTrue(g.result == 34);
854 >                checkCompletedNormally(f);
855 >                assertEquals(21, f.result);
856 >                checkCompletedNormally(g);
857 >                assertEquals(34, g.result);
858              }};
859          testInvokeOnPool(mainPool(), a);
860      }
# Line 582 | Line 863 | public class RecursiveActionTest extends
863       * invokeAll(tasks) with 1 argument invokes task
864       */
865      public void testInvokeAll1() {
866 <        RecursiveAction a = new RecursiveAction() {
867 <            public void compute() {
866 >        RecursiveAction a = new CheckedRecursiveAction() {
867 >            public void realCompute() {
868                  FibAction f = new FibAction(8);
869                  invokeAll(f);
870 <                threadAssertTrue(f.isDone());
871 <                threadAssertTrue(f.result == 21);
870 >                checkCompletedNormally(f);
871 >                assertEquals(21, f.result);
872              }};
873          testInvokeOnPool(mainPool(), a);
874      }
# Line 596 | Line 877 | public class RecursiveActionTest extends
877       * invokeAll(tasks) with > 2 argument invokes tasks
878       */
879      public void testInvokeAll3() {
880 <        RecursiveAction a = new RecursiveAction() {
881 <            public void compute() {
880 >        RecursiveAction a = new CheckedRecursiveAction() {
881 >            public void realCompute() {
882                  FibAction f = new FibAction(8);
883                  FibAction g = new FibAction(9);
884                  FibAction h = new FibAction(7);
885                  invokeAll(f, g, h);
886 <                threadAssertTrue(f.isDone());
887 <                threadAssertTrue(f.result == 21);
888 <                threadAssertTrue(g.isDone());
889 <                threadAssertTrue(g.result == 34);
890 <                threadAssertTrue(h.isDone());
891 <                threadAssertTrue(h.result == 13);
886 >                assertTrue(f.isDone());
887 >                assertTrue(g.isDone());
888 >                assertTrue(h.isDone());
889 >                checkCompletedNormally(f);
890 >                assertEquals(21, f.result);
891 >                checkCompletedNormally(g);
892 >                assertEquals(34, g.result);
893 >                checkCompletedNormally(g);
894 >                assertEquals(13, h.result);
895              }};
896          testInvokeOnPool(mainPool(), a);
897      }
# Line 616 | Line 900 | public class RecursiveActionTest extends
900       * invokeAll(collection) invokes all tasks in the collection
901       */
902      public void testInvokeAllCollection() {
903 <        RecursiveAction a = new RecursiveAction() {
904 <            public void compute() {
903 >        RecursiveAction a = new CheckedRecursiveAction() {
904 >            public void realCompute() {
905                  FibAction f = new FibAction(8);
906                  FibAction g = new FibAction(9);
907                  FibAction h = new FibAction(7);
# Line 626 | Line 910 | public class RecursiveActionTest extends
910                  set.add(g);
911                  set.add(h);
912                  invokeAll(set);
913 <                threadAssertTrue(f.isDone());
914 <                threadAssertTrue(f.result == 21);
915 <                threadAssertTrue(g.isDone());
916 <                threadAssertTrue(g.result == 34);
917 <                threadAssertTrue(h.isDone());
918 <                threadAssertTrue(h.result == 13);
913 >                assertTrue(f.isDone());
914 >                assertTrue(g.isDone());
915 >                assertTrue(h.isDone());
916 >                checkCompletedNormally(f);
917 >                assertEquals(21, f.result);
918 >                checkCompletedNormally(g);
919 >                assertEquals(34, g.result);
920 >                checkCompletedNormally(g);
921 >                assertEquals(13, h.result);
922              }};
923          testInvokeOnPool(mainPool(), a);
924      }
# Line 641 | Line 928 | public class RecursiveActionTest extends
928       * invokeAll(tasks) with any null task throws NPE
929       */
930      public void testInvokeAllNPE() {
931 <        RecursiveAction a = new RecursiveAction() {
932 <            public void compute() {
931 >        RecursiveAction a = new CheckedRecursiveAction() {
932 >            public void realCompute() {
933 >                FibAction f = new FibAction(8);
934 >                FibAction g = new FibAction(9);
935 >                FibAction h = null;
936                  try {
647                    FibAction f = new FibAction(8);
648                    FibAction g = new FibAction(9);
649                    FibAction h = null;
937                      invokeAll(f, g, h);
938                      shouldThrow();
939 <                } catch (NullPointerException success) {
653 <                }
939 >                } catch (NullPointerException success) {}
940              }};
941          testInvokeOnPool(mainPool(), a);
942      }
# Line 659 | Line 945 | public class RecursiveActionTest extends
945       * invokeAll(t1, t2) throw exception if any task does
946       */
947      public void testAbnormalInvokeAll2() {
948 <        RecursiveAction a = new RecursiveAction() {
949 <            public void compute() {
948 >        RecursiveAction a = new CheckedRecursiveAction() {
949 >            public void realCompute() {
950 >                FibAction f = new FibAction(8);
951 >                FailingFibAction g = new FailingFibAction(9);
952                  try {
665                    FibAction f = new FibAction(8);
666                    FailingFibAction g = new FailingFibAction(9);
953                      invokeAll(f, g);
954                      shouldThrow();
955                  } catch (FJException success) {
956 +                    checkCompletedAbnormally(g, success);
957                  }
958              }};
959          testInvokeOnPool(mainPool(), a);
# Line 676 | Line 963 | public class RecursiveActionTest extends
963       * invokeAll(tasks) with 1 argument throws exception if task does
964       */
965      public void testAbnormalInvokeAll1() {
966 <        RecursiveAction a = new RecursiveAction() {
967 <            public void compute() {
966 >        RecursiveAction a = new CheckedRecursiveAction() {
967 >            public void realCompute() {
968 >                FailingFibAction g = new FailingFibAction(9);
969                  try {
682                    FailingFibAction g = new FailingFibAction(9);
970                      invokeAll(g);
971                      shouldThrow();
972                  } catch (FJException success) {
973 +                    checkCompletedAbnormally(g, success);
974                  }
975              }};
976          testInvokeOnPool(mainPool(), a);
# Line 692 | Line 980 | public class RecursiveActionTest extends
980       * invokeAll(tasks) with > 2 argument throws exception if any task does
981       */
982      public void testAbnormalInvokeAll3() {
983 <        RecursiveAction a = new RecursiveAction() {
984 <            public void compute() {
983 >        RecursiveAction a = new CheckedRecursiveAction() {
984 >            public void realCompute() {
985 >                FibAction f = new FibAction(8);
986 >                FailingFibAction g = new FailingFibAction(9);
987 >                FibAction h = new FibAction(7);
988                  try {
698                    FibAction f = new FibAction(8);
699                    FailingFibAction g = new FailingFibAction(9);
700                    FibAction h = new FibAction(7);
989                      invokeAll(f, g, h);
990                      shouldThrow();
991                  } catch (FJException success) {
992 +                    checkCompletedAbnormally(g, success);
993                  }
994              }};
995          testInvokeOnPool(mainPool(), a);
# Line 710 | Line 999 | public class RecursiveActionTest extends
999       * invokeAll(collection) throws exception if any task does
1000       */
1001      public void testAbnormalInvokeAllCollection() {
1002 <        RecursiveAction a = new RecursiveAction() {
1003 <            public void compute() {
1002 >        RecursiveAction a = new CheckedRecursiveAction() {
1003 >            public void realCompute() {
1004 >                FailingFibAction f = new FailingFibAction(8);
1005 >                FibAction g = new FibAction(9);
1006 >                FibAction h = new FibAction(7);
1007 >                HashSet set = new HashSet();
1008 >                set.add(f);
1009 >                set.add(g);
1010 >                set.add(h);
1011                  try {
716                    FailingFibAction f = new FailingFibAction(8);
717                    FibAction g = new FibAction(9);
718                    FibAction h = new FibAction(7);
719                    HashSet set = new HashSet();
720                    set.add(f);
721                    set.add(g);
722                    set.add(h);
1012                      invokeAll(set);
1013                      shouldThrow();
1014                  } catch (FJException success) {
1015 +                    checkCompletedAbnormally(f, success);
1016                  }
1017              }};
1018          testInvokeOnPool(mainPool(), a);
# Line 733 | Line 1023 | public class RecursiveActionTest extends
1023       * and suppresses execution
1024       */
1025      public void testTryUnfork() {
1026 <        RecursiveAction a = new RecursiveAction() {
1027 <            public void compute() {
1026 >        RecursiveAction a = new CheckedRecursiveAction() {
1027 >            public void realCompute() {
1028                  FibAction g = new FibAction(9);
1029 <                threadAssertSame(g, g.fork());
1029 >                assertSame(g, g.fork());
1030                  FibAction f = new FibAction(8);
1031 <                threadAssertSame(f, f.fork());
1032 <                threadAssertTrue(f.tryUnfork());
1031 >                assertSame(f, f.fork());
1032 >                assertTrue(f.tryUnfork());
1033                  helpQuiesce();
1034 <                threadAssertFalse(f.isDone());
1035 <                threadAssertTrue(g.isDone());
1034 >                checkNotDone(f);
1035 >                checkCompletedNormally(g);
1036              }};
1037          testInvokeOnPool(singletonPool(), a);
1038      }
# Line 752 | Line 1042 | public class RecursiveActionTest extends
1042       * there are more tasks than threads
1043       */
1044      public void testGetSurplusQueuedTaskCount() {
1045 <        RecursiveAction a = new RecursiveAction() {
1046 <            public void compute() {
1045 >        RecursiveAction a = new CheckedRecursiveAction() {
1046 >            public void realCompute() {
1047                  FibAction h = new FibAction(7);
1048 <                threadAssertSame(h, h.fork());
1048 >                assertSame(h, h.fork());
1049                  FibAction g = new FibAction(9);
1050 <                threadAssertSame(g, g.fork());
1050 >                assertSame(g, g.fork());
1051                  FibAction f = new FibAction(8);
1052 <                threadAssertSame(f, f.fork());
1053 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
1052 >                assertSame(f, f.fork());
1053 >                assertTrue(getSurplusQueuedTaskCount() > 0);
1054                  helpQuiesce();
1055 +                assertEquals(0, getSurplusQueuedTaskCount());
1056 +                checkCompletedNormally(f);
1057 +                checkCompletedNormally(g);
1058 +                checkCompletedNormally(h);
1059              }};
1060          testInvokeOnPool(singletonPool(), a);
1061      }
# Line 770 | Line 1064 | public class RecursiveActionTest extends
1064       * peekNextLocalTask returns most recent unexecuted task.
1065       */
1066      public void testPeekNextLocalTask() {
1067 <        RecursiveAction a = new RecursiveAction() {
1068 <            public void compute() {
1067 >        RecursiveAction a = new CheckedRecursiveAction() {
1068 >            public void realCompute() {
1069                  FibAction g = new FibAction(9);
1070 <                threadAssertSame(g, g.fork());
1070 >                assertSame(g, g.fork());
1071                  FibAction f = new FibAction(8);
1072 <                threadAssertSame(f, f.fork());
1073 <                threadAssertTrue(peekNextLocalTask() == f);
1074 <                threadAssertNull(f.join());
1075 <                threadAssertTrue(f.isDone());
1072 >                assertSame(f, f.fork());
1073 >                assertSame(f, peekNextLocalTask());
1074 >                assertNull(f.join());
1075 >                checkCompletedNormally(f);
1076                  helpQuiesce();
1077 +                checkCompletedNormally(f);
1078 +                checkCompletedNormally(g);
1079              }};
1080          testInvokeOnPool(singletonPool(), a);
1081      }
# Line 789 | Line 1085 | public class RecursiveActionTest extends
1085       * without executing it
1086       */
1087      public void testPollNextLocalTask() {
1088 <        RecursiveAction a = new RecursiveAction() {
1089 <            public void compute() {
1088 >        RecursiveAction a = new CheckedRecursiveAction() {
1089 >            public void realCompute() {
1090                  FibAction g = new FibAction(9);
1091 <                threadAssertSame(g, g.fork());
1091 >                assertSame(g, g.fork());
1092                  FibAction f = new FibAction(8);
1093 <                threadAssertSame(f, f.fork());
1094 <                threadAssertTrue(pollNextLocalTask() == f);
1093 >                assertSame(f, f.fork());
1094 >                assertSame(f, pollNextLocalTask());
1095                  helpQuiesce();
1096 <                threadAssertFalse(f.isDone());
1096 >                checkNotDone(f);
1097 >                checkCompletedNormally(g);
1098              }};
1099          testInvokeOnPool(singletonPool(), a);
1100      }
1101  
1102      /**
1103 <     * pollTask returns an unexecuted task
807 <     * without executing it
1103 >     * pollTask returns an unexecuted task without executing it
1104       */
1105      public void testPollTask() {
1106 <        RecursiveAction a = new RecursiveAction() {
1107 <            public void compute() {
1106 >        RecursiveAction a = new CheckedRecursiveAction() {
1107 >            public void realCompute() {
1108                  FibAction g = new FibAction(9);
1109 <                threadAssertSame(g, g.fork());
1109 >                assertSame(g, g.fork());
1110                  FibAction f = new FibAction(8);
1111 <                threadAssertSame(f, f.fork());
1112 <                threadAssertTrue(pollTask() == f);
1111 >                assertSame(f, f.fork());
1112 >                assertSame(f, pollTask());
1113                  helpQuiesce();
1114 <                threadAssertFalse(f.isDone());
1115 <                threadAssertTrue(g.isDone());
1114 >                checkNotDone(f);
1115 >                checkCompletedNormally(g);
1116              }};
1117          testInvokeOnPool(singletonPool(), a);
1118      }
# Line 825 | Line 1121 | public class RecursiveActionTest extends
1121       * peekNextLocalTask returns least recent unexecuted task in async mode
1122       */
1123      public void testPeekNextLocalTaskAsync() {
1124 <        RecursiveAction a = new RecursiveAction() {
1125 <            public void compute() {
1124 >        RecursiveAction a = new CheckedRecursiveAction() {
1125 >            public void realCompute() {
1126                  FibAction g = new FibAction(9);
1127 <                threadAssertSame(g, g.fork());
1127 >                assertSame(g, g.fork());
1128                  FibAction f = new FibAction(8);
1129 <                threadAssertSame(f, f.fork());
1130 <                threadAssertTrue(peekNextLocalTask() == g);
1131 <                threadAssertNull(f.join());
1129 >                assertSame(f, f.fork());
1130 >                assertSame(g, peekNextLocalTask());
1131 >                assertNull(f.join());
1132                  helpQuiesce();
1133 <                threadAssertTrue(f.isDone());
1133 >                checkCompletedNormally(f);
1134 >                checkCompletedNormally(g);
1135              }};
1136          testInvokeOnPool(asyncSingletonPool(), a);
1137      }
1138  
1139      /**
1140 <     * pollNextLocalTask returns least recent unexecuted task
1141 <     * without executing it, in async mode
1140 >     * pollNextLocalTask returns least recent unexecuted task without
1141 >     * executing it, in async mode
1142       */
1143      public void testPollNextLocalTaskAsync() {
1144 <        RecursiveAction a = new RecursiveAction() {
1145 <            public void compute() {
1144 >        RecursiveAction a = new CheckedRecursiveAction() {
1145 >            public void realCompute() {
1146                  FibAction g = new FibAction(9);
1147 <                threadAssertSame(g, g.fork());
1147 >                assertSame(g, g.fork());
1148                  FibAction f = new FibAction(8);
1149 <                threadAssertSame(f, f.fork());
1150 <                threadAssertTrue(pollNextLocalTask() == g);
1149 >                assertSame(f, f.fork());
1150 >                assertSame(g, pollNextLocalTask());
1151                  helpQuiesce();
1152 <                threadAssertTrue(f.isDone());
1153 <                threadAssertFalse(g.isDone());
1152 >                checkCompletedNormally(f);
1153 >                checkNotDone(g);
1154              }};
1155          testInvokeOnPool(asyncSingletonPool(), a);
1156      }
1157  
1158      /**
1159 <     * pollTask returns an unexecuted task
1160 <     * without executing it, in async mode
1159 >     * pollTask returns an unexecuted task without executing it, in
1160 >     * async mode
1161       */
1162      public void testPollTaskAsync() {
1163 <        RecursiveAction a = new RecursiveAction() {
1164 <            public void compute() {
1163 >        RecursiveAction a = new CheckedRecursiveAction() {
1164 >            public void realCompute() {
1165                  FibAction g = new FibAction(9);
1166 <                threadAssertSame(g, g.fork());
1166 >                assertSame(g, g.fork());
1167                  FibAction f = new FibAction(8);
1168 <                threadAssertSame(f, f.fork());
1169 <                threadAssertTrue(pollTask() == g);
1168 >                assertSame(f, f.fork());
1169 >                assertSame(g, pollTask());
1170                  helpQuiesce();
1171 <                threadAssertTrue(f.isDone());
1172 <                threadAssertFalse(g.isDone());
1171 >                checkCompletedNormally(f);
1172 >                checkNotDone(g);
1173              }};
1174          testInvokeOnPool(asyncSingletonPool(), a);
1175      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines