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.5 by jsr166, Tue Aug 4 10:00:15 2009 UTC vs.
Revision 1.12 by jsr166, Sat Sep 11 07:31:52 2010 UTC

# Line 11 | Line 11 | import java.util.*;
11   public class RecursiveTaskTest extends JSR166TestCase {
12  
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16      public static Test suite() {
17 <        return new TestSuite(RecursiveTaskTest.class);
17 >        return new TestSuite(RecursiveTaskTest.class);
18      }
19  
20      static final ForkJoinPool mainPool = new ForkJoinPool();
21      static final ForkJoinPool singletonPool = new ForkJoinPool(1);
22 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
23 <    static {
24 <        asyncSingletonPool.setAsyncMode(true);
25 <    }
22 >    static final ForkJoinPool asyncSingletonPool =
23 >        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
24 >                         null, true);
25  
26      static final class FJException extends RuntimeException {
27          FJException() { super(); }
# Line 65 | Line 64 | public class RecursiveTaskTest extends J
64       * isCompletedAbnormally and isCancelled return false for normally
65       * completed tasks. getRawResult of a completed non-null task
66       * returns value;
68     *
67       */
68      public void testInvoke() {
69          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
70 <                public Integer compute() {
71 <                    FibTask f = new FibTask(8);
72 <                    Integer r = f.invoke();
73 <                    threadAssertTrue(r == 21);
74 <                    threadAssertTrue(f.isDone());
75 <                    threadAssertFalse(f.isCancelled());
76 <                    threadAssertFalse(f.isCompletedAbnormally());
77 <                    threadAssertTrue(f.getRawResult() == 21);
78 <                    return r;
79 <                }
80 <            };
70 >            public Integer compute() {
71 >                FibTask f = new FibTask(8);
72 >                Integer r = f.invoke();
73 >                threadAssertTrue(r == 21);
74 >                threadAssertTrue(f.isDone());
75 >                threadAssertFalse(f.isCancelled());
76 >                threadAssertFalse(f.isCompletedAbnormally());
77 >                threadAssertTrue(f.getRawResult() == 21);
78 >                return r;
79 >            }
80 >        };
81          assertTrue(mainPool.invoke(a) == 21);
82      }
83  
# Line 90 | Line 88 | public class RecursiveTaskTest extends J
88       */
89      public void testQuietlyInvoke() {
90          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
91 <                public Integer compute() {
92 <                    FibTask f = new FibTask(8);
93 <                    f.quietlyInvoke();
94 <                    Integer r = f.getRawResult();
95 <                    threadAssertTrue(r == 21);
96 <                    threadAssertTrue(f.isDone());
97 <                    threadAssertFalse(f.isCancelled());
98 <                    threadAssertFalse(f.isCompletedAbnormally());
99 <                    return r;
100 <                }
101 <            };
91 >            public Integer compute() {
92 >                FibTask f = new FibTask(8);
93 >                f.quietlyInvoke();
94 >                Integer r = f.getRawResult();
95 >                threadAssertTrue(r == 21);
96 >                threadAssertTrue(f.isDone());
97 >                threadAssertFalse(f.isCancelled());
98 >                threadAssertFalse(f.isCompletedAbnormally());
99 >                return r;
100 >            }
101 >        };
102          assertTrue(mainPool.invoke(a) == 21);
103      }
104  
# Line 109 | Line 107 | public class RecursiveTaskTest extends J
107       */
108      public void testForkJoin() {
109          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
110 <                public Integer compute() {
111 <                    FibTask f = new FibTask(8);
112 <                    f.fork();
113 <                    Integer r = f.join();
114 <                    threadAssertTrue(r == 21);
115 <                    threadAssertTrue(f.isDone());
116 <                    return r;
117 <                }
118 <            };
110 >            public Integer compute() {
111 >                FibTask f = new FibTask(8);
112 >                f.fork();
113 >                Integer r = f.join();
114 >                threadAssertTrue(r == 21);
115 >                threadAssertTrue(f.isDone());
116 >                return r;
117 >            }
118 >        };
119          assertTrue(mainPool.invoke(a) == 21);
120      }
121  
# Line 126 | Line 124 | public class RecursiveTaskTest extends J
124       */
125      public void testForkGet() {
126          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
127 <                public Integer compute() {
128 <                    try {
131 <                        FibTask f = new FibTask(8);
132 <                        f.fork();
133 <                        Integer r = f.get();
134 <                        threadAssertTrue(r == 21);
135 <                        threadAssertTrue(f.isDone());
136 <                        return r;
137 <                    } catch (Exception ex) {
138 <                        unexpectedException();
139 <                    }
140 <                    return NoResult;
141 <                }
142 <            };
143 <        assertTrue(mainPool.invoke(a) == 21);
144 <    }
145 <
146 <    /**
147 <     * timed get of a forked task returns when task completes
148 <     */
149 <    public void testForkTimedGet() {
150 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
151 <                public Integer compute() {
152 <                    try {
153 <                        FibTask f = new FibTask(8);
154 <                        f.fork();
155 <                        Integer r = f.get(5L, TimeUnit.SECONDS);
156 <                        threadAssertTrue(r == 21);
157 <                        threadAssertTrue(f.isDone());
158 <                        return r;
159 <                    } catch (Exception ex) {
160 <                        unexpectedException();
161 <                    }
162 <                    return NoResult;
163 <                }
164 <            };
165 <        assertTrue(mainPool.invoke(a) == 21);
166 <    }
167 <
168 <    /**
169 <     * helpJoin of a forked task returns when task completes
170 <     */
171 <    public void testForkHelpJoin() {
172 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
173 <                public Integer compute() {
127 >            public Integer compute() {
128 >                try {
129                      FibTask f = new FibTask(8);
130                      f.fork();
131 <                    Integer r = f.helpJoin();
131 >                    Integer r = f.get();
132                      threadAssertTrue(r == 21);
133                      threadAssertTrue(f.isDone());
134                      return r;
135 +                } catch (Exception ex) {
136 +                    unexpectedException(ex);
137                  }
138 <            };
138 >                return NoResult;
139 >            }
140 >        };
141          assertTrue(mainPool.invoke(a) == 21);
142      }
143  
144      /**
145 <     * quietlyJoin of a forked task returns when task completes
145 >     * timed get of a forked task returns when task completes
146       */
147 <    public void testForkQuietlyJoin() {
147 >    public void testForkTimedGet() {
148          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
149 <                public Integer compute() {
149 >            public Integer compute() {
150 >                try {
151                      FibTask f = new FibTask(8);
152                      f.fork();
153 <                    f.quietlyJoin();
194 <                    Integer r = f.getRawResult();
153 >                    Integer r = f.get(5L, TimeUnit.SECONDS);
154                      threadAssertTrue(r == 21);
155                      threadAssertTrue(f.isDone());
156                      return r;
157 +                } catch (Exception ex) {
158 +                    unexpectedException(ex);
159                  }
160 <            };
160 >                return NoResult;
161 >            }
162 >        };
163          assertTrue(mainPool.invoke(a) == 21);
164      }
165  
203
166      /**
167 <     * quietlyHelpJoin of a forked task returns when task completes
167 >     * quietlyJoin of a forked task returns when task completes
168       */
169 <    public void testForkQuietlyHelpJoin() {
169 >    public void testForkQuietlyJoin() {
170          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
171 <                public Integer compute() {
172 <                    FibTask f = new FibTask(8);
173 <                    f.fork();
174 <                    f.quietlyHelpJoin();
175 <                    Integer r = f.getRawResult();
176 <                    threadAssertTrue(r == 21);
177 <                    threadAssertTrue(f.isDone());
178 <                    return r;
179 <                }
180 <            };
171 >            public Integer compute() {
172 >                FibTask f = new FibTask(8);
173 >                f.fork();
174 >                f.quietlyJoin();
175 >                Integer r = f.getRawResult();
176 >                threadAssertTrue(r == 21);
177 >                threadAssertTrue(f.isDone());
178 >                return r;
179 >            }
180 >        };
181          assertTrue(mainPool.invoke(a) == 21);
182      }
183  
# Line 226 | Line 188 | public class RecursiveTaskTest extends J
188       */
189      public void testForkHelpQuiesce() {
190          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
191 <                public Integer compute() {
192 <                    FibTask f = new FibTask(8);
193 <                    f.fork();
194 <                    f.helpQuiesce();
195 <                    Integer r = f.getRawResult();
196 <                    threadAssertTrue(r == 21);
197 <                    threadAssertTrue(f.isDone());
198 <                    threadAssertTrue(getQueuedTaskCount() == 0);
199 <                    return r;
200 <                }
201 <            };
191 >            public Integer compute() {
192 >                FibTask f = new FibTask(8);
193 >                f.fork();
194 >                f.helpQuiesce();
195 >                Integer r = f.getRawResult();
196 >                threadAssertTrue(r == 21);
197 >                threadAssertTrue(f.isDone());
198 >                threadAssertTrue(getQueuedTaskCount() == 0);
199 >                return r;
200 >            }
201 >        };
202          assertTrue(mainPool.invoke(a) == 21);
203      }
204  
# Line 246 | Line 208 | public class RecursiveTaskTest extends J
208       */
209      public void testAbnormalInvoke() {
210          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
211 <                public Integer compute() {
212 <                    try {
213 <                        FailingFibTask f = new FailingFibTask(8);
214 <                        f.invoke();
215 <                        shouldThrow();
254 <                        return NoResult;
255 <                    } catch (FJException success) {
256 <                    }
211 >            public Integer compute() {
212 >                try {
213 >                    FailingFibTask f = new FailingFibTask(8);
214 >                    f.invoke();
215 >                    shouldThrow();
216                      return NoResult;
217 +                } catch (FJException success) {
218                  }
219 <            };
219 >                return NoResult;
220 >            }
221 >        };
222          mainPool.invoke(a);
223      }
224  
# Line 265 | Line 227 | public class RecursiveTaskTest extends J
227       */
228      public void testAbnormalQuietlyInvoke() {
229          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
230 <                public Integer compute() {
231 <                    FailingFibTask f = new FailingFibTask(8);
232 <                    f.quietlyInvoke();
233 <                    threadAssertTrue(f.isDone());
234 <                    return NoResult;
235 <                }
236 <            };
230 >            public Integer compute() {
231 >                FailingFibTask f = new FailingFibTask(8);
232 >                f.quietlyInvoke();
233 >                threadAssertTrue(f.isDone());
234 >                return NoResult;
235 >            }
236 >        };
237          mainPool.invoke(a);
238      }
239  
# Line 280 | Line 242 | public class RecursiveTaskTest extends J
242       */
243      public void testAbnormalForkJoin() {
244          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
245 <                public Integer compute() {
246 <                    try {
247 <                        FailingFibTask f = new FailingFibTask(8);
248 <                        f.fork();
249 <                        Integer r = f.join();
250 <                        shouldThrow();
251 <                        return r;
252 <                    } catch (FJException success) {
291 <                    }
292 <                    return NoResult;
245 >            public Integer compute() {
246 >                try {
247 >                    FailingFibTask f = new FailingFibTask(8);
248 >                    f.fork();
249 >                    Integer r = f.join();
250 >                    shouldThrow();
251 >                    return r;
252 >                } catch (FJException success) {
253                  }
254 <            };
254 >                return NoResult;
255 >            }
256 >        };
257          mainPool.invoke(a);
258      }
259  
# Line 300 | Line 262 | public class RecursiveTaskTest extends J
262       */
263      public void testAbnormalForkGet() {
264          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
265 <                public Integer compute() {
266 <                    try {
267 <                        FailingFibTask f = new FailingFibTask(8);
268 <                        f.fork();
269 <                        Integer r = f.get();
270 <                        shouldThrow();
271 <                        return r;
272 <                    } catch (ExecutionException success) {
273 <                    } catch (Exception ex) {
274 <                        unexpectedException(ex);
313 <                    }
314 <                    return NoResult;
265 >            public Integer compute() {
266 >                try {
267 >                    FailingFibTask f = new FailingFibTask(8);
268 >                    f.fork();
269 >                    Integer r = f.get();
270 >                    shouldThrow();
271 >                    return r;
272 >                } catch (ExecutionException success) {
273 >                } catch (Exception ex) {
274 >                    unexpectedException(ex);
275                  }
276 <            };
276 >                return NoResult;
277 >            }
278 >        };
279          mainPool.invoke(a);
280      }
281  
# Line 322 | Line 284 | public class RecursiveTaskTest extends J
284       */
285      public void testAbnormalForkTimedGet() {
286          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
287 <                public Integer compute() {
288 <                    try {
327 <                        FailingFibTask f = new FailingFibTask(8);
328 <                        f.fork();
329 <                        Integer r = f.get(5L, TimeUnit.SECONDS);
330 <                        shouldThrow();
331 <                        return r;
332 <                    } catch (ExecutionException success) {
333 <                    } catch (Exception ex) {
334 <                        unexpectedException(ex);
335 <                    }
336 <                    return NoResult;
337 <                }
338 <            };
339 <        mainPool.invoke(a);
340 <    }
341 <
342 <    /**
343 <     * join of a forked task throws exception when task completes abnormally
344 <     */
345 <    public void testAbnormalForkHelpJoin() {
346 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
347 <                public Integer compute() {
348 <                    try {
349 <                        FailingFibTask f = new FailingFibTask(8);
350 <                        f.fork();
351 <                        Integer r = f.helpJoin();
352 <                        shouldThrow();
353 <                        return r;
354 <                    } catch (FJException success) {
355 <                    }
356 <                    return NoResult;
357 <                }
358 <            };
359 <        mainPool.invoke(a);
360 <    }
361 <
362 <    /**
363 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
364 <     * getException of failed task returns its exception.
365 <     * isCompletedAbnormally of a failed task returns true.
366 <     * isCancelled of a failed uncancelled task returns false
367 <     */
368 <    public void testAbnormalForkQuietlyHelpJoin() {
369 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
370 <                public Integer compute() {
287 >            public Integer compute() {
288 >                try {
289                      FailingFibTask f = new FailingFibTask(8);
290                      f.fork();
291 <                    f.quietlyHelpJoin();
292 <                    threadAssertTrue(f.isDone());
293 <                    threadAssertTrue(f.isCompletedAbnormally());
294 <                    threadAssertFalse(f.isCancelled());
295 <                    threadAssertTrue(f.getException() instanceof FJException);
296 <                    return NoResult;
291 >                    Integer r = f.get(5L, TimeUnit.SECONDS);
292 >                    shouldThrow();
293 >                    return r;
294 >                } catch (ExecutionException success) {
295 >                } catch (Exception ex) {
296 >                    unexpectedException(ex);
297                  }
298 <            };
298 >                return NoResult;
299 >            }
300 >        };
301          mainPool.invoke(a);
302      }
303  
# Line 386 | Line 306 | public class RecursiveTaskTest extends J
306       */
307      public void testAbnormalForkQuietlyJoin() {
308          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
309 <                public Integer compute() {
310 <                    FailingFibTask f = new FailingFibTask(8);
311 <                    f.fork();
312 <                    f.quietlyJoin();
313 <                    threadAssertTrue(f.isDone());
314 <                    threadAssertTrue(f.isCompletedAbnormally());
315 <                    threadAssertTrue(f.getException() instanceof FJException);
316 <                    return NoResult;
317 <                }
318 <            };
309 >            public Integer compute() {
310 >                FailingFibTask f = new FailingFibTask(8);
311 >                f.fork();
312 >                f.quietlyJoin();
313 >                threadAssertTrue(f.isDone());
314 >                threadAssertTrue(f.isCompletedAbnormally());
315 >                threadAssertTrue(f.getException() instanceof FJException);
316 >                return NoResult;
317 >            }
318 >        };
319          mainPool.invoke(a);
320      }
321  
# Line 404 | Line 324 | public class RecursiveTaskTest extends J
324       */
325      public void testCancelledInvoke() {
326          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
327 <                public Integer compute() {
328 <                    try {
329 <                        FibTask f = new FibTask(8);
330 <                        f.cancel(true);
331 <                        Integer r = f.invoke();
332 <                        shouldThrow();
333 <                        return r;
334 <                    } catch (CancellationException success) {
415 <                    }
416 <                    return NoResult;
327 >            public Integer compute() {
328 >                try {
329 >                    FibTask f = new FibTask(8);
330 >                    f.cancel(true);
331 >                    Integer r = f.invoke();
332 >                    shouldThrow();
333 >                    return r;
334 >                } catch (CancellationException success) {
335                  }
336 <            };
336 >                return NoResult;
337 >            }
338 >        };
339          mainPool.invoke(a);
340      }
341  
# Line 424 | Line 344 | public class RecursiveTaskTest extends J
344       */
345      public void testCancelledForkJoin() {
346          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
347 <                public Integer compute() {
348 <                    try {
349 <                        FibTask f = new FibTask(8);
350 <                        f.cancel(true);
351 <                        f.fork();
352 <                        Integer r = f.join();
353 <                        shouldThrow();
354 <                        return r;
355 <                    } catch (CancellationException success) {
436 <                    }
437 <                    return NoResult;
347 >            public Integer compute() {
348 >                try {
349 >                    FibTask f = new FibTask(8);
350 >                    f.cancel(true);
351 >                    f.fork();
352 >                    Integer r = f.join();
353 >                    shouldThrow();
354 >                    return r;
355 >                } catch (CancellationException success) {
356                  }
357 <            };
357 >                return NoResult;
358 >            }
359 >        };
360          mainPool.invoke(a);
361      }
362  
# Line 445 | Line 365 | public class RecursiveTaskTest extends J
365       */
366      public void testCancelledForkGet() {
367          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
368 <                public Integer compute() {
369 <                    try {
370 <                        FibTask f = new FibTask(8);
371 <                        f.cancel(true);
372 <                        f.fork();
373 <                        Integer r = f.get();
374 <                        shouldThrow();
375 <                        return r;
376 <                    } catch (CancellationException success) {
377 <                    } catch (Exception ex) {
378 <                        unexpectedException(ex);
459 <                    }
460 <                    return NoResult;
368 >            public Integer compute() {
369 >                try {
370 >                    FibTask f = new FibTask(8);
371 >                    f.cancel(true);
372 >                    f.fork();
373 >                    Integer r = f.get();
374 >                    shouldThrow();
375 >                    return r;
376 >                } catch (CancellationException success) {
377 >                } catch (Exception ex) {
378 >                    unexpectedException(ex);
379                  }
380 <            };
380 >                return NoResult;
381 >            }
382 >        };
383          mainPool.invoke(a);
384      }
385  
# Line 468 | Line 388 | public class RecursiveTaskTest extends J
388       */
389      public void testCancelledForkTimedGet() {
390          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
391 <                public Integer compute() {
392 <                    try {
473 <                        FibTask f = new FibTask(8);
474 <                        f.cancel(true);
475 <                        f.fork();
476 <                        Integer r = f.get(5L, TimeUnit.SECONDS);
477 <                        shouldThrow();
478 <                        return r;
479 <                    } catch (CancellationException success) {
480 <                    } catch (Exception ex) {
481 <                        unexpectedException(ex);
482 <                    }
483 <                    return NoResult;
484 <                }
485 <            };
486 <        mainPool.invoke(a);
487 <    }
488 <
489 <    /**
490 <     * join of a forked task throws exception when task cancelled
491 <     */
492 <    public void testCancelledForkHelpJoin() {
493 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
494 <                public Integer compute() {
495 <                    try {
496 <                        FibTask f = new FibTask(8);
497 <                        f.cancel(true);
498 <                        f.fork();
499 <                        Integer r = f.helpJoin();
500 <                        shouldThrow();
501 <                        return r;
502 <                    } catch (CancellationException success) {
503 <                    }
504 <                    return NoResult;
505 <                }
506 <            };
507 <        mainPool.invoke(a);
508 <    }
509 <
510 <    /**
511 <     * quietlyHelpJoin of a forked task returns when task cancelled.
512 <     * getException of cancelled task returns its exception
513 <     * isCompletedAbnormally of a cancelled task returns true.
514 <     * isCancelled of a cancelled task returns true
515 <     */
516 <    public void testCancelledForkQuietlyHelpJoin() {
517 <        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
518 <                public Integer compute() {
391 >            public Integer compute() {
392 >                try {
393                      FibTask f = new FibTask(8);
394                      f.cancel(true);
395                      f.fork();
396 <                    f.quietlyHelpJoin();
397 <                    threadAssertTrue(f.isDone());
398 <                    threadAssertTrue(f.isCompletedAbnormally());
399 <                    threadAssertTrue(f.isCancelled());
400 <                    threadAssertTrue(f.getException() instanceof CancellationException);
401 <                    return NoResult;
396 >                    Integer r = f.get(5L, TimeUnit.SECONDS);
397 >                    shouldThrow();
398 >                    return r;
399 >                } catch (CancellationException success) {
400 >                } catch (Exception ex) {
401 >                    unexpectedException(ex);
402                  }
403 <            };
403 >                return NoResult;
404 >            }
405 >        };
406          mainPool.invoke(a);
407      }
408  
# Line 535 | Line 411 | public class RecursiveTaskTest extends J
411       */
412      public void testCancelledForkQuietlyJoin() {
413          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
414 <                public Integer compute() {
415 <                    FibTask f = new FibTask(8);
416 <                    f.cancel(true);
417 <                    f.fork();
418 <                    f.quietlyJoin();
419 <                    threadAssertTrue(f.isDone());
420 <                    threadAssertTrue(f.isCompletedAbnormally());
421 <                    threadAssertTrue(f.getException() instanceof CancellationException);
422 <                    return NoResult;
423 <                }
424 <            };
414 >            public Integer compute() {
415 >                FibTask f = new FibTask(8);
416 >                f.cancel(true);
417 >                f.fork();
418 >                f.quietlyJoin();
419 >                threadAssertTrue(f.isDone());
420 >                threadAssertTrue(f.isCompletedAbnormally());
421 >                threadAssertTrue(f.getException() instanceof CancellationException);
422 >                return NoResult;
423 >            }
424 >        };
425          mainPool.invoke(a);
426      }
427  
# Line 554 | Line 430 | public class RecursiveTaskTest extends J
430       */
431      public void testGetPool() {
432          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
433 <                public Integer compute() {
434 <                    threadAssertTrue(getPool() == mainPool);
435 <                    return NoResult;
436 <                }
437 <            };
433 >            public Integer compute() {
434 >                threadAssertTrue(getPool() == mainPool);
435 >                return NoResult;
436 >            }
437 >        };
438          mainPool.invoke(a);
439      }
440  
# Line 580 | Line 456 | public class RecursiveTaskTest extends J
456       */
457      public void testInForkJoinPool() {
458          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
459 <                public Integer compute() {
460 <                    threadAssertTrue(inForkJoinPool());
461 <                    return NoResult;
462 <                }
463 <            };
459 >            public Integer compute() {
460 >                threadAssertTrue(inForkJoinPool());
461 >                return NoResult;
462 >            }
463 >        };
464          mainPool.invoke(a);
465      }
466  
# Line 593 | Line 469 | public class RecursiveTaskTest extends J
469       */
470      public void testInForkJoinPool2() {
471          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
472 <                public Integer compute() {
473 <                    threadAssertTrue(!inForkJoinPool());
474 <                    return NoResult;
475 <                }
476 <            };
472 >            public Integer compute() {
473 >                threadAssertTrue(!inForkJoinPool());
474 >                return NoResult;
475 >            }
476 >        };
477          a.invoke();
478      }
479  
# Line 606 | Line 482 | public class RecursiveTaskTest extends J
482       */
483      public void testSetRawResult() {
484          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
485 <                public Integer compute() {
486 <                    setRawResult(NoResult);
487 <                    return NoResult;
488 <                }
489 <            };
485 >            public Integer compute() {
486 >                setRawResult(NoResult);
487 >                return NoResult;
488 >            }
489 >        };
490          assertEquals(a.invoke(), NoResult);
491      }
492  
# Line 619 | Line 495 | public class RecursiveTaskTest extends J
495       */
496      public void testReinitialize() {
497          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
498 <                public Integer compute() {
499 <                    FibTask f = new FibTask(8);
500 <                    Integer r = f.invoke();
501 <                    threadAssertTrue(r == 21);
502 <                    threadAssertTrue(f.isDone());
503 <                    threadAssertFalse(f.isCancelled());
504 <                    threadAssertFalse(f.isCompletedAbnormally());
505 <                    f.reinitialize();
506 <                    r = f.invoke();
507 <                    threadAssertTrue(r == 21);
508 <                    return NoResult;
509 <                }
510 <            };
498 >            public Integer compute() {
499 >                FibTask f = new FibTask(8);
500 >                Integer r = f.invoke();
501 >                threadAssertTrue(r == 21);
502 >                threadAssertTrue(f.isDone());
503 >                threadAssertFalse(f.isCancelled());
504 >                threadAssertFalse(f.isCompletedAbnormally());
505 >                f.reinitialize();
506 >                r = f.invoke();
507 >                threadAssertTrue(r == 21);
508 >                return NoResult;
509 >            }
510 >        };
511          mainPool.invoke(a);
512      }
513  
# Line 640 | Line 516 | public class RecursiveTaskTest extends J
516       */
517      public void testCompleteExceptionally() {
518          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
519 <                public Integer compute() {
520 <                    try {
521 <                        FibTask f = new FibTask(8);
522 <                        f.completeExceptionally(new FJException());
523 <                        Integer r = f.invoke();
524 <                        shouldThrow();
525 <                        return r;
526 <                    } catch (FJException success) {
651 <                    }
652 <                    return NoResult;
519 >            public Integer compute() {
520 >                try {
521 >                    FibTask f = new FibTask(8);
522 >                    f.completeExceptionally(new FJException());
523 >                    Integer r = f.invoke();
524 >                    shouldThrow();
525 >                    return r;
526 >                } catch (FJException success) {
527                  }
528 <            };
528 >                return NoResult;
529 >            }
530 >        };
531          mainPool.invoke(a);
532      }
533  
# Line 660 | Line 536 | public class RecursiveTaskTest extends J
536       */
537      public void testComplete() {
538          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
539 <                public Integer compute() {
540 <                    FibTask f = new FibTask(8);
541 <                    f.complete(NoResult);
542 <                    Integer r = f.invoke();
543 <                    threadAssertTrue(f.isDone());
544 <                    threadAssertTrue(r == NoResult);
545 <                    return r;
546 <                }
547 <            };
539 >            public Integer compute() {
540 >                FibTask f = new FibTask(8);
541 >                f.complete(NoResult);
542 >                Integer r = f.invoke();
543 >                threadAssertTrue(f.isDone());
544 >                threadAssertTrue(r == NoResult);
545 >                return r;
546 >            }
547 >        };
548          mainPool.invoke(a);
549      }
550  
# Line 677 | Line 553 | public class RecursiveTaskTest extends J
553       */
554      public void testInvokeAll2() {
555          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
556 <                public Integer compute() {
557 <                    FibTask f = new FibTask(8);
558 <                    FibTask g = new FibTask(9);
559 <                    invokeAll(f, g);
560 <                    threadAssertTrue(f.isDone());
561 <                    threadAssertTrue(f.join() == 21);
562 <                    threadAssertTrue(g.isDone());
563 <                    threadAssertTrue(g.join() == 34);
564 <                    return NoResult;
565 <                }
566 <            };
556 >            public Integer compute() {
557 >                FibTask f = new FibTask(8);
558 >                FibTask g = new FibTask(9);
559 >                invokeAll(f, g);
560 >                threadAssertTrue(f.isDone());
561 >                threadAssertTrue(f.join() == 21);
562 >                threadAssertTrue(g.isDone());
563 >                threadAssertTrue(g.join() == 34);
564 >                return NoResult;
565 >            }
566 >        };
567          mainPool.invoke(a);
568      }
569  
# Line 696 | Line 572 | public class RecursiveTaskTest extends J
572       */
573      public void testInvokeAll1() {
574          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
575 <                public Integer compute() {
576 <                    FibTask f = new FibTask(8);
577 <                    invokeAll(f);
578 <                    threadAssertTrue(f.isDone());
579 <                    threadAssertTrue(f.join() == 21);
580 <                    return NoResult;
581 <                }
582 <            };
575 >            public Integer compute() {
576 >                FibTask f = new FibTask(8);
577 >                invokeAll(f);
578 >                threadAssertTrue(f.isDone());
579 >                threadAssertTrue(f.join() == 21);
580 >                return NoResult;
581 >            }
582 >        };
583          mainPool.invoke(a);
584      }
585  
# Line 712 | Line 588 | public class RecursiveTaskTest extends J
588       */
589      public void testInvokeAll3() {
590          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
591 <                public Integer compute() {
592 <                    FibTask f = new FibTask(8);
593 <                    FibTask g = new FibTask(9);
594 <                    FibTask h = new FibTask(7);
595 <                    invokeAll(f, g, h);
596 <                    threadAssertTrue(f.isDone());
597 <                    threadAssertTrue(f.join() == 21);
598 <                    threadAssertTrue(g.isDone());
599 <                    threadAssertTrue(g.join() == 34);
600 <                    threadAssertTrue(h.isDone());
601 <                    threadAssertTrue(h.join() == 13);
602 <                    return NoResult;
603 <                }
604 <            };
591 >            public Integer compute() {
592 >                FibTask f = new FibTask(8);
593 >                FibTask g = new FibTask(9);
594 >                FibTask h = new FibTask(7);
595 >                invokeAll(f, g, h);
596 >                threadAssertTrue(f.isDone());
597 >                threadAssertTrue(f.join() == 21);
598 >                threadAssertTrue(g.isDone());
599 >                threadAssertTrue(g.join() == 34);
600 >                threadAssertTrue(h.isDone());
601 >                threadAssertTrue(h.join() == 13);
602 >                return NoResult;
603 >            }
604 >        };
605          mainPool.invoke(a);
606      }
607  
# Line 734 | Line 610 | public class RecursiveTaskTest extends J
610       */
611      public void testInvokeAllCollection() {
612          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
613 <                public Integer compute() {
614 <                    FibTask f = new FibTask(8);
615 <                    FibTask g = new FibTask(9);
616 <                    FibTask h = new FibTask(7);
617 <                    HashSet set = new HashSet();
618 <                    set.add(f);
619 <                    set.add(g);
620 <                    set.add(h);
621 <                    invokeAll(set);
622 <                    threadAssertTrue(f.isDone());
623 <                    threadAssertTrue(f.join() == 21);
624 <                    threadAssertTrue(g.isDone());
625 <                    threadAssertTrue(g.join() == 34);
626 <                    threadAssertTrue(h.isDone());
627 <                    threadAssertTrue(h.join() == 13);
628 <                    return NoResult;
629 <                }
630 <            };
613 >            public Integer compute() {
614 >                FibTask f = new FibTask(8);
615 >                FibTask g = new FibTask(9);
616 >                FibTask h = new FibTask(7);
617 >                HashSet set = new HashSet();
618 >                set.add(f);
619 >                set.add(g);
620 >                set.add(h);
621 >                invokeAll(set);
622 >                threadAssertTrue(f.isDone());
623 >                threadAssertTrue(f.join() == 21);
624 >                threadAssertTrue(g.isDone());
625 >                threadAssertTrue(g.join() == 34);
626 >                threadAssertTrue(h.isDone());
627 >                threadAssertTrue(h.join() == 13);
628 >                return NoResult;
629 >            }
630 >        };
631          mainPool.invoke(a);
632      }
633  
# Line 761 | Line 637 | public class RecursiveTaskTest extends J
637       */
638      public void testAbnormalInvokeAll2() {
639          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
640 <                public Integer compute() {
641 <                    try {
642 <                        FibTask f = new FibTask(8);
643 <                        FailingFibTask g = new FailingFibTask(9);
644 <                        invokeAll(f, g);
645 <                        shouldThrow();
770 <                        return NoResult;
771 <                    } catch (FJException success) {
772 <                    }
640 >            public Integer compute() {
641 >                try {
642 >                    FibTask f = new FibTask(8);
643 >                    FailingFibTask g = new FailingFibTask(9);
644 >                    invokeAll(f, g);
645 >                    shouldThrow();
646                      return NoResult;
647 +                } catch (FJException success) {
648                  }
649 <            };
649 >                return NoResult;
650 >            }
651 >        };
652          mainPool.invoke(a);
653      }
654  
# Line 781 | Line 657 | public class RecursiveTaskTest extends J
657       */
658      public void testAbnormalInvokeAll1() {
659          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
660 <                public Integer compute() {
661 <                    try {
662 <                        FailingFibTask g = new FailingFibTask(9);
663 <                        invokeAll(g);
664 <                        shouldThrow();
789 <                        return NoResult;
790 <                    } catch (FJException success) {
791 <                    }
660 >            public Integer compute() {
661 >                try {
662 >                    FailingFibTask g = new FailingFibTask(9);
663 >                    invokeAll(g);
664 >                    shouldThrow();
665                      return NoResult;
666 +                } catch (FJException success) {
667                  }
668 <            };
668 >                return NoResult;
669 >            }
670 >        };
671          mainPool.invoke(a);
672      }
673  
# Line 800 | Line 676 | public class RecursiveTaskTest extends J
676       */
677      public void testAbnormalInvokeAll3() {
678          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
679 <                public Integer compute() {
680 <                    try {
681 <                        FibTask f = new FibTask(8);
682 <                        FailingFibTask g = new FailingFibTask(9);
683 <                        FibTask h = new FibTask(7);
684 <                        invokeAll(f, g, h);
685 <                        shouldThrow();
810 <                        return NoResult;
811 <                    } catch (FJException success) {
812 <                    }
679 >            public Integer compute() {
680 >                try {
681 >                    FibTask f = new FibTask(8);
682 >                    FailingFibTask g = new FailingFibTask(9);
683 >                    FibTask h = new FibTask(7);
684 >                    invokeAll(f, g, h);
685 >                    shouldThrow();
686                      return NoResult;
687 +                } catch (FJException success) {
688                  }
689 <            };
689 >                return NoResult;
690 >            }
691 >        };
692          mainPool.invoke(a);
693      }
694  
# Line 821 | Line 697 | public class RecursiveTaskTest extends J
697       */
698      public void testAbnormalInvokeAllCollection() {
699          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
700 <                public Integer compute() {
701 <                    try {
702 <                        FailingFibTask f = new FailingFibTask(8);
703 <                        FibTask g = new FibTask(9);
704 <                        FibTask h = new FibTask(7);
705 <                        HashSet set = new HashSet();
706 <                        set.add(f);
707 <                        set.add(g);
708 <                        set.add(h);
709 <                        invokeAll(set);
710 <                        shouldThrow();
835 <                        return NoResult;
836 <                    } catch (FJException success) {
837 <                    }
700 >            public Integer compute() {
701 >                try {
702 >                    FailingFibTask f = new FailingFibTask(8);
703 >                    FibTask g = new FibTask(9);
704 >                    FibTask h = new FibTask(7);
705 >                    HashSet set = new HashSet();
706 >                    set.add(f);
707 >                    set.add(g);
708 >                    set.add(h);
709 >                    invokeAll(set);
710 >                    shouldThrow();
711                      return NoResult;
712 +                } catch (FJException success) {
713                  }
714 <            };
714 >                return NoResult;
715 >            }
716 >        };
717          mainPool.invoke(a);
718      }
719  
# Line 847 | Line 723 | public class RecursiveTaskTest extends J
723       */
724      public void testTryUnfork() {
725          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
726 <                public Integer compute() {
727 <                    FibTask g = new FibTask(9);
728 <                    g.fork();
729 <                    FibTask f = new FibTask(8);
730 <                    f.fork();
731 <                    threadAssertTrue(f.tryUnfork());
732 <                    helpQuiesce();
733 <                    threadAssertFalse(f.isDone());
734 <                    threadAssertTrue(g.isDone());
735 <                    return NoResult;
736 <                }
737 <            };
726 >            public Integer compute() {
727 >                FibTask g = new FibTask(9);
728 >                g.fork();
729 >                FibTask f = new FibTask(8);
730 >                f.fork();
731 >                threadAssertTrue(f.tryUnfork());
732 >                helpQuiesce();
733 >                threadAssertFalse(f.isDone());
734 >                threadAssertTrue(g.isDone());
735 >                return NoResult;
736 >            }
737 >        };
738          singletonPool.invoke(a);
739      }
740  
# Line 868 | Line 744 | public class RecursiveTaskTest extends J
744       */
745      public void testGetSurplusQueuedTaskCount() {
746          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
747 <                public Integer compute() {
748 <                    FibTask h = new FibTask(7);
749 <                    h.fork();
750 <                    FibTask g = new FibTask(9);
751 <                    g.fork();
752 <                    FibTask f = new FibTask(8);
753 <                    f.fork();
754 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
755 <                    helpQuiesce();
756 <                    return NoResult;
757 <                }
758 <            };
747 >            public Integer compute() {
748 >                FibTask h = new FibTask(7);
749 >                h.fork();
750 >                FibTask g = new FibTask(9);
751 >                g.fork();
752 >                FibTask f = new FibTask(8);
753 >                f.fork();
754 >                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
755 >                helpQuiesce();
756 >                return NoResult;
757 >            }
758 >        };
759          singletonPool.invoke(a);
760      }
761  
# Line 888 | Line 764 | public class RecursiveTaskTest extends J
764       */
765      public void testPeekNextLocalTask() {
766          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
767 <                public Integer compute() {
768 <                    FibTask g = new FibTask(9);
769 <                    g.fork();
770 <                    FibTask f = new FibTask(8);
771 <                    f.fork();
772 <                    threadAssertTrue(peekNextLocalTask() == f);
773 <                    f.join();
774 <                    threadAssertTrue(f.isDone());
775 <                    helpQuiesce();
776 <                    return NoResult;
777 <                }
778 <            };
767 >            public Integer compute() {
768 >                FibTask g = new FibTask(9);
769 >                g.fork();
770 >                FibTask f = new FibTask(8);
771 >                f.fork();
772 >                threadAssertTrue(peekNextLocalTask() == f);
773 >                f.join();
774 >                threadAssertTrue(f.isDone());
775 >                helpQuiesce();
776 >                return NoResult;
777 >            }
778 >        };
779          singletonPool.invoke(a);
780      }
781  
# Line 909 | Line 785 | public class RecursiveTaskTest extends J
785       */
786      public void testPollNextLocalTask() {
787          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
788 <                public Integer compute() {
789 <                    FibTask g = new FibTask(9);
790 <                    g.fork();
791 <                    FibTask f = new FibTask(8);
792 <                    f.fork();
793 <                    threadAssertTrue(pollNextLocalTask() == f);
794 <                    helpQuiesce();
795 <                    threadAssertFalse(f.isDone());
796 <                    return NoResult;
797 <                }
798 <            };
788 >            public Integer compute() {
789 >                FibTask g = new FibTask(9);
790 >                g.fork();
791 >                FibTask f = new FibTask(8);
792 >                f.fork();
793 >                threadAssertTrue(pollNextLocalTask() == f);
794 >                helpQuiesce();
795 >                threadAssertFalse(f.isDone());
796 >                return NoResult;
797 >            }
798 >        };
799          singletonPool.invoke(a);
800      }
801  
# Line 929 | Line 805 | public class RecursiveTaskTest extends J
805       */
806      public void testPollTask() {
807          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
808 <                public Integer compute() {
809 <                    FibTask g = new FibTask(9);
810 <                    g.fork();
811 <                    FibTask f = new FibTask(8);
812 <                    f.fork();
813 <                    threadAssertTrue(pollTask() == f);
814 <                    helpQuiesce();
815 <                    threadAssertFalse(f.isDone());
816 <                    threadAssertTrue(g.isDone());
817 <                    return NoResult;
818 <                }
819 <            };
808 >            public Integer compute() {
809 >                FibTask g = new FibTask(9);
810 >                g.fork();
811 >                FibTask f = new FibTask(8);
812 >                f.fork();
813 >                threadAssertTrue(pollTask() == f);
814 >                helpQuiesce();
815 >                threadAssertFalse(f.isDone());
816 >                threadAssertTrue(g.isDone());
817 >                return NoResult;
818 >            }
819 >        };
820          singletonPool.invoke(a);
821      }
822  
# Line 949 | Line 825 | public class RecursiveTaskTest extends J
825       */
826      public void testPeekNextLocalTaskAsync() {
827          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
828 <                public Integer compute() {
829 <                    FibTask g = new FibTask(9);
830 <                    g.fork();
831 <                    FibTask f = new FibTask(8);
832 <                    f.fork();
833 <                    threadAssertTrue(peekNextLocalTask() == g);
834 <                    f.join();
835 <                    helpQuiesce();
836 <                    threadAssertTrue(f.isDone());
837 <                    return NoResult;
838 <                }
839 <            };
828 >            public Integer compute() {
829 >                FibTask g = new FibTask(9);
830 >                g.fork();
831 >                FibTask f = new FibTask(8);
832 >                f.fork();
833 >                threadAssertTrue(peekNextLocalTask() == g);
834 >                f.join();
835 >                helpQuiesce();
836 >                threadAssertTrue(f.isDone());
837 >                return NoResult;
838 >            }
839 >        };
840          asyncSingletonPool.invoke(a);
841      }
842  
# Line 970 | Line 846 | public class RecursiveTaskTest extends J
846       */
847      public void testPollNextLocalTaskAsync() {
848          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
849 <                public Integer compute() {
850 <                    FibTask g = new FibTask(9);
851 <                    g.fork();
852 <                    FibTask f = new FibTask(8);
853 <                    f.fork();
854 <                    threadAssertTrue(pollNextLocalTask() == g);
855 <                    helpQuiesce();
856 <                    threadAssertTrue(f.isDone());
857 <                    threadAssertFalse(g.isDone());
858 <                    return NoResult;
859 <                }
860 <            };
849 >            public Integer compute() {
850 >                FibTask g = new FibTask(9);
851 >                g.fork();
852 >                FibTask f = new FibTask(8);
853 >                f.fork();
854 >                threadAssertTrue(pollNextLocalTask() == g);
855 >                helpQuiesce();
856 >                threadAssertTrue(f.isDone());
857 >                threadAssertFalse(g.isDone());
858 >                return NoResult;
859 >            }
860 >        };
861          asyncSingletonPool.invoke(a);
862      }
863  
# Line 991 | Line 867 | public class RecursiveTaskTest extends J
867       */
868      public void testPollTaskAsync() {
869          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
870 <                public Integer compute() {
871 <                    FibTask g = new FibTask(9);
872 <                    g.fork();
873 <                    FibTask f = new FibTask(8);
874 <                    f.fork();
875 <                    threadAssertTrue(pollTask() == g);
876 <                    helpQuiesce();
877 <                    threadAssertTrue(f.isDone());
878 <                    threadAssertFalse(g.isDone());
879 <                    return NoResult;
880 <                }
881 <            };
870 >            public Integer compute() {
871 >                FibTask g = new FibTask(9);
872 >                g.fork();
873 >                FibTask f = new FibTask(8);
874 >                f.fork();
875 >                threadAssertTrue(pollTask() == g);
876 >                helpQuiesce();
877 >                threadAssertTrue(f.isDone());
878 >                threadAssertFalse(g.isDone());
879 >                return NoResult;
880 >            }
881 >        };
882          asyncSingletonPool.invoke(a);
883      }
884  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines