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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.4 by jsr166, Tue Aug 4 09:35:31 2009 UTC vs.
Revision 1.13 by jsr166, Mon Sep 13 07:26:30 2010 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5   */
6 < import junit.framework.*;
7 < import java.util.concurrent.*;
6 > import java.util.concurrent.ExecutionException;
7 > import java.util.concurrent.CancellationException;
8 > import java.util.concurrent.ForkJoinPool;
9 > import java.util.concurrent.ForkJoinTask;
10 > import java.util.concurrent.ForkJoinWorkerThread;
11 > import java.util.concurrent.RecursiveAction;
12 > import java.util.concurrent.TimeUnit;
13   import java.util.concurrent.atomic.*;
14   import java.util.*;
15 + import junit.framework.*;
16  
17   public class ForkJoinTaskTest extends JSR166TestCase {
18  
19      public static void main(String[] args) {
20 <        junit.textui.TestRunner.run (suite());
20 >        junit.textui.TestRunner.run(suite());
21      }
22 +
23      public static Test suite() {
24 <        return new TestSuite(ForkJoinTaskTest.class);
24 >        return new TestSuite(ForkJoinTaskTest.class);
25      }
26  
27      /**
# Line 27 | Line 34 | public class ForkJoinTaskTest extends JS
34  
35      static final ForkJoinPool mainPool = new ForkJoinPool();
36      static final ForkJoinPool singletonPool = new ForkJoinPool(1);
37 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
38 <    static {
39 <        asyncSingletonPool.setAsyncMode(true);
33 <    }
34 <
37 >    static final ForkJoinPool asyncSingletonPool =
38 >        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
39 >                         null, true);
40      static final class FJException extends RuntimeException {
41          FJException() { super(); }
42      }
# Line 148 | Line 153 | public class ForkJoinTaskTest extends JS
153  
154      }
155  
156 <    static final class AsyncFib  extends BinaryAsyncAction {
156 >    static final class AsyncFib extends BinaryAsyncAction {
157          int number;
158          public AsyncFib(int n) {
159              this.number = n;
# Line 177 | Line 182 | public class ForkJoinTaskTest extends JS
182      }
183  
184  
185 <    static final class FailingAsyncFib  extends BinaryAsyncAction {
185 >    static final class FailingAsyncFib extends BinaryAsyncAction {
186          int number;
187          public FailingAsyncFib(int n) {
188              this.number = n;
# Line 209 | Line 214 | public class ForkJoinTaskTest extends JS
214       * invoke returns when task completes normally.
215       * isCompletedAbnormally and isCancelled return false for normally
216       * completed tasks. getRawResult of a RecursiveAction returns null;
212     *
217       */
218      public void testInvoke() {
219          RecursiveAction a = new RecursiveAction() {
220 <                public void compute() {
221 <                    AsyncFib f = new AsyncFib(8);
222 <                    f.invoke();
223 <                    threadAssertTrue(f.number == 21);
224 <                    threadAssertTrue(f.isDone());
225 <                    threadAssertFalse(f.isCancelled());
226 <                    threadAssertFalse(f.isCompletedAbnormally());
227 <                    threadAssertTrue(f.getRawResult() == null);
228 <                }
225 <            };
220 >            public void compute() {
221 >                AsyncFib f = new AsyncFib(8);
222 >                f.invoke();
223 >                threadAssertTrue(f.number == 21);
224 >                threadAssertTrue(f.isDone());
225 >                threadAssertFalse(f.isCancelled());
226 >                threadAssertFalse(f.isCompletedAbnormally());
227 >                threadAssertTrue(f.getRawResult() == null);
228 >            }};
229          mainPool.invoke(a);
230      }
231  
# Line 233 | Line 236 | public class ForkJoinTaskTest extends JS
236       */
237      public void testQuietlyInvoke() {
238          RecursiveAction a = new RecursiveAction() {
239 <                public void compute() {
240 <                    AsyncFib f = new AsyncFib(8);
241 <                    f.quietlyInvoke();
242 <                    threadAssertTrue(f.number == 21);
243 <                    threadAssertTrue(f.isDone());
244 <                    threadAssertFalse(f.isCancelled());
245 <                    threadAssertFalse(f.isCompletedAbnormally());
246 <                    threadAssertTrue(f.getRawResult() == null);
247 <                }
245 <            };
239 >            public void compute() {
240 >                AsyncFib f = new AsyncFib(8);
241 >                f.quietlyInvoke();
242 >                threadAssertTrue(f.number == 21);
243 >                threadAssertTrue(f.isDone());
244 >                threadAssertFalse(f.isCancelled());
245 >                threadAssertFalse(f.isCompletedAbnormally());
246 >                threadAssertTrue(f.getRawResult() == null);
247 >            }};
248          mainPool.invoke(a);
249      }
250  
# Line 251 | Line 253 | public class ForkJoinTaskTest extends JS
253       */
254      public void testForkJoin() {
255          RecursiveAction a = new RecursiveAction() {
256 <                public void compute() {
257 <                    AsyncFib f = new AsyncFib(8);
258 <                    f.fork();
259 <                    f.join();
260 <                    threadAssertTrue(f.number == 21);
261 <                    threadAssertTrue(f.isDone());
262 <                    threadAssertTrue(f.getRawResult() == null);
263 <                }
262 <            };
256 >            public void compute() {
257 >                AsyncFib f = new AsyncFib(8);
258 >                f.fork();
259 >                f.join();
260 >                threadAssertTrue(f.number == 21);
261 >                threadAssertTrue(f.isDone());
262 >                threadAssertTrue(f.getRawResult() == null);
263 >            }};
264          mainPool.invoke(a);
265      }
266  
# Line 268 | Line 269 | public class ForkJoinTaskTest extends JS
269       */
270      public void testForkGet() {
271          RecursiveAction a = new RecursiveAction() {
272 <                public void compute() {
273 <                    try {
274 <                        AsyncFib f = new AsyncFib(8);
275 <                        f.fork();
276 <                        f.get();
277 <                        threadAssertTrue(f.number == 21);
278 <                        threadAssertTrue(f.isDone());
279 <                    } catch (Exception ex) {
280 <                        unexpectedException(ex);
280 <                    }
272 >            public void compute() {
273 >                try {
274 >                    AsyncFib f = new AsyncFib(8);
275 >                    f.fork();
276 >                    f.get();
277 >                    threadAssertTrue(f.number == 21);
278 >                    threadAssertTrue(f.isDone());
279 >                } catch (Exception ex) {
280 >                    unexpectedException(ex);
281                  }
282 <            };
282 >            }};
283          mainPool.invoke(a);
284      }
285  
# Line 288 | Line 288 | public class ForkJoinTaskTest extends JS
288       */
289      public void testForkTimedGet() {
290          RecursiveAction a = new RecursiveAction() {
291 <                public void compute() {
292 <                    try {
293 <                        AsyncFib f = new AsyncFib(8);
294 <                        f.fork();
295 <                        f.get(5L, TimeUnit.SECONDS);
296 <                        threadAssertTrue(f.number == 21);
297 <                        threadAssertTrue(f.isDone());
298 <                    } catch (Exception ex) {
299 <                        unexpectedException(ex);
300 <                    }
301 <                }
302 <            };
303 <        mainPool.invoke(a);
304 <    }
305 <
306 <    /**
307 <     * timed get with null time unit throws NPE
308 <     */
309 <    public void testForkTimedGetNPE() {
310 <        RecursiveAction a = new RecursiveAction() {
311 <                public void compute() {
312 <                    try {
313 <                        AsyncFib f = new AsyncFib(8);
314 <                        f.fork();
315 <                        f.get(5L, null);
316 <                        shouldThrow();
317 <                    } catch (NullPointerException success) {
318 <                    } catch (Exception ex) {
319 <                        unexpectedException(ex);
320 <                    }
321 <                }
322 <            };
323 <        mainPool.invoke(a);
324 <    }
325 <
326 <    /**
327 <     * helpJoin of a forked task returns when task completes
328 <     */
329 <    public void testForkHelpJoin() {
330 <        RecursiveAction a = new RecursiveAction() {
331 <                public void compute() {
291 >            public void compute() {
292 >                try {
293                      AsyncFib f = new AsyncFib(8);
294                      f.fork();
295 <                    f.helpJoin();
295 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
296                      threadAssertTrue(f.number == 21);
297                      threadAssertTrue(f.isDone());
298 +                } catch (Exception ex) {
299 +                    unexpectedException(ex);
300                  }
301 <            };
301 >            }};
302          mainPool.invoke(a);
303      }
304  
305      /**
306 <     * quietlyJoin of a forked task returns when task completes
306 >     * timed get with null time unit throws NPE
307       */
308 <    public void testForkQuietlyJoin() {
308 >    public void testForkTimedGetNPE() {
309          RecursiveAction a = new RecursiveAction() {
310 <                public void compute() {
310 >            public void compute() {
311 >                try {
312                      AsyncFib f = new AsyncFib(8);
313                      f.fork();
314 <                    f.quietlyJoin();
315 <                    threadAssertTrue(f.number == 21);
316 <                    threadAssertTrue(f.isDone());
314 >                    f.get(5L, null);
315 >                    shouldThrow();
316 >                } catch (NullPointerException success) {
317 >                } catch (Exception ex) {
318 >                    unexpectedException(ex);
319                  }
320 <            };
320 >            }};
321          mainPool.invoke(a);
322      }
323  
358
324      /**
325 <     * quietlyHelpJoin of a forked task returns when task completes
325 >     * quietlyJoin of a forked task returns when task completes
326       */
327 <    public void testForkQuietlyHelpJoin() {
327 >    public void testForkQuietlyJoin() {
328          RecursiveAction a = new RecursiveAction() {
329 <                public void compute() {
330 <                    AsyncFib f = new AsyncFib(8);
331 <                    f.fork();
332 <                    f.quietlyHelpJoin();
333 <                    threadAssertTrue(f.number == 21);
334 <                    threadAssertTrue(f.isDone());
335 <                }
371 <            };
329 >            public void compute() {
330 >                AsyncFib f = new AsyncFib(8);
331 >                f.fork();
332 >                f.quietlyJoin();
333 >                threadAssertTrue(f.number == 21);
334 >                threadAssertTrue(f.isDone());
335 >            }};
336          mainPool.invoke(a);
337      }
338  
# Line 379 | Line 343 | public class ForkJoinTaskTest extends JS
343       */
344      public void testForkHelpQuiesce() {
345          RecursiveAction a = new RecursiveAction() {
346 <                public void compute() {
347 <                    AsyncFib f = new AsyncFib(8);
348 <                    f.fork();
349 <                    f.helpQuiesce();
350 <                    threadAssertTrue(f.number == 21);
351 <                    threadAssertTrue(f.isDone());
352 <                    threadAssertTrue(getQueuedTaskCount() == 0);
353 <                }
390 <            };
346 >            public void compute() {
347 >                AsyncFib f = new AsyncFib(8);
348 >                f.fork();
349 >                f.helpQuiesce();
350 >                threadAssertTrue(f.number == 21);
351 >                threadAssertTrue(f.isDone());
352 >                threadAssertTrue(getQueuedTaskCount() == 0);
353 >            }};
354          mainPool.invoke(a);
355      }
356  
# Line 397 | Line 360 | public class ForkJoinTaskTest extends JS
360       */
361      public void testAbnormalInvoke() {
362          RecursiveAction a = new RecursiveAction() {
363 <                public void compute() {
364 <                    try {
365 <                        FailingAsyncFib f = new FailingAsyncFib(8);
366 <                        f.invoke();
367 <                        shouldThrow();
368 <                    } catch (FJException success) {
406 <                    }
363 >            public void compute() {
364 >                try {
365 >                    FailingAsyncFib f = new FailingAsyncFib(8);
366 >                    f.invoke();
367 >                    shouldThrow();
368 >                } catch (FJException success) {
369                  }
370 <            };
370 >            }};
371          mainPool.invoke(a);
372      }
373  
# Line 414 | Line 376 | public class ForkJoinTaskTest extends JS
376       */
377      public void testAbnormalQuietlyInvoke() {
378          RecursiveAction a = new RecursiveAction() {
379 <                public void compute() {
380 <                    FailingAsyncFib f = new FailingAsyncFib(8);
381 <                    f.quietlyInvoke();
382 <                    threadAssertTrue(f.isDone());
383 <                }
422 <            };
379 >            public void compute() {
380 >                FailingAsyncFib f = new FailingAsyncFib(8);
381 >                f.quietlyInvoke();
382 >                threadAssertTrue(f.isDone());
383 >            }};
384          mainPool.invoke(a);
385      }
386  
# Line 428 | Line 389 | public class ForkJoinTaskTest extends JS
389       */
390      public void testAbnormalForkJoin() {
391          RecursiveAction a = new RecursiveAction() {
392 <                public void compute() {
393 <                    try {
394 <                        FailingAsyncFib f = new FailingAsyncFib(8);
395 <                        f.fork();
396 <                        f.join();
397 <                        shouldThrow();
398 <                    } catch (FJException success) {
438 <                    }
392 >            public void compute() {
393 >                try {
394 >                    FailingAsyncFib f = new FailingAsyncFib(8);
395 >                    f.fork();
396 >                    f.join();
397 >                    shouldThrow();
398 >                } catch (FJException success) {
399                  }
400 <            };
400 >            }};
401          mainPool.invoke(a);
402      }
403  
# Line 446 | Line 406 | public class ForkJoinTaskTest extends JS
406       */
407      public void testAbnormalForkGet() {
408          RecursiveAction a = new RecursiveAction() {
409 <                public void compute() {
410 <                    try {
411 <                        FailingAsyncFib f = new FailingAsyncFib(8);
412 <                        f.fork();
413 <                        f.get();
414 <                        shouldThrow();
415 <                    } catch (ExecutionException success) {
416 <                    } catch (Exception ex) {
417 <                        unexpectedException(ex);
458 <                    }
409 >            public void compute() {
410 >                try {
411 >                    FailingAsyncFib f = new FailingAsyncFib(8);
412 >                    f.fork();
413 >                    f.get();
414 >                    shouldThrow();
415 >                } catch (ExecutionException success) {
416 >                } catch (Exception ex) {
417 >                    unexpectedException(ex);
418                  }
419 <            };
419 >            }};
420          mainPool.invoke(a);
421      }
422  
# Line 466 | Line 425 | public class ForkJoinTaskTest extends JS
425       */
426      public void testAbnormalForkTimedGet() {
427          RecursiveAction a = new RecursiveAction() {
428 <                public void compute() {
429 <                    try {
471 <                        FailingAsyncFib f = new FailingAsyncFib(8);
472 <                        f.fork();
473 <                        f.get(5L, TimeUnit.SECONDS);
474 <                        shouldThrow();
475 <                    } catch (ExecutionException success) {
476 <                    } catch (Exception ex) {
477 <                        unexpectedException(ex);
478 <                    }
479 <                }
480 <            };
481 <        mainPool.invoke(a);
482 <    }
483 <
484 <    /**
485 <     * join of a forked task throws exception when task completes abnormally
486 <     */
487 <    public void testAbnormalForkHelpJoin() {
488 <        RecursiveAction a = new RecursiveAction() {
489 <                public void compute() {
490 <                    try {
491 <                        FailingAsyncFib f = new FailingAsyncFib(8);
492 <                        f.fork();
493 <                        f.helpJoin();
494 <                        shouldThrow();
495 <                    } catch (FJException success) {
496 <                    }
497 <                }
498 <            };
499 <        mainPool.invoke(a);
500 <    }
501 <
502 <    /**
503 <     * quietlyHelpJoin of a forked task returns when task completes abnormally.
504 <     * getException of failed task returns its exception.
505 <     * isCompletedAbnormally of a failed task returns true.
506 <     * isCancelled of a failed uncancelled task returns false
507 <     */
508 <    public void testAbnormalForkQuietlyHelpJoin() {
509 <        RecursiveAction a = new RecursiveAction() {
510 <                public void compute() {
428 >            public void compute() {
429 >                try {
430                      FailingAsyncFib f = new FailingAsyncFib(8);
431                      f.fork();
432 <                    f.quietlyHelpJoin();
433 <                    threadAssertTrue(f.isDone());
434 <                    threadAssertTrue(f.isCompletedAbnormally());
435 <                    threadAssertFalse(f.isCancelled());
436 <                    threadAssertTrue(f.getException() instanceof FJException);
432 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
433 >                    shouldThrow();
434 >                } catch (ExecutionException success) {
435 >                } catch (Exception ex) {
436 >                    unexpectedException(ex);
437                  }
438 <            };
438 >            }};
439          mainPool.invoke(a);
440      }
441  
# Line 525 | Line 444 | public class ForkJoinTaskTest extends JS
444       */
445      public void testAbnormalForkQuietlyJoin() {
446          RecursiveAction a = new RecursiveAction() {
447 <                public void compute() {
448 <                    FailingAsyncFib f = new FailingAsyncFib(8);
449 <                    f.fork();
450 <                    f.quietlyJoin();
451 <                    threadAssertTrue(f.isDone());
452 <                    threadAssertTrue(f.isCompletedAbnormally());
453 <                    threadAssertTrue(f.getException() instanceof FJException);
454 <                }
536 <            };
447 >            public void compute() {
448 >                FailingAsyncFib f = new FailingAsyncFib(8);
449 >                f.fork();
450 >                f.quietlyJoin();
451 >                threadAssertTrue(f.isDone());
452 >                threadAssertTrue(f.isCompletedAbnormally());
453 >                threadAssertTrue(f.getException() instanceof FJException);
454 >            }};
455          mainPool.invoke(a);
456      }
457  
# Line 542 | Line 460 | public class ForkJoinTaskTest extends JS
460       */
461      public void testCancelledInvoke() {
462          RecursiveAction a = new RecursiveAction() {
463 <                public void compute() {
464 <                    try {
465 <                        AsyncFib f = new AsyncFib(8);
466 <                        f.cancel(true);
467 <                        f.invoke();
468 <                        shouldThrow();
469 <                    } catch (CancellationException success) {
552 <                    }
463 >            public void compute() {
464 >                try {
465 >                    AsyncFib f = new AsyncFib(8);
466 >                    f.cancel(true);
467 >                    f.invoke();
468 >                    shouldThrow();
469 >                } catch (CancellationException success) {
470                  }
471 <            };
471 >            }};
472          mainPool.invoke(a);
473      }
474  
# Line 560 | Line 477 | public class ForkJoinTaskTest extends JS
477       */
478      public void testCancelledForkJoin() {
479          RecursiveAction a = new RecursiveAction() {
480 <                public void compute() {
481 <                    try {
482 <                        AsyncFib f = new AsyncFib(8);
483 <                        f.cancel(true);
484 <                        f.fork();
485 <                        f.join();
486 <                        shouldThrow();
487 <                    } catch (CancellationException success) {
571 <                    }
480 >            public void compute() {
481 >                try {
482 >                    AsyncFib f = new AsyncFib(8);
483 >                    f.cancel(true);
484 >                    f.fork();
485 >                    f.join();
486 >                    shouldThrow();
487 >                } catch (CancellationException success) {
488                  }
489 <            };
489 >            }};
490          mainPool.invoke(a);
491      }
492  
# Line 579 | Line 495 | public class ForkJoinTaskTest extends JS
495       */
496      public void testCancelledForkGet() {
497          RecursiveAction a = new RecursiveAction() {
498 <                public void compute() {
499 <                    try {
500 <                        AsyncFib f = new AsyncFib(8);
501 <                        f.cancel(true);
502 <                        f.fork();
503 <                        f.get();
504 <                        shouldThrow();
505 <                    } catch (CancellationException success) {
506 <                    } catch (Exception ex) {
507 <                        unexpectedException(ex);
592 <                    }
498 >            public void compute() {
499 >                try {
500 >                    AsyncFib f = new AsyncFib(8);
501 >                    f.cancel(true);
502 >                    f.fork();
503 >                    f.get();
504 >                    shouldThrow();
505 >                } catch (CancellationException success) {
506 >                } catch (Exception ex) {
507 >                    unexpectedException(ex);
508                  }
509 <            };
509 >            }};
510          mainPool.invoke(a);
511      }
512  
# Line 600 | Line 515 | public class ForkJoinTaskTest extends JS
515       */
516      public void testCancelledForkTimedGet() {
517          RecursiveAction a = new RecursiveAction() {
518 <                public void compute() {
519 <                    try {
605 <                        AsyncFib f = new AsyncFib(8);
606 <                        f.cancel(true);
607 <                        f.fork();
608 <                        f.get(5L, TimeUnit.SECONDS);
609 <                        shouldThrow();
610 <                    } catch (CancellationException success) {
611 <                    } catch (Exception ex) {
612 <                        unexpectedException(ex);
613 <                    }
614 <                }
615 <            };
616 <        mainPool.invoke(a);
617 <    }
618 <
619 <    /**
620 <     * join of a forked task throws exception when task cancelled
621 <     */
622 <    public void testCancelledForkHelpJoin() {
623 <        RecursiveAction a = new RecursiveAction() {
624 <                public void compute() {
625 <                    try {
626 <                        AsyncFib f = new AsyncFib(8);
627 <                        f.cancel(true);
628 <                        f.fork();
629 <                        f.helpJoin();
630 <                        shouldThrow();
631 <                    } catch (CancellationException success) {
632 <                    }
633 <                }
634 <            };
635 <        mainPool.invoke(a);
636 <    }
637 <
638 <    /**
639 <     * quietlyHelpJoin of a forked task returns when task cancelled.
640 <     * getException of cancelled task returns its exception.
641 <     * isCompletedAbnormally of a cancelled task returns true.
642 <     * isCancelled of a cancelled task returns true
643 <     */
644 <    public void testCancelledForkQuietlyHelpJoin() {
645 <        RecursiveAction a = new RecursiveAction() {
646 <                public void compute() {
518 >            public void compute() {
519 >                try {
520                      AsyncFib f = new AsyncFib(8);
521                      f.cancel(true);
522                      f.fork();
523 <                    f.quietlyHelpJoin();
524 <                    threadAssertTrue(f.isDone());
525 <                    threadAssertTrue(f.isCompletedAbnormally());
526 <                    threadAssertTrue(f.isCancelled());
527 <                    threadAssertTrue(f.getException() instanceof CancellationException);
523 >                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
524 >                    shouldThrow();
525 >                } catch (CancellationException success) {
526 >                } catch (Exception ex) {
527 >                    unexpectedException(ex);
528                  }
529 <            };
529 >            }};
530          mainPool.invoke(a);
531      }
532  
# Line 662 | Line 535 | public class ForkJoinTaskTest extends JS
535       */
536      public void testCancelledForkQuietlyJoin() {
537          RecursiveAction a = new RecursiveAction() {
538 <                public void compute() {
539 <                    AsyncFib f = new AsyncFib(8);
540 <                    f.cancel(true);
541 <                    f.fork();
542 <                    f.quietlyJoin();
543 <                    threadAssertTrue(f.isDone());
544 <                    threadAssertTrue(f.isCompletedAbnormally());
545 <                    threadAssertTrue(f.getException() instanceof CancellationException);
546 <                }
674 <            };
538 >            public void compute() {
539 >                AsyncFib f = new AsyncFib(8);
540 >                f.cancel(true);
541 >                f.fork();
542 >                f.quietlyJoin();
543 >                threadAssertTrue(f.isDone());
544 >                threadAssertTrue(f.isCompletedAbnormally());
545 >                threadAssertTrue(f.getException() instanceof CancellationException);
546 >            }};
547          mainPool.invoke(a);
548      }
549  
# Line 680 | Line 552 | public class ForkJoinTaskTest extends JS
552       */
553      public void testGetPool() {
554          RecursiveAction a = new RecursiveAction() {
555 <                public void compute() {
556 <                    threadAssertTrue(getPool() == mainPool);
557 <                }
686 <            };
555 >            public void compute() {
556 >                threadAssertTrue(getPool() == mainPool);
557 >            }};
558          mainPool.invoke(a);
559      }
560  
# Line 692 | Line 563 | public class ForkJoinTaskTest extends JS
563       */
564      public void testGetPool2() {
565          RecursiveAction a = new RecursiveAction() {
566 <                public void compute() {
567 <                    threadAssertTrue(getPool() == null);
568 <                }
698 <            };
566 >            public void compute() {
567 >                threadAssertTrue(getPool() == null);
568 >            }};
569          a.invoke();
570      }
571  
# Line 704 | Line 574 | public class ForkJoinTaskTest extends JS
574       */
575      public void testInForkJoinPool() {
576          RecursiveAction a = new RecursiveAction() {
577 <                public void compute() {
578 <                    threadAssertTrue(inForkJoinPool());
579 <                }
710 <            };
577 >            public void compute() {
578 >                threadAssertTrue(inForkJoinPool());
579 >            }};
580          mainPool.invoke(a);
581      }
582  
# Line 716 | Line 585 | public class ForkJoinTaskTest extends JS
585       */
586      public void testInForkJoinPool2() {
587          RecursiveAction a = new RecursiveAction() {
588 <                public void compute() {
589 <                    threadAssertTrue(!inForkJoinPool());
590 <                }
722 <            };
588 >            public void compute() {
589 >                threadAssertTrue(!inForkJoinPool());
590 >            }};
591          a.invoke();
592      }
593  
# Line 728 | Line 596 | public class ForkJoinTaskTest extends JS
596       */
597      public void testSetRawResult() {
598          RecursiveAction a = new RecursiveAction() {
599 <                public void compute() {
600 <                    setRawResult(null);
601 <                }
734 <            };
599 >            public void compute() {
600 >                setRawResult(null);
601 >            }};
602          a.invoke();
603      }
604  
# Line 740 | Line 607 | public class ForkJoinTaskTest extends JS
607       */
608      public void testCompleteExceptionally() {
609          RecursiveAction a = new RecursiveAction() {
610 <                public void compute() {
611 <                    try {
612 <                        AsyncFib f = new AsyncFib(8);
613 <                        f.completeExceptionally(new FJException());
614 <                        f.invoke();
615 <                        shouldThrow();
616 <                    } catch (FJException success) {
750 <                    }
610 >            public void compute() {
611 >                try {
612 >                    AsyncFib f = new AsyncFib(8);
613 >                    f.completeExceptionally(new FJException());
614 >                    f.invoke();
615 >                    shouldThrow();
616 >                } catch (FJException success) {
617                  }
618 <            };
618 >            }};
619          mainPool.invoke(a);
620      }
621  
# Line 758 | Line 624 | public class ForkJoinTaskTest extends JS
624       */
625      public void testInvokeAll2() {
626          RecursiveAction a = new RecursiveAction() {
627 <                public void compute() {
628 <                    AsyncFib f = new AsyncFib(8);
629 <                    AsyncFib g = new AsyncFib(9);
630 <                    invokeAll(f, g);
631 <                    threadAssertTrue(f.isDone());
632 <                    threadAssertTrue(f.number == 21);
633 <                    threadAssertTrue(g.isDone());
634 <                    threadAssertTrue(g.number == 34);
635 <                }
770 <            };
627 >            public void compute() {
628 >                AsyncFib f = new AsyncFib(8);
629 >                AsyncFib g = new AsyncFib(9);
630 >                invokeAll(f, g);
631 >                threadAssertTrue(f.isDone());
632 >                threadAssertTrue(f.number == 21);
633 >                threadAssertTrue(g.isDone());
634 >                threadAssertTrue(g.number == 34);
635 >            }};
636          mainPool.invoke(a);
637      }
638  
# Line 776 | Line 641 | public class ForkJoinTaskTest extends JS
641       */
642      public void testInvokeAll1() {
643          RecursiveAction a = new RecursiveAction() {
644 <                public void compute() {
645 <                    AsyncFib f = new AsyncFib(8);
646 <                    invokeAll(f);
647 <                    threadAssertTrue(f.isDone());
648 <                    threadAssertTrue(f.number == 21);
649 <                }
785 <            };
644 >            public void compute() {
645 >                AsyncFib f = new AsyncFib(8);
646 >                invokeAll(f);
647 >                threadAssertTrue(f.isDone());
648 >                threadAssertTrue(f.number == 21);
649 >            }};
650          mainPool.invoke(a);
651      }
652  
# Line 791 | Line 655 | public class ForkJoinTaskTest extends JS
655       */
656      public void testInvokeAll3() {
657          RecursiveAction a = new RecursiveAction() {
658 <                public void compute() {
659 <                    AsyncFib f = new AsyncFib(8);
660 <                    AsyncFib g = new AsyncFib(9);
661 <                    AsyncFib h = new AsyncFib(7);
662 <                    invokeAll(f, g, h);
663 <                    threadAssertTrue(f.isDone());
664 <                    threadAssertTrue(f.number == 21);
665 <                    threadAssertTrue(g.isDone());
666 <                    threadAssertTrue(g.number == 34);
667 <                    threadAssertTrue(h.isDone());
668 <                    threadAssertTrue(h.number == 13);
669 <                }
806 <            };
658 >            public void compute() {
659 >                AsyncFib f = new AsyncFib(8);
660 >                AsyncFib g = new AsyncFib(9);
661 >                AsyncFib h = new AsyncFib(7);
662 >                invokeAll(f, g, h);
663 >                threadAssertTrue(f.isDone());
664 >                threadAssertTrue(f.number == 21);
665 >                threadAssertTrue(g.isDone());
666 >                threadAssertTrue(g.number == 34);
667 >                threadAssertTrue(h.isDone());
668 >                threadAssertTrue(h.number == 13);
669 >            }};
670          mainPool.invoke(a);
671      }
672  
# Line 812 | Line 675 | public class ForkJoinTaskTest extends JS
675       */
676      public void testInvokeAllCollection() {
677          RecursiveAction a = new RecursiveAction() {
678 <                public void compute() {
679 <                    AsyncFib f = new AsyncFib(8);
680 <                    AsyncFib g = new AsyncFib(9);
681 <                    AsyncFib h = new AsyncFib(7);
682 <                    HashSet set = new HashSet();
683 <                    set.add(f);
684 <                    set.add(g);
685 <                    set.add(h);
686 <                    invokeAll(set);
687 <                    threadAssertTrue(f.isDone());
688 <                    threadAssertTrue(f.number == 21);
689 <                    threadAssertTrue(g.isDone());
690 <                    threadAssertTrue(g.number == 34);
691 <                    threadAssertTrue(h.isDone());
692 <                    threadAssertTrue(h.number == 13);
693 <                }
831 <            };
678 >            public void compute() {
679 >                AsyncFib f = new AsyncFib(8);
680 >                AsyncFib g = new AsyncFib(9);
681 >                AsyncFib h = new AsyncFib(7);
682 >                HashSet set = new HashSet();
683 >                set.add(f);
684 >                set.add(g);
685 >                set.add(h);
686 >                invokeAll(set);
687 >                threadAssertTrue(f.isDone());
688 >                threadAssertTrue(f.number == 21);
689 >                threadAssertTrue(g.isDone());
690 >                threadAssertTrue(g.number == 34);
691 >                threadAssertTrue(h.isDone());
692 >                threadAssertTrue(h.number == 13);
693 >            }};
694          mainPool.invoke(a);
695      }
696  
# Line 838 | Line 700 | public class ForkJoinTaskTest extends JS
700       */
701      public void testInvokeAllNPE() {
702          RecursiveAction a = new RecursiveAction() {
703 <                public void compute() {
704 <                    try {
705 <                        AsyncFib f = new AsyncFib(8);
706 <                        AsyncFib g = new AsyncFib(9);
707 <                        AsyncFib h = null;
708 <                        invokeAll(f, g, h);
709 <                        shouldThrow();
710 <                    } catch (NullPointerException success) {
849 <                    }
703 >            public void compute() {
704 >                try {
705 >                    AsyncFib f = new AsyncFib(8);
706 >                    AsyncFib g = new AsyncFib(9);
707 >                    AsyncFib h = null;
708 >                    invokeAll(f, g, h);
709 >                    shouldThrow();
710 >                } catch (NullPointerException success) {
711                  }
712 <            };
712 >            }};
713          mainPool.invoke(a);
714      }
715  
# Line 857 | Line 718 | public class ForkJoinTaskTest extends JS
718       */
719      public void testAbnormalInvokeAll2() {
720          RecursiveAction a = new RecursiveAction() {
721 <                public void compute() {
722 <                    try {
723 <                        AsyncFib f = new AsyncFib(8);
724 <                        FailingAsyncFib g = new FailingAsyncFib(9);
725 <                        invokeAll(f, g);
726 <                        shouldThrow();
727 <                    } catch (FJException success) {
867 <                    }
721 >            public void compute() {
722 >                try {
723 >                    AsyncFib f = new AsyncFib(8);
724 >                    FailingAsyncFib g = new FailingAsyncFib(9);
725 >                    invokeAll(f, g);
726 >                    shouldThrow();
727 >                } catch (FJException success) {
728                  }
729 <            };
729 >            }};
730          mainPool.invoke(a);
731      }
732  
# Line 875 | Line 735 | public class ForkJoinTaskTest extends JS
735       */
736      public void testAbnormalInvokeAll1() {
737          RecursiveAction a = new RecursiveAction() {
738 <                public void compute() {
739 <                    try {
740 <                        FailingAsyncFib g = new FailingAsyncFib(9);
741 <                        invokeAll(g);
742 <                        shouldThrow();
743 <                    } catch (FJException success) {
884 <                    }
738 >            public void compute() {
739 >                try {
740 >                    FailingAsyncFib g = new FailingAsyncFib(9);
741 >                    invokeAll(g);
742 >                    shouldThrow();
743 >                } catch (FJException success) {
744                  }
745 <            };
745 >            }};
746          mainPool.invoke(a);
747      }
748  
# Line 892 | Line 751 | public class ForkJoinTaskTest extends JS
751       */
752      public void testAbnormalInvokeAll3() {
753          RecursiveAction a = new RecursiveAction() {
754 <                public void compute() {
755 <                    try {
756 <                        AsyncFib f = new AsyncFib(8);
757 <                        FailingAsyncFib g = new FailingAsyncFib(9);
758 <                        AsyncFib h = new AsyncFib(7);
759 <                        invokeAll(f, g, h);
760 <                        shouldThrow();
761 <                    } catch (FJException success) {
903 <                    }
754 >            public void compute() {
755 >                try {
756 >                    AsyncFib f = new AsyncFib(8);
757 >                    FailingAsyncFib g = new FailingAsyncFib(9);
758 >                    AsyncFib h = new AsyncFib(7);
759 >                    invokeAll(f, g, h);
760 >                    shouldThrow();
761 >                } catch (FJException success) {
762                  }
763 <            };
763 >            }};
764          mainPool.invoke(a);
765      }
766  
# Line 911 | Line 769 | public class ForkJoinTaskTest extends JS
769       */
770      public void testAbnormalInvokeAllCollection() {
771          RecursiveAction a = new RecursiveAction() {
772 <                public void compute() {
773 <                    try {
774 <                        FailingAsyncFib f = new FailingAsyncFib(8);
775 <                        AsyncFib g = new AsyncFib(9);
776 <                        AsyncFib h = new AsyncFib(7);
777 <                        HashSet set = new HashSet();
778 <                        set.add(f);
779 <                        set.add(g);
780 <                        set.add(h);
781 <                        invokeAll(set);
782 <                        shouldThrow();
783 <                    } catch (FJException success) {
926 <                    }
772 >            public void compute() {
773 >                try {
774 >                    FailingAsyncFib f = new FailingAsyncFib(8);
775 >                    AsyncFib g = new AsyncFib(9);
776 >                    AsyncFib h = new AsyncFib(7);
777 >                    HashSet set = new HashSet();
778 >                    set.add(f);
779 >                    set.add(g);
780 >                    set.add(h);
781 >                    invokeAll(set);
782 >                    shouldThrow();
783 >                } catch (FJException success) {
784                  }
785 <            };
785 >            }};
786          mainPool.invoke(a);
787      }
788  
# Line 935 | Line 792 | public class ForkJoinTaskTest extends JS
792       */
793      public void testTryUnfork() {
794          RecursiveAction a = new RecursiveAction() {
795 <                public void compute() {
796 <                    AsyncFib g = new AsyncFib(9);
797 <                    g.fork();
798 <                    AsyncFib f = new AsyncFib(8);
799 <                    f.fork();
800 <                    threadAssertTrue(f.tryUnfork());
801 <                    helpQuiesce();
802 <                    threadAssertFalse(f.isDone());
803 <                    threadAssertTrue(g.isDone());
804 <                }
948 <            };
795 >            public void compute() {
796 >                AsyncFib g = new AsyncFib(9);
797 >                g.fork();
798 >                AsyncFib f = new AsyncFib(8);
799 >                f.fork();
800 >                threadAssertTrue(f.tryUnfork());
801 >                helpQuiesce();
802 >                threadAssertFalse(f.isDone());
803 >                threadAssertTrue(g.isDone());
804 >            }};
805          singletonPool.invoke(a);
806      }
807  
# Line 955 | Line 811 | public class ForkJoinTaskTest extends JS
811       */
812      public void testGetSurplusQueuedTaskCount() {
813          RecursiveAction a = new RecursiveAction() {
814 <                public void compute() {
815 <                    AsyncFib h = new AsyncFib(7);
816 <                    h.fork();
817 <                    AsyncFib g = new AsyncFib(9);
818 <                    g.fork();
819 <                    AsyncFib f = new AsyncFib(8);
820 <                    f.fork();
821 <                    threadAssertTrue(getSurplusQueuedTaskCount() > 0);
822 <                    helpQuiesce();
823 <                }
968 <            };
814 >            public void compute() {
815 >                AsyncFib h = new AsyncFib(7);
816 >                h.fork();
817 >                AsyncFib g = new AsyncFib(9);
818 >                g.fork();
819 >                AsyncFib f = new AsyncFib(8);
820 >                f.fork();
821 >                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
822 >                helpQuiesce();
823 >            }};
824          singletonPool.invoke(a);
825      }
826  
# Line 974 | Line 829 | public class ForkJoinTaskTest extends JS
829       */
830      public void testPeekNextLocalTask() {
831          RecursiveAction a = new RecursiveAction() {
832 <                public void compute() {
833 <                    AsyncFib g = new AsyncFib(9);
834 <                    g.fork();
835 <                    AsyncFib f = new AsyncFib(8);
836 <                    f.fork();
837 <                    threadAssertTrue(peekNextLocalTask() == f);
838 <                    f.join();
839 <                    threadAssertTrue(f.isDone());
840 <                    helpQuiesce();
841 <                }
987 <            };
832 >            public void compute() {
833 >                AsyncFib g = new AsyncFib(9);
834 >                g.fork();
835 >                AsyncFib f = new AsyncFib(8);
836 >                f.fork();
837 >                threadAssertTrue(peekNextLocalTask() == f);
838 >                f.join();
839 >                threadAssertTrue(f.isDone());
840 >                helpQuiesce();
841 >            }};
842          singletonPool.invoke(a);
843      }
844  
# Line 994 | Line 848 | public class ForkJoinTaskTest extends JS
848       */
849      public void testPollNextLocalTask() {
850          RecursiveAction a = new RecursiveAction() {
851 <                public void compute() {
852 <                    AsyncFib g = new AsyncFib(9);
853 <                    g.fork();
854 <                    AsyncFib f = new AsyncFib(8);
855 <                    f.fork();
856 <                    threadAssertTrue(pollNextLocalTask() == f);
857 <                    helpQuiesce();
858 <                    threadAssertFalse(f.isDone());
859 <                }
1006 <            };
851 >            public void compute() {
852 >                AsyncFib g = new AsyncFib(9);
853 >                g.fork();
854 >                AsyncFib f = new AsyncFib(8);
855 >                f.fork();
856 >                threadAssertTrue(pollNextLocalTask() == f);
857 >                helpQuiesce();
858 >                threadAssertFalse(f.isDone());
859 >            }};
860          singletonPool.invoke(a);
861      }
862  
# Line 1013 | Line 866 | public class ForkJoinTaskTest extends JS
866       */
867      public void testPollTask() {
868          RecursiveAction a = new RecursiveAction() {
869 <                public void compute() {
870 <                    AsyncFib g = new AsyncFib(9);
871 <                    g.fork();
872 <                    AsyncFib f = new AsyncFib(8);
873 <                    f.fork();
874 <                    threadAssertTrue(pollTask() == f);
875 <                    helpQuiesce();
876 <                    threadAssertFalse(f.isDone());
877 <                    threadAssertTrue(g.isDone());
878 <                }
1026 <            };
869 >            public void compute() {
870 >                AsyncFib g = new AsyncFib(9);
871 >                g.fork();
872 >                AsyncFib f = new AsyncFib(8);
873 >                f.fork();
874 >                threadAssertTrue(pollTask() == f);
875 >                helpQuiesce();
876 >                threadAssertFalse(f.isDone());
877 >                threadAssertTrue(g.isDone());
878 >            }};
879          singletonPool.invoke(a);
880      }
881  
# Line 1032 | Line 884 | public class ForkJoinTaskTest extends JS
884       */
885      public void testPeekNextLocalTaskAsync() {
886          RecursiveAction a = new RecursiveAction() {
887 <                public void compute() {
888 <                    AsyncFib g = new AsyncFib(9);
889 <                    g.fork();
890 <                    AsyncFib f = new AsyncFib(8);
891 <                    f.fork();
892 <                    threadAssertTrue(peekNextLocalTask() == g);
893 <                    f.join();
894 <                    helpQuiesce();
895 <                    threadAssertTrue(f.isDone());
896 <                }
1045 <            };
887 >            public void compute() {
888 >                AsyncFib g = new AsyncFib(9);
889 >                g.fork();
890 >                AsyncFib f = new AsyncFib(8);
891 >                f.fork();
892 >                threadAssertTrue(peekNextLocalTask() == g);
893 >                f.join();
894 >                helpQuiesce();
895 >                threadAssertTrue(f.isDone());
896 >            }};
897          asyncSingletonPool.invoke(a);
898      }
899  
# Line 1052 | Line 903 | public class ForkJoinTaskTest extends JS
903       */
904      public void testPollNextLocalTaskAsync() {
905          RecursiveAction a = new RecursiveAction() {
906 <                public void compute() {
907 <                    AsyncFib g = new AsyncFib(9);
908 <                    g.fork();
909 <                    AsyncFib f = new AsyncFib(8);
910 <                    f.fork();
911 <                    threadAssertTrue(pollNextLocalTask() == g);
912 <                    helpQuiesce();
913 <                    threadAssertTrue(f.isDone());
914 <                    threadAssertFalse(g.isDone());
915 <                }
1065 <            };
906 >            public void compute() {
907 >                AsyncFib g = new AsyncFib(9);
908 >                g.fork();
909 >                AsyncFib f = new AsyncFib(8);
910 >                f.fork();
911 >                threadAssertTrue(pollNextLocalTask() == g);
912 >                helpQuiesce();
913 >                threadAssertTrue(f.isDone());
914 >                threadAssertFalse(g.isDone());
915 >            }};
916          asyncSingletonPool.invoke(a);
917      }
918  
# Line 1072 | Line 922 | public class ForkJoinTaskTest extends JS
922       */
923      public void testPollTaskAsync() {
924          RecursiveAction a = new RecursiveAction() {
925 <                public void compute() {
926 <                    AsyncFib g = new AsyncFib(9);
927 <                    g.fork();
928 <                    AsyncFib f = new AsyncFib(8);
929 <                    f.fork();
930 <                    threadAssertTrue(pollTask() == g);
931 <                    helpQuiesce();
932 <                    threadAssertTrue(f.isDone());
933 <                    threadAssertFalse(g.isDone());
934 <                }
1085 <            };
925 >            public void compute() {
926 >                AsyncFib g = new AsyncFib(9);
927 >                g.fork();
928 >                AsyncFib f = new AsyncFib(8);
929 >                f.fork();
930 >                threadAssertTrue(pollTask() == g);
931 >                helpQuiesce();
932 >                threadAssertTrue(f.isDone());
933 >                threadAssertFalse(g.isDone());
934 >            }};
935          asyncSingletonPool.invoke(a);
936      }
937   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines