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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.7 by jsr166, Wed Aug 5 01:17:30 2009 UTC vs.
Revision 1.13 by jsr166, Sat Sep 11 07:31:52 2010 UTC

# Line 11 | Line 11 | import java.util.*;
11   public class RecursiveActionTest extends JSR166TestCase {
12  
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());
14 >        junit.textui.TestRunner.run(suite());
15      }
16 +
17      public static Test suite() {
18 <        return new TestSuite(RecursiveActionTest.class);
18 >        return new TestSuite(RecursiveActionTest.class);
19      }
20  
21      static final ForkJoinPool mainPool = new ForkJoinPool();
22      static final ForkJoinPool singletonPool = new ForkJoinPool(1);
23 <    static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1);
24 <    static {
25 <        asyncSingletonPool.setAsyncMode(true);
25 <    }
23 >    static final ForkJoinPool asyncSingletonPool =
24 >        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
25 >                         null, true);
26  
27      static final class FJException extends RuntimeException {
28          FJException() { super(); }
# Line 68 | Line 68 | public class RecursiveActionTest extends
68       * invoke returns when task completes normally.
69       * isCompletedAbnormally and isCancelled return false for normally
70       * completed tasks. getRawResult of a RecursiveAction returns null;
71     *
71       */
72      public void testInvoke() {
73          RecursiveAction a = new RecursiveAction() {
# Line 162 | Line 161 | public class RecursiveActionTest extends
161       */
162      public void testForkTimedGetNPE() {
163          RecursiveAction a = new RecursiveAction() {
165                public void compute() {
166                    try {
167                        FibAction f = new FibAction(8);
168                        f.fork();
169                        f.get(5L, null);
170                        shouldThrow();
171                    } catch (NullPointerException success) {
172                    } catch (Exception ex) {
173                        unexpectedException(ex);
174                    }
175                }
176            };
177        mainPool.invoke(a);
178    }
179
180    /**
181     * helpJoin of a forked task returns when task completes
182     */
183    public void testForkHelpJoin() {
184        RecursiveAction a = new RecursiveAction() {
164              public void compute() {
165 <                FibAction f = new FibAction(8);
166 <                f.fork();
167 <                f.helpJoin();
168 <                threadAssertTrue(f.result == 21);
169 <                threadAssertTrue(f.isDone());
165 >                try {
166 >                    FibAction f = new FibAction(8);
167 >                    f.fork();
168 >                    f.get(5L, null);
169 >                    shouldThrow();
170 >                } catch (NullPointerException success) {
171 >                } catch (Exception ex) {
172 >                    unexpectedException(ex);
173 >                }
174              }};
175          mainPool.invoke(a);
176      }
# Line 209 | Line 192 | public class RecursiveActionTest extends
192  
193  
194      /**
212     * quietlyHelpJoin of a forked task returns when task completes
213     */
214    public void testForkQuietlyHelpJoin() {
215        RecursiveAction a = new RecursiveAction() {
216            public void compute() {
217                FibAction f = new FibAction(8);
218                f.fork();
219                f.quietlyHelpJoin();
220                threadAssertTrue(f.result == 21);
221                threadAssertTrue(f.isDone());
222            }};
223        mainPool.invoke(a);
224    }
225
226
227    /**
195       * helpQuiesce returns when tasks are complete.
196       * getQueuedTaskCount returns 0 when quiescent
197       */
# Line 327 | Line 294 | public class RecursiveActionTest extends
294      }
295  
296      /**
330     * join of a forked task throws exception when task completes abnormally
331     */
332    public void testAbnormalForkHelpJoin() {
333        RecursiveAction a = new RecursiveAction() {
334            public void compute() {
335                try {
336                    FailingFibAction f = new FailingFibAction(8);
337                    f.fork();
338                    f.helpJoin();
339                    shouldThrow();
340                } catch (FJException success) {
341                }
342            }};
343        mainPool.invoke(a);
344    }
345
346    /**
347     * quietlyHelpJoin of a forked task returns when task completes abnormally.
348     * getException of failed task returns its exception.
349     * isCompletedAbnormally of a failed task returns true.
350     * isCancelled of a failed uncancelled task returns false
351     */
352    public void testAbnormalForkQuietlyHelpJoin() {
353        RecursiveAction a = new RecursiveAction() {
354            public void compute() {
355                FailingFibAction f = new FailingFibAction(8);
356                f.fork();
357                f.quietlyHelpJoin();
358                threadAssertTrue(f.isDone());
359                threadAssertTrue(f.isCompletedAbnormally());
360                threadAssertFalse(f.isCancelled());
361                threadAssertTrue(f.getException() instanceof FJException);
362            }};
363        mainPool.invoke(a);
364    }
365
366    /**
297       * quietlyJoin of a forked task returns when task completes abnormally
298       */
299      public void testAbnormalForkQuietlyJoin() {
# Line 455 | Line 385 | public class RecursiveActionTest extends
385      }
386  
387      /**
458     * join of a forked task throws exception when task cancelled
459     */
460    public void testCancelledForkHelpJoin() {
461        RecursiveAction a = new RecursiveAction() {
462            public void compute() {
463                try {
464                    FibAction f = new FibAction(8);
465                    f.cancel(true);
466                    f.fork();
467                    f.helpJoin();
468                    shouldThrow();
469                } catch (CancellationException success) {
470                }
471            }};
472        mainPool.invoke(a);
473    }
474
475    /**
476     * quietlyHelpJoin of a forked task returns when task cancelled.
477     * getException of cancelled task returns its exception.
478     * isCompletedAbnormally of a cancelled task returns true.
479     * isCancelled of a cancelled task returns true
480     */
481    public void testCancelledForkQuietlyHelpJoin() {
482        RecursiveAction a = new RecursiveAction() {
483            public void compute() {
484                FibAction f = new FibAction(8);
485                f.cancel(true);
486                f.fork();
487                f.quietlyHelpJoin();
488                threadAssertTrue(f.isDone());
489                threadAssertTrue(f.isCompletedAbnormally());
490                threadAssertTrue(f.isCancelled());
491                threadAssertTrue(f.getException() instanceof CancellationException);
492            }};
493        mainPool.invoke(a);
494    }
495
496    /**
388       * quietlyJoin of a forked task returns when task cancelled
389       */
390      public void testCancelledForkQuietlyJoin() {
# Line 569 | Line 460 | public class RecursiveActionTest extends
460  
461      /**
462       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
572     *
463       */
464      public void testWorkerGetPoolIndex() {
465          RecursiveAction a = new RecursiveAction() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines