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.27 by jsr166, Tue Nov 23 08:48:23 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 <                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 <                f.fork();
244 <                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 >
259 >                // test join()
260 >                assertSame(f, f.fork());
261 >                Thread.currentThread().interrupt();
262 >                assertNull(f.join());
263 >                Thread.interrupted();
264 >                assertEquals(21, f.result);
265 >                checkCompletedNormally(f);
266 >
267 >                f.reinitialize();
268 >                f.cancel(true);
269 >                assertSame(f, f.fork());
270 >                Thread.currentThread().interrupt();
271                  try {
272 <                    FibAction f = new FibAction(8);
273 <                    f.fork();
274 <                    f.get();
275 <                    threadAssertTrue(f.result == 21);
276 <                    threadAssertTrue(f.isDone());
154 <                } catch (Exception ex) {
155 <                    unexpectedException(ex);
272 >                    f.join();
273 >                    shouldThrow();
274 >                } catch (CancellationException success) {
275 >                    Thread.interrupted();
276 >                    checkCancelled(f);
277                  }
278 +
279 +                f.reinitialize();
280 +                f.completeExceptionally(new FJException());
281 +                assertSame(f, f.fork());
282 +                Thread.currentThread().interrupt();
283 +                try {
284 +                    f.join();
285 +                    shouldThrow();
286 +                } catch (FJException success) {
287 +                    Thread.interrupted();
288 +                    checkCompletedAbnormally(f, success);
289 +                }
290 +
291 +                // test quietlyJoin()
292 +                f.reinitialize();
293 +                assertSame(f, f.fork());
294 +                Thread.currentThread().interrupt();
295 +                f.quietlyJoin();
296 +                Thread.interrupted();
297 +                assertEquals(21, f.result);
298 +                checkCompletedNormally(f);
299 +
300 +                f.reinitialize();
301 +                f.cancel(true);
302 +                assertSame(f, f.fork());
303 +                Thread.currentThread().interrupt();
304 +                f.quietlyJoin();
305 +                Thread.interrupted();
306 +                checkCancelled(f);
307 +
308 +                f.reinitialize();
309 +                f.completeExceptionally(new FJException());
310 +                assertSame(f, f.fork());
311 +                Thread.currentThread().interrupt();
312 +                f.quietlyJoin();
313 +                Thread.interrupted();
314 +                checkCompletedAbnormally(f, f.getException());
315              }};
316          testInvokeOnPool(mainPool(), a);
317 +        a.reinitialize();
318 +        testInvokeOnPool(singletonPool(), a);
319      }
320  
321      /**
322 <     * timed get of a forked task returns when task completes
322 >     * join/quietlyJoin of a forked task when not in ForkJoinPool
323 >     * succeeds in the presence of interrupts
324       */
325 <    public void testForkTimedGet() {
326 <        RecursiveAction a = new RecursiveAction() {
327 <            public void compute() {
325 >    public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
326 >        final SynchronousQueue<FibAction[]> sq =
327 >            new SynchronousQueue<FibAction[]>();
328 >        RecursiveAction a = new CheckedRecursiveAction() {
329 >            public void realCompute() throws InterruptedException {
330 >                FibAction[] fibActions = new FibAction[6];
331 >                for (int i = 0; i < fibActions.length; i++)
332 >                    fibActions[i] = new FibAction(8);
333 >
334 >                fibActions[1].cancel(false);
335 >                fibActions[2].completeExceptionally(new FJException());
336 >                fibActions[4].cancel(true);
337 >                fibActions[5].completeExceptionally(new FJException());
338 >
339 >                for (int i = 0; i < fibActions.length; i++)
340 >                    fibActions[i].fork();
341 >
342 >                sq.put(fibActions);
343 >
344 >                helpQuiesce();
345 >            }};
346 >
347 >        Runnable r = new CheckedRunnable() {
348 >            public void realRun() throws InterruptedException {
349 >                FibAction[] fibActions = sq.take();
350 >                FibAction f;
351 >
352 >                // test join() ------------
353 >
354 >                f = fibActions[0];
355 >                assertFalse(ForkJoinTask.inForkJoinPool());
356 >                Thread.currentThread().interrupt();
357 >                assertNull(f.join());
358 >                assertTrue(Thread.interrupted());
359 >                assertEquals(21, f.result);
360 >                checkCompletedNormally(f);
361 >
362 >                f = fibActions[1];
363 >                Thread.currentThread().interrupt();
364                  try {
365 <                    FibAction f = new FibAction(8);
366 <                    f.fork();
367 <                    f.get(5L, TimeUnit.SECONDS);
368 <                    threadAssertTrue(f.result == 21);
369 <                    threadAssertTrue(f.isDone());
173 <                } catch (Exception ex) {
174 <                    unexpectedException(ex);
365 >                    f.join();
366 >                    shouldThrow();
367 >                } catch (CancellationException success) {
368 >                    assertTrue(Thread.interrupted());
369 >                    checkCancelled(f);
370                  }
371 +
372 +                f = fibActions[2];
373 +                Thread.currentThread().interrupt();
374 +                try {
375 +                    f.join();
376 +                    shouldThrow();
377 +                } catch (FJException success) {
378 +                    assertTrue(Thread.interrupted());
379 +                    checkCompletedAbnormally(f, success);
380 +                }
381 +
382 +                // test quietlyJoin() ---------
383 +
384 +                f = fibActions[3];
385 +                Thread.currentThread().interrupt();
386 +                f.quietlyJoin();
387 +                assertTrue(Thread.interrupted());
388 +                assertEquals(21, f.result);
389 +                checkCompletedNormally(f);
390 +
391 +                f = fibActions[4];
392 +                Thread.currentThread().interrupt();
393 +                f.quietlyJoin();
394 +                assertTrue(Thread.interrupted());
395 +                checkCancelled(f);
396 +
397 +                f = fibActions[5];
398 +                Thread.currentThread().interrupt();
399 +                f.quietlyJoin();
400 +                assertTrue(Thread.interrupted());
401 +                assertTrue(f.getException() instanceof FJException);
402 +                checkCompletedAbnormally(f, f.getException());
403 +            }};
404 +
405 +        Thread t;
406 +
407 +        t = newStartedThread(r);
408 +        testInvokeOnPool(mainPool(), a);
409 +        awaitTermination(t, LONG_DELAY_MS);
410 +
411 +        a.reinitialize();
412 +        t = newStartedThread(r);
413 +        testInvokeOnPool(singletonPool(), a);
414 +        awaitTermination(t, LONG_DELAY_MS);
415 +    }
416 +
417 +    /**
418 +     * get of a forked task returns when task completes
419 +     */
420 +    public void testForkGet() {
421 +        RecursiveAction a = new CheckedRecursiveAction() {
422 +            public void realCompute() throws Exception {
423 +                FibAction f = new FibAction(8);
424 +                assertSame(f, f.fork());
425 +                assertNull(f.get());
426 +                assertEquals(21, f.result);
427 +                checkCompletedNormally(f);
428 +            }};
429 +        testInvokeOnPool(mainPool(), a);
430 +    }
431 +
432 +    /**
433 +     * timed get of a forked task returns when task completes
434 +     */
435 +    public void testForkTimedGet() {
436 +        RecursiveAction a = new CheckedRecursiveAction() {
437 +            public void realCompute() throws Exception {
438 +                FibAction f = new FibAction(8);
439 +                assertSame(f, f.fork());
440 +                assertNull(f.get(5L, SECONDS));
441 +                assertEquals(21, f.result);
442 +                checkCompletedNormally(f);
443              }};
444          testInvokeOnPool(mainPool(), a);
445      }
# Line 181 | Line 448 | public class RecursiveActionTest extends
448       * timed get with null time unit throws NPE
449       */
450      public void testForkTimedGetNPE() {
451 <        RecursiveAction a = new RecursiveAction() {
452 <            public void compute() {
451 >        RecursiveAction a = new CheckedRecursiveAction() {
452 >            public void realCompute() throws Exception {
453 >                FibAction f = new FibAction(8);
454 >                assertSame(f, f.fork());
455                  try {
187                    FibAction f = new FibAction(8);
188                    f.fork();
456                      f.get(5L, null);
457                      shouldThrow();
458 <                } catch (NullPointerException success) {
192 <                } catch (Exception ex) {
193 <                    unexpectedException(ex);
194 <                }
458 >                } catch (NullPointerException success) {}
459              }};
460          testInvokeOnPool(mainPool(), a);
461      }
# Line 200 | Line 464 | public class RecursiveActionTest extends
464       * quietlyJoin of a forked task returns when task completes
465       */
466      public void testForkQuietlyJoin() {
467 <        RecursiveAction a = new RecursiveAction() {
468 <            public void compute() {
467 >        RecursiveAction a = new CheckedRecursiveAction() {
468 >            public void realCompute() {
469                  FibAction f = new FibAction(8);
470 <                f.fork();
470 >                assertSame(f, f.fork());
471                  f.quietlyJoin();
472 <                threadAssertTrue(f.result == 21);
473 <                threadAssertTrue(f.isDone());
472 >                assertEquals(21, f.result);
473 >                checkCompletedNormally(f);
474              }};
475          testInvokeOnPool(mainPool(), a);
476      }
# Line 217 | Line 481 | public class RecursiveActionTest extends
481       * getQueuedTaskCount returns 0 when quiescent
482       */
483      public void testForkHelpQuiesce() {
484 <        RecursiveAction a = new RecursiveAction() {
485 <            public void compute() {
484 >        RecursiveAction a = new CheckedRecursiveAction() {
485 >            public void realCompute() {
486                  FibAction f = new FibAction(8);
487 <                f.fork();
487 >                assertSame(f, f.fork());
488                  f.helpQuiesce();
489 <                threadAssertTrue(f.result == 21);
490 <                threadAssertTrue(f.isDone());
491 <                threadAssertTrue(getQueuedTaskCount() == 0);
489 >                assertEquals(21, f.result);
490 >                assertEquals(0, getQueuedTaskCount());
491 >                checkCompletedNormally(f);
492              }};
493          testInvokeOnPool(mainPool(), a);
494      }
# Line 234 | Line 498 | public class RecursiveActionTest extends
498       * invoke task throws exception when task completes abnormally
499       */
500      public void testAbnormalInvoke() {
501 <        RecursiveAction a = new RecursiveAction() {
502 <            public void compute() {
501 >        RecursiveAction a = new CheckedRecursiveAction() {
502 >            public void realCompute() {
503 >                FailingFibAction f = new FailingFibAction(8);
504                  try {
240                    FailingFibAction f = new FailingFibAction(8);
505                      f.invoke();
506                      shouldThrow();
507                  } catch (FJException success) {
508 +                    checkCompletedAbnormally(f, success);
509                  }
510              }};
511          testInvokeOnPool(mainPool(), a);
# Line 250 | Line 515 | public class RecursiveActionTest extends
515       * quietlyInvoke task returns when task completes abnormally
516       */
517      public void testAbnormalQuietlyInvoke() {
518 <        RecursiveAction a = new RecursiveAction() {
519 <            public void compute() {
518 >        RecursiveAction a = new CheckedRecursiveAction() {
519 >            public void realCompute() {
520                  FailingFibAction f = new FailingFibAction(8);
521                  f.quietlyInvoke();
522 <                threadAssertTrue(f.isDone());
522 >                assertTrue(f.getException() instanceof FJException);
523 >                checkCompletedAbnormally(f, f.getException());
524              }};
525          testInvokeOnPool(mainPool(), a);
526      }
# Line 263 | Line 529 | public class RecursiveActionTest extends
529       * join of a forked task throws exception when task completes abnormally
530       */
531      public void testAbnormalForkJoin() {
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 >                assertSame(f, f.fork());
536                  try {
269                    FailingFibAction f = new FailingFibAction(8);
270                    f.fork();
537                      f.join();
538                      shouldThrow();
539                  } catch (FJException success) {
540 +                    checkCompletedAbnormally(f, success);
541                  }
542              }};
543          testInvokeOnPool(mainPool(), a);
# Line 280 | Line 547 | public class RecursiveActionTest extends
547       * get of a forked task throws exception when task completes abnormally
548       */
549      public void testAbnormalForkGet() {
550 <        RecursiveAction a = new RecursiveAction() {
551 <            public void compute() {
550 >        RecursiveAction a = new CheckedRecursiveAction() {
551 >            public void realCompute() throws Exception {
552 >                FailingFibAction f = new FailingFibAction(8);
553 >                assertSame(f, f.fork());
554                  try {
286                    FailingFibAction f = new FailingFibAction(8);
287                    f.fork();
555                      f.get();
556                      shouldThrow();
557                  } catch (ExecutionException success) {
558 <                } catch (Exception ex) {
559 <                    unexpectedException(ex);
558 >                    Throwable cause = success.getCause();
559 >                    assertTrue(cause instanceof FJException);
560 >                    checkCompletedAbnormally(f, cause);
561                  }
562              }};
563          testInvokeOnPool(mainPool(), a);
# Line 299 | Line 567 | public class RecursiveActionTest extends
567       * timed get of a forked task throws exception when task completes abnormally
568       */
569      public void testAbnormalForkTimedGet() {
570 <        RecursiveAction a = new RecursiveAction() {
571 <            public void compute() {
570 >        RecursiveAction a = new CheckedRecursiveAction() {
571 >            public void realCompute() throws Exception {
572 >                FailingFibAction f = new FailingFibAction(8);
573 >                assertSame(f, f.fork());
574                  try {
305                    FailingFibAction f = new FailingFibAction(8);
306                    f.fork();
575                      f.get(5L, TimeUnit.SECONDS);
576                      shouldThrow();
577                  } catch (ExecutionException success) {
578 <                } catch (Exception ex) {
579 <                    unexpectedException(ex);
578 >                    Throwable cause = success.getCause();
579 >                    assertTrue(cause instanceof FJException);
580 >                    checkCompletedAbnormally(f, cause);
581                  }
582              }};
583          testInvokeOnPool(mainPool(), a);
# Line 318 | Line 587 | public class RecursiveActionTest extends
587       * quietlyJoin of a forked task returns when task completes abnormally
588       */
589      public void testAbnormalForkQuietlyJoin() {
590 <        RecursiveAction a = new RecursiveAction() {
591 <            public void compute() {
590 >        RecursiveAction a = new CheckedRecursiveAction() {
591 >            public void realCompute() {
592                  FailingFibAction f = new FailingFibAction(8);
593 <                f.fork();
593 >                assertSame(f, f.fork());
594                  f.quietlyJoin();
595 <                threadAssertTrue(f.isDone());
596 <                threadAssertTrue(f.isCompletedAbnormally());
328 <                threadAssertTrue(f.getException() instanceof FJException);
595 >                assertTrue(f.getException() instanceof FJException);
596 >                checkCompletedAbnormally(f, f.getException());
597              }};
598          testInvokeOnPool(mainPool(), a);
599      }
# Line 334 | Line 602 | public class RecursiveActionTest extends
602       * invoke task throws exception when task cancelled
603       */
604      public void testCancelledInvoke() {
605 <        RecursiveAction a = new RecursiveAction() {
606 <            public void compute() {
605 >        RecursiveAction a = new CheckedRecursiveAction() {
606 >            public void realCompute() {
607 >                FibAction f = new FibAction(8);
608 >                assertTrue(f.cancel(true));
609                  try {
340                    FibAction f = new FibAction(8);
341                    f.cancel(true);
610                      f.invoke();
611                      shouldThrow();
612                  } catch (CancellationException success) {
613 +                    checkCancelled(f);
614                  }
615              }};
616          testInvokeOnPool(mainPool(), a);
# Line 351 | Line 620 | public class RecursiveActionTest extends
620       * join of a forked task throws exception when task cancelled
621       */
622      public void testCancelledForkJoin() {
623 <        RecursiveAction a = new RecursiveAction() {
624 <            public void compute() {
623 >        RecursiveAction a = new CheckedRecursiveAction() {
624 >            public void realCompute() {
625 >                FibAction f = new FibAction(8);
626 >                assertTrue(f.cancel(true));
627 >                assertSame(f, f.fork());
628                  try {
357                    FibAction f = new FibAction(8);
358                    f.cancel(true);
359                    f.fork();
629                      f.join();
630                      shouldThrow();
631                  } catch (CancellationException success) {
632 +                    checkCancelled(f);
633                  }
634              }};
635          testInvokeOnPool(mainPool(), a);
# Line 369 | Line 639 | public class RecursiveActionTest extends
639       * get of a forked task throws exception when task cancelled
640       */
641      public void testCancelledForkGet() {
642 <        RecursiveAction a = new RecursiveAction() {
643 <            public void compute() {
642 >        RecursiveAction a = new CheckedRecursiveAction() {
643 >            public void realCompute() throws Exception {
644 >                FibAction f = new FibAction(8);
645 >                assertTrue(f.cancel(true));
646 >                assertSame(f, f.fork());
647                  try {
375                    FibAction f = new FibAction(8);
376                    f.cancel(true);
377                    f.fork();
648                      f.get();
649                      shouldThrow();
650                  } catch (CancellationException success) {
651 <                } catch (Exception ex) {
382 <                    unexpectedException(ex);
651 >                    checkCancelled(f);
652                  }
653              }};
654          testInvokeOnPool(mainPool(), a);
# Line 389 | Line 658 | public class RecursiveActionTest extends
658       * timed get of a forked task throws exception when task cancelled
659       */
660      public void testCancelledForkTimedGet() {
661 <        RecursiveAction a = new RecursiveAction() {
662 <            public void compute() {
661 >        RecursiveAction a = new CheckedRecursiveAction() {
662 >            public void realCompute() throws Exception {
663 >                FibAction f = new FibAction(8);
664 >                assertTrue(f.cancel(true));
665 >                assertSame(f, f.fork());
666                  try {
667 <                    FibAction f = new FibAction(8);
396 <                    f.cancel(true);
397 <                    f.fork();
398 <                    f.get(5L, TimeUnit.SECONDS);
667 >                    f.get(5L, SECONDS);
668                      shouldThrow();
669                  } catch (CancellationException success) {
670 <                } catch (Exception ex) {
402 <                    unexpectedException(ex);
670 >                    checkCancelled(f);
671                  }
672              }};
673          testInvokeOnPool(mainPool(), a);
# Line 409 | Line 677 | public class RecursiveActionTest extends
677       * quietlyJoin of a forked task returns when task cancelled
678       */
679      public void testCancelledForkQuietlyJoin() {
680 <        RecursiveAction a = new RecursiveAction() {
681 <            public void compute() {
680 >        RecursiveAction a = new CheckedRecursiveAction() {
681 >            public void realCompute() {
682                  FibAction f = new FibAction(8);
683 <                f.cancel(true);
684 <                f.fork();
683 >                assertTrue(f.cancel(true));
684 >                assertSame(f, f.fork());
685                  f.quietlyJoin();
686 <                threadAssertTrue(f.isDone());
419 <                threadAssertTrue(f.isCompletedAbnormally());
420 <                threadAssertTrue(f.getException() instanceof CancellationException);
686 >                checkCancelled(f);
687              }};
688          testInvokeOnPool(mainPool(), a);
689      }
# Line 427 | Line 693 | public class RecursiveActionTest extends
693       */
694      public void testGetPool() {
695          final ForkJoinPool mainPool = mainPool();
696 <        RecursiveAction a = new RecursiveAction() {
697 <            public void compute() {
698 <                threadAssertTrue(getPool() == mainPool);
696 >        RecursiveAction a = new CheckedRecursiveAction() {
697 >            public void realCompute() {
698 >                assertSame(mainPool, getPool());
699              }};
700          testInvokeOnPool(mainPool, a);
701      }
# Line 438 | Line 704 | public class RecursiveActionTest extends
704       * getPool of non-FJ task returns null
705       */
706      public void testGetPool2() {
707 <        RecursiveAction a = new RecursiveAction() {
708 <            public void compute() {
709 <                threadAssertTrue(getPool() == null);
707 >        RecursiveAction a = new CheckedRecursiveAction() {
708 >            public void realCompute() {
709 >                assertNull(getPool());
710              }};
711 <        a.invoke();
711 >        assertNull(a.invoke());
712      }
713  
714      /**
715       * inForkJoinPool of executing task returns true
716       */
717      public void testInForkJoinPool() {
718 <        RecursiveAction a = new RecursiveAction() {
719 <            public void compute() {
720 <                threadAssertTrue(inForkJoinPool());
718 >        RecursiveAction a = new CheckedRecursiveAction() {
719 >            public void realCompute() {
720 >                assertTrue(inForkJoinPool());
721              }};
722          testInvokeOnPool(mainPool(), a);
723      }
# Line 460 | Line 726 | public class RecursiveActionTest extends
726       * inForkJoinPool of non-FJ task returns false
727       */
728      public void testInForkJoinPool2() {
729 <        RecursiveAction a = new RecursiveAction() {
730 <            public void compute() {
731 <                threadAssertTrue(!inForkJoinPool());
729 >        RecursiveAction a = new CheckedRecursiveAction() {
730 >            public void realCompute() {
731 >                assertFalse(inForkJoinPool());
732              }};
733 <        a.invoke();
733 >        assertNull(a.invoke());
734      }
735  
736      /**
# Line 472 | Line 738 | public class RecursiveActionTest extends
738       */
739      public void testWorkerGetPool() {
740          final ForkJoinPool mainPool = mainPool();
741 <        RecursiveAction a = new RecursiveAction() {
742 <            public void compute() {
741 >        RecursiveAction a = new CheckedRecursiveAction() {
742 >            public void realCompute() {
743                  ForkJoinWorkerThread w =
744                      (ForkJoinWorkerThread) Thread.currentThread();
745 <                threadAssertTrue(w.getPool() == mainPool);
745 >                assertSame(mainPool, w.getPool());
746              }};
747          testInvokeOnPool(mainPool, a);
748      }
# Line 486 | Line 752 | public class RecursiveActionTest extends
752       */
753      public void testWorkerGetPoolIndex() {
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 <                int idx = w.getPoolIndex();
760 <                threadAssertTrue(idx >= 0);
495 <                threadAssertTrue(idx < mainPool.getPoolSize());
759 >                assertTrue(w.getPoolIndex() >= 0);
760 >                assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
761              }};
762          testInvokeOnPool(mainPool, a);
763      }
# Line 502 | Line 767 | public class RecursiveActionTest extends
767       * setRawResult(null) succeeds
768       */
769      public void testSetRawResult() {
770 <        RecursiveAction a = new RecursiveAction() {
771 <            public void compute() {
770 >        RecursiveAction a = new CheckedRecursiveAction() {
771 >            public void realCompute() {
772                  setRawResult(null);
773 +                assertNull(getRawResult());
774              }};
775 <        a.invoke();
775 >        assertNull(a.invoke());
776      }
777  
778      /**
779       * A reinitialized task may be re-invoked
780       */
781      public void testReinitialize() {
782 <        RecursiveAction a = new RecursiveAction() {
783 <            public void compute() {
782 >        RecursiveAction a = new CheckedRecursiveAction() {
783 >            public void realCompute() {
784                  FibAction f = new FibAction(8);
785 <                f.invoke();
786 <                threadAssertTrue(f.result == 21);
787 <                threadAssertTrue(f.isDone());
788 <                threadAssertFalse(f.isCancelled());
789 <                threadAssertFalse(f.isCompletedAbnormally());
790 <                f.reinitialize();
791 <                f.invoke();
792 <                threadAssertTrue(f.result == 21);
785 >                checkNotDone(f);
786 >
787 >                for (int i = 0; i < 3; i++) {
788 >                    assertNull(f.invoke());
789 >                    assertEquals(21, f.result);
790 >                    checkCompletedNormally(f);
791 >                    f.reinitialize();
792 >                    checkNotDone(f);
793 >                }
794              }};
795          testInvokeOnPool(mainPool(), a);
796      }
# Line 532 | Line 799 | public class RecursiveActionTest extends
799       * invoke task throws exception after invoking completeExceptionally
800       */
801      public void testCompleteExceptionally() {
802 <        RecursiveAction a = new RecursiveAction() {
803 <            public void compute() {
802 >        RecursiveAction a = new CheckedRecursiveAction() {
803 >            public void realCompute() {
804 >                FibAction f = new FibAction(8);
805 >                f.completeExceptionally(new FJException());
806                  try {
538                    FibAction f = new FibAction(8);
539                    f.completeExceptionally(new FJException());
807                      f.invoke();
808                      shouldThrow();
809                  } catch (FJException success) {
810 +                    checkCompletedAbnormally(f, success);
811                  }
812              }};
813          testInvokeOnPool(mainPool(), a);
# Line 549 | Line 817 | public class RecursiveActionTest extends
817       * invoke task suppresses execution invoking complete
818       */
819      public void testComplete() {
820 <        RecursiveAction a = new RecursiveAction() {
821 <            public void compute() {
820 >        RecursiveAction a = new CheckedRecursiveAction() {
821 >            public void realCompute() {
822                  FibAction f = new FibAction(8);
823                  f.complete(null);
824 <                f.invoke();
825 <                threadAssertTrue(f.isDone());
826 <                threadAssertTrue(f.result == 0);
824 >                assertNull(f.invoke());
825 >                assertEquals(0, f.result);
826 >                checkCompletedNormally(f);
827              }};
828          testInvokeOnPool(mainPool(), a);
829      }
# Line 564 | Line 832 | public class RecursiveActionTest extends
832       * invokeAll(t1, t2) invokes all task arguments
833       */
834      public void testInvokeAll2() {
835 <        RecursiveAction a = new RecursiveAction() {
836 <            public void compute() {
835 >        RecursiveAction a = new CheckedRecursiveAction() {
836 >            public void realCompute() {
837                  FibAction f = new FibAction(8);
838                  FibAction g = new FibAction(9);
839                  invokeAll(f, g);
840 <                threadAssertTrue(f.isDone());
841 <                threadAssertTrue(f.result == 21);
842 <                threadAssertTrue(g.isDone());
843 <                threadAssertTrue(g.result == 34);
840 >                checkCompletedNormally(f);
841 >                assertEquals(21, f.result);
842 >                checkCompletedNormally(g);
843 >                assertEquals(34, g.result);
844              }};
845          testInvokeOnPool(mainPool(), a);
846      }
# Line 581 | Line 849 | public class RecursiveActionTest extends
849       * invokeAll(tasks) with 1 argument invokes task
850       */
851      public void testInvokeAll1() {
852 <        RecursiveAction a = new RecursiveAction() {
853 <            public void compute() {
852 >        RecursiveAction a = new CheckedRecursiveAction() {
853 >            public void realCompute() {
854                  FibAction f = new FibAction(8);
855                  invokeAll(f);
856 <                threadAssertTrue(f.isDone());
857 <                threadAssertTrue(f.result == 21);
856 >                checkCompletedNormally(f);
857 >                assertEquals(21, f.result);
858              }};
859          testInvokeOnPool(mainPool(), a);
860      }
# Line 595 | Line 863 | public class RecursiveActionTest extends
863       * invokeAll(tasks) with > 2 argument invokes tasks
864       */
865      public void testInvokeAll3() {
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                  FibAction g = new FibAction(9);
870                  FibAction h = new FibAction(7);
871                  invokeAll(f, g, h);
872 <                threadAssertTrue(f.isDone());
873 <                threadAssertTrue(f.result == 21);
874 <                threadAssertTrue(g.isDone());
875 <                threadAssertTrue(g.result == 34);
876 <                threadAssertTrue(h.isDone());
877 <                threadAssertTrue(h.result == 13);
872 >                assertTrue(f.isDone());
873 >                assertTrue(g.isDone());
874 >                assertTrue(h.isDone());
875 >                checkCompletedNormally(f);
876 >                assertEquals(21, f.result);
877 >                checkCompletedNormally(g);
878 >                assertEquals(34, g.result);
879 >                checkCompletedNormally(g);
880 >                assertEquals(13, h.result);
881              }};
882          testInvokeOnPool(mainPool(), a);
883      }
# Line 615 | Line 886 | public class RecursiveActionTest extends
886       * invokeAll(collection) invokes all tasks in the collection
887       */
888      public void testInvokeAllCollection() {
889 <        RecursiveAction a = new RecursiveAction() {
890 <            public void compute() {
889 >        RecursiveAction a = new CheckedRecursiveAction() {
890 >            public void realCompute() {
891                  FibAction f = new FibAction(8);
892                  FibAction g = new FibAction(9);
893                  FibAction h = new FibAction(7);
# Line 625 | Line 896 | public class RecursiveActionTest extends
896                  set.add(g);
897                  set.add(h);
898                  invokeAll(set);
899 <                threadAssertTrue(f.isDone());
900 <                threadAssertTrue(f.result == 21);
901 <                threadAssertTrue(g.isDone());
902 <                threadAssertTrue(g.result == 34);
903 <                threadAssertTrue(h.isDone());
904 <                threadAssertTrue(h.result == 13);
899 >                assertTrue(f.isDone());
900 >                assertTrue(g.isDone());
901 >                assertTrue(h.isDone());
902 >                checkCompletedNormally(f);
903 >                assertEquals(21, f.result);
904 >                checkCompletedNormally(g);
905 >                assertEquals(34, g.result);
906 >                checkCompletedNormally(g);
907 >                assertEquals(13, h.result);
908              }};
909          testInvokeOnPool(mainPool(), a);
910      }
# Line 640 | Line 914 | public class RecursiveActionTest extends
914       * invokeAll(tasks) with any null task throws NPE
915       */
916      public void testInvokeAllNPE() {
917 <        RecursiveAction a = new RecursiveAction() {
918 <            public void compute() {
917 >        RecursiveAction a = new CheckedRecursiveAction() {
918 >            public void realCompute() {
919 >                FibAction f = new FibAction(8);
920 >                FibAction g = new FibAction(9);
921 >                FibAction h = null;
922                  try {
646                    FibAction f = new FibAction(8);
647                    FibAction g = new FibAction(9);
648                    FibAction h = null;
923                      invokeAll(f, g, h);
924                      shouldThrow();
925 <                } catch (NullPointerException success) {
652 <                }
925 >                } catch (NullPointerException success) {}
926              }};
927          testInvokeOnPool(mainPool(), a);
928      }
# Line 658 | Line 931 | public class RecursiveActionTest extends
931       * invokeAll(t1, t2) throw exception if any task does
932       */
933      public void testAbnormalInvokeAll2() {
934 <        RecursiveAction a = new RecursiveAction() {
935 <            public void compute() {
934 >        RecursiveAction a = new CheckedRecursiveAction() {
935 >            public void realCompute() {
936 >                FibAction f = new FibAction(8);
937 >                FailingFibAction g = new FailingFibAction(9);
938                  try {
664                    FibAction f = new FibAction(8);
665                    FailingFibAction g = new FailingFibAction(9);
939                      invokeAll(f, g);
940                      shouldThrow();
941                  } catch (FJException success) {
942 +                    checkCompletedAbnormally(g, success);
943                  }
944              }};
945          testInvokeOnPool(mainPool(), a);
# Line 675 | Line 949 | public class RecursiveActionTest extends
949       * invokeAll(tasks) with 1 argument throws exception if task does
950       */
951      public void testAbnormalInvokeAll1() {
952 <        RecursiveAction a = new RecursiveAction() {
953 <            public void compute() {
952 >        RecursiveAction a = new CheckedRecursiveAction() {
953 >            public void realCompute() {
954 >                FailingFibAction g = new FailingFibAction(9);
955                  try {
681                    FailingFibAction g = new FailingFibAction(9);
956                      invokeAll(g);
957                      shouldThrow();
958                  } catch (FJException success) {
959 +                    checkCompletedAbnormally(g, success);
960                  }
961              }};
962          testInvokeOnPool(mainPool(), a);
# Line 691 | Line 966 | public class RecursiveActionTest extends
966       * invokeAll(tasks) with > 2 argument throws exception if any task does
967       */
968      public void testAbnormalInvokeAll3() {
969 <        RecursiveAction a = new RecursiveAction() {
970 <            public void compute() {
969 >        RecursiveAction a = new CheckedRecursiveAction() {
970 >            public void realCompute() {
971 >                FibAction f = new FibAction(8);
972 >                FailingFibAction g = new FailingFibAction(9);
973 >                FibAction h = new FibAction(7);
974                  try {
697                    FibAction f = new FibAction(8);
698                    FailingFibAction g = new FailingFibAction(9);
699                    FibAction h = new FibAction(7);
975                      invokeAll(f, g, h);
976                      shouldThrow();
977                  } catch (FJException success) {
978 +                    checkCompletedAbnormally(g, success);
979                  }
980              }};
981          testInvokeOnPool(mainPool(), a);
# Line 709 | Line 985 | public class RecursiveActionTest extends
985       * invokeAll(collection) throws exception if any task does
986       */
987      public void testAbnormalInvokeAllCollection() {
988 <        RecursiveAction a = new RecursiveAction() {
989 <            public void compute() {
988 >        RecursiveAction a = new CheckedRecursiveAction() {
989 >            public void realCompute() {
990 >                FailingFibAction f = new FailingFibAction(8);
991 >                FibAction g = new FibAction(9);
992 >                FibAction h = new FibAction(7);
993 >                HashSet set = new HashSet();
994 >                set.add(f);
995 >                set.add(g);
996 >                set.add(h);
997                  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);
998                      invokeAll(set);
999                      shouldThrow();
1000                  } catch (FJException success) {
1001 +                    checkCompletedAbnormally(f, success);
1002                  }
1003              }};
1004          testInvokeOnPool(mainPool(), a);
# Line 732 | Line 1009 | public class RecursiveActionTest extends
1009       * and suppresses execution
1010       */
1011      public void testTryUnfork() {
1012 <        RecursiveAction a = new RecursiveAction() {
1013 <            public void compute() {
1012 >        RecursiveAction a = new CheckedRecursiveAction() {
1013 >            public void realCompute() {
1014                  FibAction g = new FibAction(9);
1015 <                g.fork();
1015 >                assertSame(g, g.fork());
1016                  FibAction f = new FibAction(8);
1017 <                f.fork();
1018 <                threadAssertTrue(f.tryUnfork());
1017 >                assertSame(f, f.fork());
1018 >                assertTrue(f.tryUnfork());
1019                  helpQuiesce();
1020 <                threadAssertFalse(f.isDone());
1021 <                threadAssertTrue(g.isDone());
1020 >                checkNotDone(f);
1021 >                checkCompletedNormally(g);
1022              }};
1023          testInvokeOnPool(singletonPool(), a);
1024      }
# Line 751 | Line 1028 | public class RecursiveActionTest extends
1028       * there are more tasks than threads
1029       */
1030      public void testGetSurplusQueuedTaskCount() {
1031 <        RecursiveAction a = new RecursiveAction() {
1032 <            public void compute() {
1031 >        RecursiveAction a = new CheckedRecursiveAction() {
1032 >            public void realCompute() {
1033                  FibAction h = new FibAction(7);
1034 <                h.fork();
1034 >                assertSame(h, h.fork());
1035                  FibAction g = new FibAction(9);
1036 <                g.fork();
1036 >                assertSame(g, g.fork());
1037                  FibAction f = new FibAction(8);
1038 <                f.fork();
1039 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
1038 >                assertSame(f, f.fork());
1039 >                assertTrue(getSurplusQueuedTaskCount() > 0);
1040                  helpQuiesce();
1041 +                assertEquals(0, getSurplusQueuedTaskCount());
1042 +                checkCompletedNormally(f);
1043 +                checkCompletedNormally(g);
1044 +                checkCompletedNormally(h);
1045              }};
1046          testInvokeOnPool(singletonPool(), a);
1047      }
# Line 769 | Line 1050 | public class RecursiveActionTest extends
1050       * peekNextLocalTask returns most recent unexecuted task.
1051       */
1052      public void testPeekNextLocalTask() {
1053 <        RecursiveAction a = new RecursiveAction() {
1054 <            public void compute() {
1053 >        RecursiveAction a = new CheckedRecursiveAction() {
1054 >            public void realCompute() {
1055                  FibAction g = new FibAction(9);
1056 <                g.fork();
1056 >                assertSame(g, g.fork());
1057                  FibAction f = new FibAction(8);
1058 <                f.fork();
1059 <                threadAssertTrue(peekNextLocalTask() == f);
1060 <                f.join();
1061 <                threadAssertTrue(f.isDone());
1058 >                assertSame(f, f.fork());
1059 >                assertSame(f, peekNextLocalTask());
1060 >                assertNull(f.join());
1061 >                checkCompletedNormally(f);
1062                  helpQuiesce();
1063 +                checkCompletedNormally(f);
1064 +                checkCompletedNormally(g);
1065              }};
1066          testInvokeOnPool(singletonPool(), a);
1067      }
# Line 788 | Line 1071 | public class RecursiveActionTest extends
1071       * without executing it
1072       */
1073      public void testPollNextLocalTask() {
1074 <        RecursiveAction a = new RecursiveAction() {
1075 <            public void compute() {
1074 >        RecursiveAction a = new CheckedRecursiveAction() {
1075 >            public void realCompute() {
1076                  FibAction g = new FibAction(9);
1077 <                g.fork();
1077 >                assertSame(g, g.fork());
1078                  FibAction f = new FibAction(8);
1079 <                f.fork();
1080 <                threadAssertTrue(pollNextLocalTask() == f);
1079 >                assertSame(f, f.fork());
1080 >                assertSame(f, pollNextLocalTask());
1081                  helpQuiesce();
1082 <                threadAssertFalse(f.isDone());
1082 >                checkNotDone(f);
1083 >                checkCompletedNormally(g);
1084              }};
1085          testInvokeOnPool(singletonPool(), a);
1086      }
1087  
1088      /**
1089 <     * pollTask returns an unexecuted task
806 <     * without executing it
1089 >     * pollTask returns an unexecuted task without executing it
1090       */
1091      public void testPollTask() {
1092 <        RecursiveAction a = new RecursiveAction() {
1093 <            public void compute() {
1092 >        RecursiveAction a = new CheckedRecursiveAction() {
1093 >            public void realCompute() {
1094                  FibAction g = new FibAction(9);
1095 <                g.fork();
1095 >                assertSame(g, g.fork());
1096                  FibAction f = new FibAction(8);
1097 <                f.fork();
1098 <                threadAssertTrue(pollTask() == f);
1097 >                assertSame(f, f.fork());
1098 >                assertSame(f, pollTask());
1099                  helpQuiesce();
1100 <                threadAssertFalse(f.isDone());
1101 <                threadAssertTrue(g.isDone());
1100 >                checkNotDone(f);
1101 >                checkCompletedNormally(g);
1102              }};
1103          testInvokeOnPool(singletonPool(), a);
1104      }
# Line 824 | Line 1107 | public class RecursiveActionTest extends
1107       * peekNextLocalTask returns least recent unexecuted task in async mode
1108       */
1109      public void testPeekNextLocalTaskAsync() {
1110 <        RecursiveAction a = new RecursiveAction() {
1111 <            public void compute() {
1110 >        RecursiveAction a = new CheckedRecursiveAction() {
1111 >            public void realCompute() {
1112                  FibAction g = new FibAction(9);
1113 <                g.fork();
1113 >                assertSame(g, g.fork());
1114                  FibAction f = new FibAction(8);
1115 <                f.fork();
1116 <                threadAssertTrue(peekNextLocalTask() == g);
1117 <                f.join();
1115 >                assertSame(f, f.fork());
1116 >                assertSame(g, peekNextLocalTask());
1117 >                assertNull(f.join());
1118                  helpQuiesce();
1119 <                threadAssertTrue(f.isDone());
1119 >                checkCompletedNormally(f);
1120 >                checkCompletedNormally(g);
1121              }};
1122          testInvokeOnPool(asyncSingletonPool(), a);
1123      }
1124  
1125      /**
1126 <     * pollNextLocalTask returns least recent unexecuted task
1127 <     * without executing it, in async mode
1126 >     * pollNextLocalTask returns least recent unexecuted task without
1127 >     * executing it, in async mode
1128       */
1129      public void testPollNextLocalTaskAsync() {
1130 <        RecursiveAction a = new RecursiveAction() {
1131 <            public void compute() {
1130 >        RecursiveAction a = new CheckedRecursiveAction() {
1131 >            public void realCompute() {
1132                  FibAction g = new FibAction(9);
1133 <                g.fork();
1133 >                assertSame(g, g.fork());
1134                  FibAction f = new FibAction(8);
1135 <                f.fork();
1136 <                threadAssertTrue(pollNextLocalTask() == g);
1135 >                assertSame(f, f.fork());
1136 >                assertSame(g, pollNextLocalTask());
1137                  helpQuiesce();
1138 <                threadAssertTrue(f.isDone());
1139 <                threadAssertFalse(g.isDone());
1138 >                checkCompletedNormally(f);
1139 >                checkNotDone(g);
1140              }};
1141          testInvokeOnPool(asyncSingletonPool(), a);
1142      }
1143  
1144      /**
1145 <     * pollTask returns an unexecuted task
1146 <     * without executing it, in async mode
1145 >     * pollTask returns an unexecuted task without executing it, in
1146 >     * async mode
1147       */
1148      public void testPollTaskAsync() {
1149 <        RecursiveAction a = new RecursiveAction() {
1150 <            public void compute() {
1149 >        RecursiveAction a = new CheckedRecursiveAction() {
1150 >            public void realCompute() {
1151                  FibAction g = new FibAction(9);
1152 <                g.fork();
1152 >                assertSame(g, g.fork());
1153                  FibAction f = new FibAction(8);
1154 <                f.fork();
1155 <                threadAssertTrue(pollTask() == g);
1154 >                assertSame(f, f.fork());
1155 >                assertSame(g, pollTask());
1156                  helpQuiesce();
1157 <                threadAssertTrue(f.isDone());
1158 <                threadAssertFalse(g.isDone());
1157 >                checkCompletedNormally(f);
1158 >                checkNotDone(g);
1159              }};
1160          testInvokeOnPool(asyncSingletonPool(), a);
1161      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines