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.7 by jsr166, Tue Dec 1 23:01:44 2009 UTC vs.
Revision 1.8 by dl, Wed Aug 11 19:50:02 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 java.util.*;
7 + import java.util.concurrent.Executor;
8 + import java.util.concurrent.Executors;
9 + import java.util.concurrent.ExecutorService;
10 + import java.util.concurrent.AbstractExecutorService;
11 + import java.util.concurrent.CountDownLatch;
12 + import java.util.concurrent.Callable;
13 + import java.util.concurrent.Future;
14 + import java.util.concurrent.ExecutionException;
15 + import java.util.concurrent.CancellationException;
16 + import java.util.concurrent.RejectedExecutionException;
17 + import java.util.concurrent.ForkJoinPool;
18 + import java.util.concurrent.ForkJoinTask;
19 + import java.util.concurrent.ForkJoinWorkerThread;
20 + import java.util.concurrent.RecursiveAction;
21 + import java.util.concurrent.RecursiveTask;
22 + import java.util.concurrent.TimeUnit;
23   import junit.framework.*;
24 < import java.util.concurrent.*;
24 > import java.util.concurrent.TimeUnit;
25   import java.util.concurrent.atomic.*;
26   import java.util.*;
27  
# Line 27 | Line 44 | public class ForkJoinTaskTest extends JS
44  
45      static final ForkJoinPool mainPool = new ForkJoinPool();
46      static final ForkJoinPool singletonPool = new ForkJoinPool(1);
47 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
48 <    static {
49 <        asyncSingletonPool.setAsyncMode(true);
33 <    }
34 <
47 >    static final ForkJoinPool asyncSingletonPool =
48 >        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
49 >                         null, true);
50      static final class FJException extends RuntimeException {
51          FJException() { super(); }
52      }
# Line 324 | Line 339 | public class ForkJoinTaskTest extends JS
339      }
340  
341      /**
327     * helpJoin of a forked task returns when task completes
328     */
329    public void testForkHelpJoin() {
330        RecursiveAction a = new RecursiveAction() {
331                public void compute() {
332                    AsyncFib f = new AsyncFib(8);
333                    f.fork();
334                    f.helpJoin();
335                    threadAssertTrue(f.number == 21);
336                    threadAssertTrue(f.isDone());
337                }
338            };
339        mainPool.invoke(a);
340    }
341
342    /**
342       * quietlyJoin of a forked task returns when task completes
343       */
344      public void testForkQuietlyJoin() {
# Line 357 | Line 356 | public class ForkJoinTaskTest extends JS
356  
357  
358      /**
360     * quietlyHelpJoin of a forked task returns when task completes
361     */
362    public void testForkQuietlyHelpJoin() {
363        RecursiveAction a = new RecursiveAction() {
364                public void compute() {
365                    AsyncFib f = new AsyncFib(8);
366                    f.fork();
367                    f.quietlyHelpJoin();
368                    threadAssertTrue(f.number == 21);
369                    threadAssertTrue(f.isDone());
370                }
371            };
372        mainPool.invoke(a);
373    }
374
375
376    /**
359       * helpQuiesce returns when tasks are complete.
360       * getQueuedTaskCount returns 0 when quiescent
361       */
# Line 482 | Line 464 | public class ForkJoinTaskTest extends JS
464      }
465  
466      /**
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() {
511                    FailingAsyncFib f = new FailingAsyncFib(8);
512                    f.fork();
513                    f.quietlyHelpJoin();
514                    threadAssertTrue(f.isDone());
515                    threadAssertTrue(f.isCompletedAbnormally());
516                    threadAssertFalse(f.isCancelled());
517                    threadAssertTrue(f.getException() instanceof FJException);
518                }
519            };
520        mainPool.invoke(a);
521    }
522
523    /**
467       * quietlyJoin of a forked task returns when task completes abnormally
468       */
469      public void testAbnormalForkQuietlyJoin() {
# Line 614 | Line 557 | public class ForkJoinTaskTest extends JS
557                  }
558              };
559          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() {
647                    AsyncFib f = new AsyncFib(8);
648                    f.cancel(true);
649                    f.fork();
650                    f.quietlyHelpJoin();
651                    threadAssertTrue(f.isDone());
652                    threadAssertTrue(f.isCompletedAbnormally());
653                    threadAssertTrue(f.isCancelled());
654                    threadAssertTrue(f.getException() instanceof CancellationException);
655                }
656            };
657        mainPool.invoke(a);
560      }
561  
562      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines