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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines