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

Comparing jsr166/src/test/tck/RecursiveTaskTest.java (file contents):
Revision 1.13 by jsr166, Mon Sep 13 07:51:18 2010 UTC vs.
Revision 1.29 by jsr166, Sat Jun 18 14:33:38 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  
7   import junit.framework.*;
8 < import java.util.concurrent.*;
9 < import java.util.*;
8 > import java.util.concurrent.CancellationException;
9 > import java.util.concurrent.ExecutionException;
10 > import java.util.concurrent.ForkJoinPool;
11 > import java.util.concurrent.ForkJoinTask;
12 > import java.util.concurrent.ForkJoinWorkerThread;
13 > import java.util.concurrent.RecursiveTask;
14 > import java.util.concurrent.TimeUnit;
15 > import java.util.concurrent.TimeoutException;
16 > import static java.util.concurrent.TimeUnit.SECONDS;
17 > import java.util.HashSet;
18  
19   public class RecursiveTaskTest extends JSR166TestCase {
20  
# Line 33 | Line 41 | public class RecursiveTaskTest extends J
41  
42      private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) {
43          try {
44 <            return pool.invoke(a);
44 >            checkNotDone(a);
45 >
46 >            T result = pool.invoke(a);
47 >
48 >            checkCompletedNormally(a, result);
49 >            return result;
50          } finally {
51              joinPool(pool);
52          }
53      }
54  
55 <    static final class FJException extends RuntimeException {
56 <        FJException() { super(); }
55 >    void checkNotDone(RecursiveTask a) {
56 >        assertFalse(a.isDone());
57 >        assertFalse(a.isCompletedNormally());
58 >        assertFalse(a.isCompletedAbnormally());
59 >        assertFalse(a.isCancelled());
60 >        assertNull(a.getException());
61 >        assertNull(a.getRawResult());
62 >
63 >        if (! ForkJoinTask.inForkJoinPool()) {
64 >            Thread.currentThread().interrupt();
65 >            try {
66 >                a.get();
67 >                shouldThrow();
68 >            } catch (InterruptedException success) {
69 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
70 >
71 >            Thread.currentThread().interrupt();
72 >            try {
73 >                a.get(5L, SECONDS);
74 >                shouldThrow();
75 >            } catch (InterruptedException success) {
76 >            } catch (Throwable fail) { threadUnexpectedException(fail); }
77 >        }
78 >
79 >        try {
80 >            a.get(0L, SECONDS);
81 >            shouldThrow();
82 >        } catch (TimeoutException success) {
83 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
84 >    }
85 >
86 >    <T> void checkCompletedNormally(RecursiveTask<T> a, T expected) {
87 >        assertTrue(a.isDone());
88 >        assertFalse(a.isCancelled());
89 >        assertTrue(a.isCompletedNormally());
90 >        assertFalse(a.isCompletedAbnormally());
91 >        assertNull(a.getException());
92 >        assertSame(expected, a.getRawResult());
93 >        assertSame(expected, a.join());
94 >        assertFalse(a.cancel(false));
95 >        assertFalse(a.cancel(true));
96 >        try {
97 >            assertSame(expected, a.get());
98 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
99 >        try {
100 >            assertSame(expected, a.get(5L, SECONDS));
101 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
102 >    }
103 >
104 >    /**
105 >     * Waits for the task to complete, and checks that when it does,
106 >     * it will have an Integer result equals to the given int.
107 >     */
108 >    void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
109 >        Integer r = a.join();
110 >        assertEquals(expected, (int) r);
111 >        checkCompletedNormally(a, r);
112 >    }
113 >
114 >    /**
115 >     * Like checkCompletesNormally, but verifies that the task has
116 >     * already completed.
117 >     */
118 >    void checkCompletedNormally(RecursiveTask<Integer> a, int expected) {
119 >        Integer r = a.getRawResult();
120 >        assertEquals(expected, (int) r);
121 >        checkCompletedNormally(a, r);
122 >    }
123 >
124 >    void checkCancelled(RecursiveTask a) {
125 >        assertTrue(a.isDone());
126 >        assertTrue(a.isCancelled());
127 >        assertFalse(a.isCompletedNormally());
128 >        assertTrue(a.isCompletedAbnormally());
129 >        assertTrue(a.getException() instanceof CancellationException);
130 >        assertNull(a.getRawResult());
131 >
132 >        try {
133 >            a.join();
134 >            shouldThrow();
135 >        } catch (CancellationException success) {
136 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
137 >
138 >        try {
139 >            a.get();
140 >            shouldThrow();
141 >        } catch (CancellationException success) {
142 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
143 >
144 >        try {
145 >            a.get(5L, SECONDS);
146 >            shouldThrow();
147 >        } catch (CancellationException success) {
148 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
149 >    }
150 >
151 >    void checkCompletedAbnormally(RecursiveTask a, Throwable t) {
152 >        assertTrue(a.isDone());
153 >        assertFalse(a.isCancelled());
154 >        assertFalse(a.isCompletedNormally());
155 >        assertTrue(a.isCompletedAbnormally());
156 >        assertSame(t.getClass(), a.getException().getClass());
157 >        assertNull(a.getRawResult());
158 >        assertFalse(a.cancel(false));
159 >        assertFalse(a.cancel(true));
160 >
161 >        try {
162 >            a.join();
163 >            shouldThrow();
164 >        } catch (Throwable expected) {
165 >            assertSame(t.getClass(), expected.getClass());
166 >        }
167 >
168 >        try {
169 >            a.get();
170 >            shouldThrow();
171 >        } catch (ExecutionException success) {
172 >            assertSame(t.getClass(), success.getCause().getClass());
173 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
174 >
175 >        try {
176 >            a.get(5L, SECONDS);
177 >            shouldThrow();
178 >        } catch (ExecutionException success) {
179 >            assertSame(t.getClass(), success.getCause().getClass());
180 >        } catch (Throwable fail) { threadUnexpectedException(fail); }
181 >    }
182 >
183 >    public static final class FJException extends RuntimeException {
184 >        public FJException() { super(); }
185      }
186  
187      // An invalid return value for Fib
188      static final Integer NoResult = Integer.valueOf(-17);
189  
190      // A simple recursive task for testing
191 <    static final class FibTask extends RecursiveTask<Integer> {
191 >    final class FibTask extends CheckedRecursiveTask<Integer> {
192          final int number;
193          FibTask(int n) { number = n; }
194 <        public Integer compute() {
194 >        public Integer realCompute() {
195              int n = number;
196              if (n <= 1)
197                  return n;
# Line 58 | Line 199 | public class RecursiveTaskTest extends J
199              f1.fork();
200              return (new FibTask(n - 2)).compute() + f1.join();
201          }
202 +
203 +        public void publicSetRawResult(Integer result) {
204 +            setRawResult(result);
205 +        }
206      }
207  
208      // A recursive action failing in base case
209 <    static final class FailingFibTask extends RecursiveTask<Integer> {
209 >    final class FailingFibTask extends RecursiveTask<Integer> {
210          final int number;
211          int result;
212          FailingFibTask(int n) { number = n; }
# Line 82 | Line 227 | public class RecursiveTaskTest extends J
227       * returns value;
228       */
229      public void testInvoke() {
230 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
231 <            public Integer compute() {
230 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
231 >            public Integer realCompute() {
232                  FibTask f = new FibTask(8);
233                  Integer r = f.invoke();
234 <                threadAssertTrue(r == 21);
235 <                threadAssertTrue(f.isDone());
91 <                threadAssertFalse(f.isCancelled());
92 <                threadAssertFalse(f.isCompletedAbnormally());
93 <                threadAssertTrue(f.getRawResult() == 21);
234 >                assertEquals(21, (int) r);
235 >                checkCompletedNormally(f, r);
236                  return r;
237 <            }
96 <        };
237 >            }};
238          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
239      }
240  
# Line 103 | Line 244 | public class RecursiveTaskTest extends J
244       * completed tasks
245       */
246      public void testQuietlyInvoke() {
247 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
248 <            public Integer compute() {
247 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
248 >            public Integer realCompute() {
249                  FibTask f = new FibTask(8);
250                  f.quietlyInvoke();
251 <                Integer r = f.getRawResult();
252 <                threadAssertTrue(r == 21);
253 <                threadAssertTrue(f.isDone());
254 <                threadAssertFalse(f.isCancelled());
114 <                threadAssertFalse(f.isCompletedAbnormally());
115 <                return r;
116 <            }
117 <        };
118 <        assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
251 >                checkCompletedNormally(f, 21);
252 >                return NoResult;
253 >            }};
254 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
255      }
256  
257      /**
258       * join of a forked task returns when task completes
259       */
260      public void testForkJoin() {
261 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
262 <            public Integer compute() {
261 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
262 >            public Integer realCompute() {
263                  FibTask f = new FibTask(8);
264 <                f.fork();
264 >                assertSame(f, f.fork());
265                  Integer r = f.join();
266 <                threadAssertTrue(r == 21);
267 <                threadAssertTrue(f.isDone());
266 >                assertEquals(21, (int) r);
267 >                checkCompletedNormally(f, r);
268                  return r;
269 <            }
134 <        };
269 >            }};
270          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
271      }
272  
# Line 139 | Line 274 | public class RecursiveTaskTest extends J
274       * get of a forked task returns when task completes
275       */
276      public void testForkGet() {
277 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
278 <            public Integer compute() {
279 <                try {
280 <                    FibTask f = new FibTask(8);
281 <                    f.fork();
282 <                    Integer r = f.get();
283 <                    threadAssertTrue(r == 21);
284 <                    threadAssertTrue(f.isDone());
285 <                    return r;
151 <                } catch (Exception ex) {
152 <                    unexpectedException(ex);
153 <                }
154 <                return NoResult;
155 <            }
156 <        };
277 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
278 >            public Integer realCompute() throws Exception {
279 >                FibTask f = new FibTask(8);
280 >                assertSame(f, f.fork());
281 >                Integer r = f.get();
282 >                assertEquals(21, (int) r);
283 >                checkCompletedNormally(f, r);
284 >                return r;
285 >            }};
286          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
287      }
288  
# Line 161 | Line 290 | public class RecursiveTaskTest extends J
290       * timed get of a forked task returns when task completes
291       */
292      public void testForkTimedGet() {
293 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
294 <            public Integer compute() {
295 <                try {
296 <                    FibTask f = new FibTask(8);
297 <                    f.fork();
298 <                    Integer r = f.get(5L, TimeUnit.SECONDS);
299 <                    threadAssertTrue(r == 21);
300 <                    threadAssertTrue(f.isDone());
301 <                    return r;
173 <                } catch (Exception ex) {
174 <                    unexpectedException(ex);
175 <                }
176 <                return NoResult;
177 <            }
178 <        };
293 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
294 >            public Integer realCompute() throws Exception {
295 >                FibTask f = new FibTask(8);
296 >                assertSame(f, f.fork());
297 >                Integer r = f.get(5L, SECONDS);
298 >                assertEquals(21, (int) r);
299 >                checkCompletedNormally(f, r);
300 >                return r;
301 >            }};
302          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
303      }
304  
# Line 183 | Line 306 | public class RecursiveTaskTest extends J
306       * quietlyJoin of a forked task returns when task completes
307       */
308      public void testForkQuietlyJoin() {
309 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
310 <            public Integer compute() {
309 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
310 >            public Integer realCompute() {
311                  FibTask f = new FibTask(8);
312 <                f.fork();
312 >                assertSame(f, f.fork());
313                  f.quietlyJoin();
314                  Integer r = f.getRawResult();
315 <                threadAssertTrue(r == 21);
316 <                threadAssertTrue(f.isDone());
315 >                assertEquals(21, (int) r);
316 >                checkCompletedNormally(f, r);
317                  return r;
318 <            }
196 <        };
318 >            }};
319          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
320      }
321  
200
322      /**
323       * helpQuiesce returns when tasks are complete.
324       * getQueuedTaskCount returns 0 when quiescent
325       */
326      public void testForkHelpQuiesce() {
327 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
328 <            public Integer compute() {
327 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
328 >            public Integer realCompute() {
329                  FibTask f = new FibTask(8);
330 <                f.fork();
331 <                f.helpQuiesce();
332 <                Integer r = f.getRawResult();
333 <                threadAssertTrue(r == 21);
334 <                threadAssertTrue(f.isDone());
335 <                threadAssertTrue(getQueuedTaskCount() == 0);
336 <                return r;
216 <            }
217 <        };
218 <        assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
330 >                assertSame(f, f.fork());
331 >                helpQuiesce();
332 >                assertEquals(0, getQueuedTaskCount());
333 >                checkCompletedNormally(f, 21);
334 >                return NoResult;
335 >            }};
336 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
337      }
338  
221
339      /**
340       * invoke task throws exception when task completes abnormally
341       */
342      public void testAbnormalInvoke() {
343 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
344 <            public Integer compute() {
343 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
344 >            public Integer realCompute() {
345 >                FailingFibTask f = new FailingFibTask(8);
346                  try {
229                    FailingFibTask f = new FailingFibTask(8);
347                      f.invoke();
348                      shouldThrow();
232                    return NoResult;
349                  } catch (FJException success) {
350 +                    checkCompletedAbnormally(f, success);
351                  }
352                  return NoResult;
353 <            }
237 <        };
353 >            }};
354          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
355      }
356  
# Line 242 | Line 358 | public class RecursiveTaskTest extends J
358       * quietlyInvoke task returns when task completes abnormally
359       */
360      public void testAbnormalQuietlyInvoke() {
361 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
362 <            public Integer compute() {
361 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
362 >            public Integer realCompute() {
363                  FailingFibTask f = new FailingFibTask(8);
364                  f.quietlyInvoke();
365 <                threadAssertTrue(f.isDone());
365 >                assertTrue(f.getException() instanceof FJException);
366 >                checkCompletedAbnormally(f, f.getException());
367                  return NoResult;
368 <            }
252 <        };
368 >            }};
369          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
370      }
371  
# Line 257 | Line 373 | public class RecursiveTaskTest extends J
373       * join of a forked task throws exception when task completes abnormally
374       */
375      public void testAbnormalForkJoin() {
376 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
377 <            public Integer compute() {
376 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
377 >            public Integer realCompute() {
378 >                FailingFibTask f = new FailingFibTask(8);
379 >                assertSame(f, f.fork());
380                  try {
263                    FailingFibTask f = new FailingFibTask(8);
264                    f.fork();
381                      Integer r = f.join();
382                      shouldThrow();
267                    return r;
383                  } catch (FJException success) {
384 +                    checkCompletedAbnormally(f, success);
385                  }
386                  return NoResult;
387 <            }
272 <        };
387 >            }};
388          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
389      }
390  
# Line 277 | Line 392 | public class RecursiveTaskTest extends J
392       * get of a forked task throws exception when task completes abnormally
393       */
394      public void testAbnormalForkGet() {
395 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
396 <            public Integer compute() {
395 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
396 >            public Integer realCompute() throws Exception {
397 >                FailingFibTask f = new FailingFibTask(8);
398 >                assertSame(f, f.fork());
399                  try {
283                    FailingFibTask f = new FailingFibTask(8);
284                    f.fork();
400                      Integer r = f.get();
401                      shouldThrow();
287                    return r;
402                  } catch (ExecutionException success) {
403 <                } catch (Exception ex) {
404 <                    unexpectedException(ex);
403 >                    Throwable cause = success.getCause();
404 >                    assertTrue(cause instanceof FJException);
405 >                    checkCompletedAbnormally(f, cause);
406                  }
407                  return NoResult;
408 <            }
294 <        };
408 >            }};
409          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
410      }
411  
# Line 299 | Line 413 | public class RecursiveTaskTest extends J
413       * timed get of a forked task throws exception when task completes abnormally
414       */
415      public void testAbnormalForkTimedGet() {
416 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
417 <            public Integer compute() {
416 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
417 >            public Integer realCompute() throws Exception {
418 >                FailingFibTask f = new FailingFibTask(8);
419 >                assertSame(f, f.fork());
420                  try {
421 <                    FailingFibTask f = new FailingFibTask(8);
306 <                    f.fork();
307 <                    Integer r = f.get(5L, TimeUnit.SECONDS);
421 >                    Integer r = f.get(5L, SECONDS);
422                      shouldThrow();
309                    return r;
423                  } catch (ExecutionException success) {
424 <                } catch (Exception ex) {
425 <                    unexpectedException(ex);
424 >                    Throwable cause = success.getCause();
425 >                    assertTrue(cause instanceof FJException);
426 >                    checkCompletedAbnormally(f, cause);
427                  }
428                  return NoResult;
429 <            }
316 <        };
429 >            }};
430          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
431      }
432  
# Line 321 | Line 434 | public class RecursiveTaskTest extends J
434       * quietlyJoin of a forked task returns when task completes abnormally
435       */
436      public void testAbnormalForkQuietlyJoin() {
437 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
438 <            public Integer compute() {
437 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
438 >            public Integer realCompute() {
439                  FailingFibTask f = new FailingFibTask(8);
440 <                f.fork();
440 >                assertSame(f, f.fork());
441                  f.quietlyJoin();
442 <                threadAssertTrue(f.isDone());
443 <                threadAssertTrue(f.isCompletedAbnormally());
331 <                threadAssertTrue(f.getException() instanceof FJException);
442 >                assertTrue(f.getException() instanceof FJException);
443 >                checkCompletedAbnormally(f, f.getException());
444                  return NoResult;
445 <            }
334 <        };
445 >            }};
446          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
447      }
448  
# Line 339 | Line 450 | public class RecursiveTaskTest extends J
450       * invoke task throws exception when task cancelled
451       */
452      public void testCancelledInvoke() {
453 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
454 <            public Integer compute() {
453 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
454 >            public Integer realCompute() {
455 >                FibTask f = new FibTask(8);
456 >                assertTrue(f.cancel(true));
457                  try {
345                    FibTask f = new FibTask(8);
346                    f.cancel(true);
458                      Integer r = f.invoke();
459                      shouldThrow();
349                    return r;
460                  } catch (CancellationException success) {
461 +                    checkCancelled(f);
462                  }
463                  return NoResult;
464 <            }
354 <        };
464 >            }};
465          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
466      }
467  
# Line 359 | Line 469 | public class RecursiveTaskTest extends J
469       * join of a forked task throws exception when task cancelled
470       */
471      public void testCancelledForkJoin() {
472 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
473 <            public Integer compute() {
472 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
473 >            public Integer realCompute() {
474 >                FibTask f = new FibTask(8);
475 >                assertTrue(f.cancel(true));
476 >                assertSame(f, f.fork());
477                  try {
365                    FibTask f = new FibTask(8);
366                    f.cancel(true);
367                    f.fork();
478                      Integer r = f.join();
479                      shouldThrow();
370                    return r;
480                  } catch (CancellationException success) {
481 +                    checkCancelled(f);
482                  }
483                  return NoResult;
484 <            }
375 <        };
484 >            }};
485          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
486      }
487  
# Line 380 | Line 489 | public class RecursiveTaskTest extends J
489       * get of a forked task throws exception when task cancelled
490       */
491      public void testCancelledForkGet() {
492 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
493 <            public Integer compute() {
492 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
493 >            public Integer realCompute() throws Exception {
494 >                FibTask f = new FibTask(8);
495 >                assertTrue(f.cancel(true));
496 >                assertSame(f, f.fork());
497                  try {
386                    FibTask f = new FibTask(8);
387                    f.cancel(true);
388                    f.fork();
498                      Integer r = f.get();
499                      shouldThrow();
391                    return r;
500                  } catch (CancellationException success) {
501 <                } catch (Exception ex) {
394 <                    unexpectedException(ex);
501 >                    checkCancelled(f);
502                  }
503                  return NoResult;
504 <            }
398 <        };
504 >            }};
505          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
506      }
507  
# Line 403 | Line 509 | public class RecursiveTaskTest extends J
509       * timed get of a forked task throws exception when task cancelled
510       */
511      public void testCancelledForkTimedGet() {
512 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
513 <            public Integer compute() {
512 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
513 >            public Integer realCompute() throws Exception {
514 >                FibTask f = new FibTask(8);
515 >                assertTrue(f.cancel(true));
516 >                assertSame(f, f.fork());
517                  try {
518 <                    FibTask f = new FibTask(8);
410 <                    f.cancel(true);
411 <                    f.fork();
412 <                    Integer r = f.get(5L, TimeUnit.SECONDS);
518 >                    Integer r = f.get(5L, SECONDS);
519                      shouldThrow();
414                    return r;
520                  } catch (CancellationException success) {
521 <                } catch (Exception ex) {
417 <                    unexpectedException(ex);
521 >                    checkCancelled(f);
522                  }
523                  return NoResult;
524 <            }
421 <        };
524 >            }};
525          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
526      }
527  
# Line 426 | Line 529 | public class RecursiveTaskTest extends J
529       * quietlyJoin of a forked task returns when task cancelled
530       */
531      public void testCancelledForkQuietlyJoin() {
532 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
533 <            public Integer compute() {
532 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
533 >            public Integer realCompute() {
534                  FibTask f = new FibTask(8);
535 <                f.cancel(true);
536 <                f.fork();
535 >                assertTrue(f.cancel(true));
536 >                assertSame(f, f.fork());
537                  f.quietlyJoin();
538 <                threadAssertTrue(f.isDone());
436 <                threadAssertTrue(f.isCompletedAbnormally());
437 <                threadAssertTrue(f.getException() instanceof CancellationException);
538 >                checkCancelled(f);
539                  return NoResult;
540 <            }
440 <        };
540 >            }};
541          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
542      }
543  
# Line 446 | Line 546 | public class RecursiveTaskTest extends J
546       */
547      public void testGetPool() {
548          final ForkJoinPool mainPool = mainPool();
549 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
550 <            public Integer compute() {
551 <                threadAssertTrue(getPool() == mainPool);
549 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
550 >            public Integer realCompute() {
551 >                assertSame(mainPool, getPool());
552                  return NoResult;
553 <            }
454 <        };
553 >            }};
554          assertSame(NoResult, testInvokeOnPool(mainPool, a));
555      }
556  
# Line 459 | Line 558 | public class RecursiveTaskTest extends J
558       * getPool of non-FJ task returns null
559       */
560      public void testGetPool2() {
561 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
562 <            public Integer compute() {
563 <                threadAssertTrue(getPool() == null);
561 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
562 >            public Integer realCompute() {
563 >                assertNull(getPool());
564                  return NoResult;
565 <            }
566 <        };
468 <        a.invoke();
565 >            }};
566 >        assertSame(NoResult, a.invoke());
567      }
568  
569      /**
570       * inForkJoinPool of executing task returns true
571       */
572      public void testInForkJoinPool() {
573 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
574 <            public Integer compute() {
575 <                threadAssertTrue(inForkJoinPool());
573 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
574 >            public Integer realCompute() {
575 >                assertTrue(inForkJoinPool());
576                  return NoResult;
577 <            }
480 <        };
577 >            }};
578          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
579      }
580  
# Line 485 | Line 582 | public class RecursiveTaskTest extends J
582       * inForkJoinPool of non-FJ task returns false
583       */
584      public void testInForkJoinPool2() {
585 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
586 <            public Integer compute() {
587 <                threadAssertTrue(!inForkJoinPool());
585 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
586 >            public Integer realCompute() {
587 >                assertFalse(inForkJoinPool());
588                  return NoResult;
589 <            }
590 <        };
494 <        a.invoke();
589 >            }};
590 >        assertSame(NoResult, a.invoke());
591      }
592  
593      /**
594 <     * setRawResult(null) succeeds
594 >     * The value set by setRawResult is returned by getRawResult
595       */
596      public void testSetRawResult() {
597 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
598 <            public Integer compute() {
597 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
598 >            public Integer realCompute() {
599                  setRawResult(NoResult);
600 +                assertSame(NoResult, getRawResult());
601                  return NoResult;
602              }
603          };
# Line 508 | Line 605 | public class RecursiveTaskTest extends J
605      }
606  
607      /**
608 <     * A reinitialized task may be re-invoked
608 >     * A reinitialized normally completed task may be re-invoked
609       */
610      public void testReinitialize() {
611 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
612 <            public Integer compute() {
611 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
612 >            public Integer realCompute() {
613                  FibTask f = new FibTask(8);
614 <                Integer r = f.invoke();
615 <                threadAssertTrue(r == 21);
616 <                threadAssertTrue(f.isDone());
617 <                threadAssertFalse(f.isCancelled());
618 <                threadAssertFalse(f.isCompletedAbnormally());
619 <                f.reinitialize();
620 <                r = f.invoke();
621 <                threadAssertTrue(r == 21);
614 >                checkNotDone(f);
615 >
616 >                for (int i = 0; i < 3; i++) {
617 >                    Integer r = f.invoke();
618 >                    assertEquals(21, (int) r);
619 >                    checkCompletedNormally(f, r);
620 >                    f.reinitialize();
621 >                    f.publicSetRawResult(null);
622 >                    checkNotDone(f);
623 >                }
624                  return NoResult;
625 <            }
626 <        };
625 >            }};
626 >        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
627 >    }
628 >
629 >    /**
630 >     * A reinitialized abnormally completed task may be re-invoked
631 >     */
632 >    public void testReinitializeAbnormal() {
633 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
634 >            public Integer realCompute() {
635 >                FailingFibTask f = new FailingFibTask(8);
636 >                checkNotDone(f);
637 >
638 >                for (int i = 0; i < 3; i++) {
639 >                    try {
640 >                        f.invoke();
641 >                        shouldThrow();
642 >                    } catch (FJException success) {
643 >                        checkCompletedAbnormally(f, success);
644 >                    }
645 >                    f.reinitialize();
646 >                    checkNotDone(f);
647 >                }
648 >                return NoResult;
649 >            }};
650          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
651      }
652  
# Line 532 | Line 654 | public class RecursiveTaskTest extends J
654       * invoke task throws exception after invoking completeExceptionally
655       */
656      public void testCompleteExceptionally() {
657 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
658 <            public Integer compute() {
657 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
658 >            public Integer realCompute() {
659 >                FibTask f = new FibTask(8);
660 >                f.completeExceptionally(new FJException());
661                  try {
538                    FibTask f = new FibTask(8);
539                    f.completeExceptionally(new FJException());
662                      Integer r = f.invoke();
663                      shouldThrow();
542                    return r;
664                  } catch (FJException success) {
665 +                    checkCompletedAbnormally(f, success);
666                  }
667                  return NoResult;
668 <            }
547 <        };
668 >            }};
669          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
670      }
671  
# Line 552 | Line 673 | public class RecursiveTaskTest extends J
673       * invoke task suppresses execution invoking complete
674       */
675      public void testComplete() {
676 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
677 <            public Integer compute() {
676 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
677 >            public Integer realCompute() {
678                  FibTask f = new FibTask(8);
679                  f.complete(NoResult);
680                  Integer r = f.invoke();
681 <                threadAssertTrue(f.isDone());
682 <                threadAssertTrue(r == NoResult);
681 >                assertSame(NoResult, r);
682 >                checkCompletedNormally(f, NoResult);
683                  return r;
684 <            }
564 <        };
684 >            }};
685          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
686      }
687  
# Line 569 | Line 689 | public class RecursiveTaskTest extends J
689       * invokeAll(t1, t2) invokes all task arguments
690       */
691      public void testInvokeAll2() {
692 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
693 <            public Integer compute() {
692 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
693 >            public Integer realCompute() {
694                  FibTask f = new FibTask(8);
695                  FibTask g = new FibTask(9);
696                  invokeAll(f, g);
697 <                threadAssertTrue(f.isDone());
698 <                threadAssertTrue(f.join() == 21);
579 <                threadAssertTrue(g.isDone());
580 <                threadAssertTrue(g.join() == 34);
697 >                checkCompletedNormally(f, 21);
698 >                checkCompletedNormally(g, 34);
699                  return NoResult;
700 <            }
583 <        };
700 >            }};
701          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
702      }
703  
# Line 588 | Line 705 | public class RecursiveTaskTest extends J
705       * invokeAll(tasks) with 1 argument invokes task
706       */
707      public void testInvokeAll1() {
708 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
709 <            public Integer compute() {
708 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
709 >            public Integer realCompute() {
710                  FibTask f = new FibTask(8);
711                  invokeAll(f);
712 <                threadAssertTrue(f.isDone());
596 <                threadAssertTrue(f.join() == 21);
712 >                checkCompletedNormally(f, 21);
713                  return NoResult;
714 <            }
599 <        };
714 >            }};
715          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
716      }
717  
# Line 604 | Line 719 | public class RecursiveTaskTest extends J
719       * invokeAll(tasks) with > 2 argument invokes tasks
720       */
721      public void testInvokeAll3() {
722 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
723 <            public Integer compute() {
722 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
723 >            public Integer realCompute() {
724                  FibTask f = new FibTask(8);
725                  FibTask g = new FibTask(9);
726                  FibTask h = new FibTask(7);
727                  invokeAll(f, g, h);
728 <                threadAssertTrue(f.isDone());
729 <                threadAssertTrue(f.join() == 21);
730 <                threadAssertTrue(g.isDone());
731 <                threadAssertTrue(g.join() == 34);
732 <                threadAssertTrue(h.isDone());
733 <                threadAssertTrue(h.join() == 13);
728 >                assertTrue(f.isDone());
729 >                assertTrue(g.isDone());
730 >                assertTrue(h.isDone());
731 >                checkCompletedNormally(f, 21);
732 >                checkCompletedNormally(g, 34);
733 >                checkCompletedNormally(h, 13);
734                  return NoResult;
735 <            }
621 <        };
735 >            }};
736          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
737      }
738  
# Line 626 | Line 740 | public class RecursiveTaskTest extends J
740       * invokeAll(collection) invokes all tasks in the collection
741       */
742      public void testInvokeAllCollection() {
743 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
744 <            public Integer compute() {
743 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
744 >            public Integer realCompute() {
745                  FibTask f = new FibTask(8);
746                  FibTask g = new FibTask(9);
747                  FibTask h = new FibTask(7);
# Line 636 | Line 750 | public class RecursiveTaskTest extends J
750                  set.add(g);
751                  set.add(h);
752                  invokeAll(set);
753 <                threadAssertTrue(f.isDone());
754 <                threadAssertTrue(f.join() == 21);
755 <                threadAssertTrue(g.isDone());
756 <                threadAssertTrue(g.join() == 34);
757 <                threadAssertTrue(h.isDone());
758 <                threadAssertTrue(h.join() == 13);
753 >                assertTrue(f.isDone());
754 >                assertTrue(g.isDone());
755 >                assertTrue(h.isDone());
756 >                checkCompletedNormally(f, 21);
757 >                checkCompletedNormally(g, 34);
758 >                checkCompletedNormally(h, 13);
759                  return NoResult;
760 <            }
647 <        };
760 >            }};
761          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
762      }
763  
764 +    /**
765 +     * invokeAll(tasks) with any null task throws NPE
766 +     */
767 +    public void testInvokeAllNPE() {
768 +        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
769 +            public Integer realCompute() {
770 +                FibTask f = new FibTask(8);
771 +                FibTask g = new FibTask(9);
772 +                FibTask h = null;
773 +                try {
774 +                    invokeAll(f, g, h);
775 +                    shouldThrow();
776 +                } catch (NullPointerException success) {}
777 +                return NoResult;
778 +            }};
779 +        assertSame(NoResult, testInvokeOnPool(mainPool(), a));
780 +    }
781  
782      /**
783       * invokeAll(t1, t2) throw exception if any task does
784       */
785      public void testAbnormalInvokeAll2() {
786 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
787 <            public Integer compute() {
786 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
787 >            public Integer realCompute() {
788 >                FibTask f = new FibTask(8);
789 >                FailingFibTask g = new FailingFibTask(9);
790                  try {
659                    FibTask f = new FibTask(8);
660                    FailingFibTask g = new FailingFibTask(9);
791                      invokeAll(f, g);
792                      shouldThrow();
663                    return NoResult;
793                  } catch (FJException success) {
794 +                    checkCompletedAbnormally(g, success);
795                  }
796                  return NoResult;
797 <            }
668 <        };
797 >            }};
798          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
799      }
800  
# Line 673 | Line 802 | public class RecursiveTaskTest extends J
802       * invokeAll(tasks) with 1 argument throws exception if task does
803       */
804      public void testAbnormalInvokeAll1() {
805 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
806 <            public Integer compute() {
805 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
806 >            public Integer realCompute() {
807 >                FailingFibTask g = new FailingFibTask(9);
808                  try {
679                    FailingFibTask g = new FailingFibTask(9);
809                      invokeAll(g);
810                      shouldThrow();
682                    return NoResult;
811                  } catch (FJException success) {
812 +                    checkCompletedAbnormally(g, success);
813                  }
814                  return NoResult;
815 <            }
687 <        };
815 >            }};
816          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
817      }
818  
# Line 692 | Line 820 | public class RecursiveTaskTest extends J
820       * invokeAll(tasks) with > 2 argument throws exception if any task does
821       */
822      public void testAbnormalInvokeAll3() {
823 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
824 <            public Integer compute() {
823 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
824 >            public Integer realCompute() {
825 >                FibTask f = new FibTask(8);
826 >                FailingFibTask g = new FailingFibTask(9);
827 >                FibTask h = new FibTask(7);
828                  try {
698                    FibTask f = new FibTask(8);
699                    FailingFibTask g = new FailingFibTask(9);
700                    FibTask h = new FibTask(7);
829                      invokeAll(f, g, h);
830                      shouldThrow();
703                    return NoResult;
831                  } catch (FJException success) {
832 +                    checkCompletedAbnormally(g, success);
833                  }
834                  return NoResult;
835 <            }
708 <        };
835 >            }};
836          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
837      }
838  
# Line 713 | Line 840 | public class RecursiveTaskTest extends J
840       * invokeAll(collection) throws exception if any task does
841       */
842      public void testAbnormalInvokeAllCollection() {
843 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
844 <            public Integer compute() {
843 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
844 >            public Integer realCompute() {
845 >                FailingFibTask f = new FailingFibTask(8);
846 >                FibTask g = new FibTask(9);
847 >                FibTask h = new FibTask(7);
848 >                HashSet set = new HashSet();
849 >                set.add(f);
850 >                set.add(g);
851 >                set.add(h);
852                  try {
719                    FailingFibTask f = new FailingFibTask(8);
720                    FibTask g = new FibTask(9);
721                    FibTask h = new FibTask(7);
722                    HashSet set = new HashSet();
723                    set.add(f);
724                    set.add(g);
725                    set.add(h);
853                      invokeAll(set);
854                      shouldThrow();
728                    return NoResult;
855                  } catch (FJException success) {
856 +                    checkCompletedAbnormally(f, success);
857                  }
858                  return NoResult;
859 <            }
733 <        };
859 >            }};
860          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
861      }
862  
# Line 739 | Line 865 | public class RecursiveTaskTest extends J
865       * and suppresses execution
866       */
867      public void testTryUnfork() {
868 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
869 <            public Integer compute() {
868 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
869 >            public Integer realCompute() {
870                  FibTask g = new FibTask(9);
871 <                g.fork();
871 >                assertSame(g, g.fork());
872                  FibTask f = new FibTask(8);
873 <                f.fork();
874 <                threadAssertTrue(f.tryUnfork());
873 >                assertSame(f, f.fork());
874 >                assertTrue(f.tryUnfork());
875                  helpQuiesce();
876 <                threadAssertFalse(f.isDone());
877 <                threadAssertTrue(g.isDone());
876 >                checkNotDone(f);
877 >                checkCompletedNormally(g, 34);
878                  return NoResult;
879 <            }
754 <        };
879 >            }};
880          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
881      }
882  
# Line 760 | Line 885 | public class RecursiveTaskTest extends J
885       * there are more tasks than threads
886       */
887      public void testGetSurplusQueuedTaskCount() {
888 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
889 <            public Integer compute() {
888 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
889 >            public Integer realCompute() {
890                  FibTask h = new FibTask(7);
891 <                h.fork();
891 >                assertSame(h, h.fork());
892                  FibTask g = new FibTask(9);
893 <                g.fork();
893 >                assertSame(g, g.fork());
894                  FibTask f = new FibTask(8);
895 <                f.fork();
896 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
895 >                assertSame(f, f.fork());
896 >                assertTrue(getSurplusQueuedTaskCount() > 0);
897                  helpQuiesce();
898 +                assertEquals(0, getSurplusQueuedTaskCount());
899 +                checkCompletedNormally(f, 21);
900 +                checkCompletedNormally(g, 34);
901 +                checkCompletedNormally(h, 13);
902                  return NoResult;
903 <            }
775 <        };
903 >            }};
904          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
905      }
906  
# Line 780 | Line 908 | public class RecursiveTaskTest extends J
908       * peekNextLocalTask returns most recent unexecuted task.
909       */
910      public void testPeekNextLocalTask() {
911 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
912 <            public Integer compute() {
911 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
912 >            public Integer realCompute() {
913                  FibTask g = new FibTask(9);
914 <                g.fork();
914 >                assertSame(g, g.fork());
915                  FibTask f = new FibTask(8);
916 <                f.fork();
917 <                threadAssertTrue(peekNextLocalTask() == f);
918 <                f.join();
791 <                threadAssertTrue(f.isDone());
916 >                assertSame(f, f.fork());
917 >                assertSame(f, peekNextLocalTask());
918 >                checkCompletesNormally(f, 21);
919                  helpQuiesce();
920 +                checkCompletedNormally(g, 34);
921                  return NoResult;
922 <            }
795 <        };
922 >            }};
923          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
924      }
925  
# Line 801 | Line 928 | public class RecursiveTaskTest extends J
928       * without executing it
929       */
930      public void testPollNextLocalTask() {
931 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
932 <            public Integer compute() {
931 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
932 >            public Integer realCompute() {
933                  FibTask g = new FibTask(9);
934 <                g.fork();
934 >                assertSame(g, g.fork());
935                  FibTask f = new FibTask(8);
936 <                f.fork();
937 <                threadAssertTrue(pollNextLocalTask() == f);
936 >                assertSame(f, f.fork());
937 >                assertSame(f, pollNextLocalTask());
938                  helpQuiesce();
939 <                threadAssertFalse(f.isDone());
939 >                checkNotDone(f);
940 >                checkCompletedNormally(g, 34);
941                  return NoResult;
942 <            }
815 <        };
942 >            }};
943          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
944      }
945  
# Line 820 | Line 947 | public class RecursiveTaskTest extends J
947       * pollTask returns an unexecuted task without executing it
948       */
949      public void testPollTask() {
950 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
951 <            public Integer compute() {
950 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
951 >            public Integer realCompute() {
952                  FibTask g = new FibTask(9);
953 <                g.fork();
953 >                assertSame(g, g.fork());
954                  FibTask f = new FibTask(8);
955 <                f.fork();
956 <                threadAssertTrue(pollTask() == f);
955 >                assertSame(f, f.fork());
956 >                assertSame(f, pollTask());
957                  helpQuiesce();
958 <                threadAssertFalse(f.isDone());
959 <                threadAssertTrue(g.isDone());
958 >                checkNotDone(f);
959 >                checkCompletedNormally(g, 34);
960                  return NoResult;
961 <            }
835 <        };
961 >            }};
962          assertSame(NoResult, testInvokeOnPool(singletonPool(), a));
963      }
964  
# Line 840 | Line 966 | public class RecursiveTaskTest extends J
966       * peekNextLocalTask returns least recent unexecuted task in async mode
967       */
968      public void testPeekNextLocalTaskAsync() {
969 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
970 <            public Integer compute() {
969 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
970 >            public Integer realCompute() {
971                  FibTask g = new FibTask(9);
972 <                g.fork();
972 >                assertSame(g, g.fork());
973                  FibTask f = new FibTask(8);
974 <                f.fork();
975 <                threadAssertTrue(peekNextLocalTask() == g);
976 <                f.join();
974 >                assertSame(f, f.fork());
975 >                assertSame(g, peekNextLocalTask());
976 >                assertEquals(21, (int) f.join());
977                  helpQuiesce();
978 <                threadAssertTrue(f.isDone());
978 >                checkCompletedNormally(f, 21);
979 >                checkCompletedNormally(g, 34);
980                  return NoResult;
981 <            }
855 <        };
981 >            }};
982          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
983      }
984  
985      /**
986 <     * pollNextLocalTask returns least recent unexecuted task
987 <     * without executing it, in async mode
986 >     * pollNextLocalTask returns least recent unexecuted task without
987 >     * executing it, in async mode
988       */
989      public void testPollNextLocalTaskAsync() {
990 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
991 <            public Integer compute() {
990 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
991 >            public Integer realCompute() {
992                  FibTask g = new FibTask(9);
993 <                g.fork();
993 >                assertSame(g, g.fork());
994                  FibTask f = new FibTask(8);
995 <                f.fork();
996 <                threadAssertTrue(pollNextLocalTask() == g);
995 >                assertSame(f, f.fork());
996 >                assertSame(g, pollNextLocalTask());
997                  helpQuiesce();
998 <                threadAssertTrue(f.isDone());
999 <                threadAssertFalse(g.isDone());
998 >                checkCompletedNormally(f, 21);
999 >                checkNotDone(g);
1000                  return NoResult;
1001 <            }
876 <        };
1001 >            }};
1002          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
1003      }
1004  
1005      /**
1006 <     * pollTask returns an unexecuted task
1007 <     * without executing it, in async mode
1006 >     * pollTask returns an unexecuted task without executing it, in
1007 >     * async mode
1008       */
1009      public void testPollTaskAsync() {
1010 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
1011 <            public Integer compute() {
1010 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
1011 >            public Integer realCompute() {
1012                  FibTask g = new FibTask(9);
1013 <                g.fork();
1013 >                assertSame(g, g.fork());
1014                  FibTask f = new FibTask(8);
1015 <                f.fork();
1016 <                threadAssertTrue(pollTask() == g);
1015 >                assertSame(f, f.fork());
1016 >                assertSame(g, pollTask());
1017                  helpQuiesce();
1018 <                threadAssertTrue(f.isDone());
1019 <                threadAssertFalse(g.isDone());
1018 >                checkCompletedNormally(f, 21);
1019 >                checkNotDone(g);
1020                  return NoResult;
1021 <            }
897 <        };
1021 >            }};
1022          assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a));
1023      }
1024  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines