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.13 by jsr166, Sat Sep 11 07:31:52 2010 UTC vs.
Revision 1.30 by jsr166, Tue Mar 15 19:47:07 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines