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.8 by jsr166, Sat Nov 21 02:07:27 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);
# Line 19 | Line 19 | public class RecursiveTaskTest extends J
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>() {
# Line 166 | Line 164 | public class RecursiveTaskTest extends J
164      }
165  
166      /**
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() {
174                FibTask f = new FibTask(8);
175                f.fork();
176                Integer r = f.helpJoin();
177                threadAssertTrue(r == 21);
178                threadAssertTrue(f.isDone());
179                return r;
180            }
181        };
182        assertTrue(mainPool.invoke(a) == 21);
183    }
184
185    /**
167       * quietlyJoin of a forked task returns when task completes
168       */
169      public void testForkQuietlyJoin() {
# Line 202 | Line 183 | public class RecursiveTaskTest extends J
183  
184  
185      /**
205     * quietlyHelpJoin of a forked task returns when task completes
206     */
207    public void testForkQuietlyHelpJoin() {
208        RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
209            public Integer compute() {
210                FibTask f = new FibTask(8);
211                f.fork();
212                f.quietlyHelpJoin();
213                Integer r = f.getRawResult();
214                threadAssertTrue(r == 21);
215                threadAssertTrue(f.isDone());
216                return r;
217            }
218        };
219        assertTrue(mainPool.invoke(a) == 21);
220    }
221
222
223    /**
186       * helpQuiesce returns when tasks are complete.
187       * getQueuedTaskCount returns 0 when quiescent
188       */
# Line 340 | Line 302 | public class RecursiveTaskTest extends J
302      }
303  
304      /**
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() {
371                FailingFibTask f = new FailingFibTask(8);
372                f.fork();
373                f.quietlyHelpJoin();
374                threadAssertTrue(f.isDone());
375                threadAssertTrue(f.isCompletedAbnormally());
376                threadAssertFalse(f.isCancelled());
377                threadAssertTrue(f.getException() instanceof FJException);
378                return NoResult;
379            }
380        };
381        mainPool.invoke(a);
382    }
383
384    /**
305       * quietlyJoin of a forked task returns when task completes abnormally
306       */
307      public void testAbnormalForkQuietlyJoin() {
# Line 483 | Line 403 | public class RecursiveTaskTest extends J
403                  return NoResult;
404              }
405          };
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() {
519                FibTask f = new FibTask(8);
520                f.cancel(true);
521                f.fork();
522                f.quietlyHelpJoin();
523                threadAssertTrue(f.isDone());
524                threadAssertTrue(f.isCompletedAbnormally());
525                threadAssertTrue(f.isCancelled());
526                threadAssertTrue(f.getException() instanceof CancellationException);
527                return NoResult;
528            }
529        };
406          mainPool.invoke(a);
407      }
408  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines