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

Comparing jsr166/src/test/tck/CountedCompleterTest.java (file contents):
Revision 1.2 by dl, Thu Mar 21 16:26:43 2013 UTC vs.
Revision 1.9 by jsr166, Wed Jun 5 05:48:26 2013 UTC

# Line 12 | Line 12 | import java.util.concurrent.ForkJoinWork
12   import java.util.concurrent.RecursiveAction;
13   import java.util.concurrent.TimeUnit;
14   import java.util.concurrent.TimeoutException;
15 + import java.util.concurrent.atomic.AtomicInteger;
16   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
17 + import java.util.concurrent.atomic.AtomicReference;
18   import static java.util.concurrent.TimeUnit.MILLISECONDS;
19   import static java.util.concurrent.TimeUnit.SECONDS;
20   import java.util.HashSet;
# Line 32 | Line 34 | public class CountedCompleterTest extend
34      static final int mainPoolSize =
35          Math.max(2, Runtime.getRuntime().availableProcessors());
36  
35    /**
36     * Analog of CheckedRunnable for ForkJoinTasks
37     */
38    public abstract class CheckedFJTask extends RecursiveAction {
39        protected abstract void realCompute() throws Throwable;
40
41        public final void compute() {
42            try {
43                realCompute();
44            } catch (Throwable t) {
45                threadUnexpectedException(t);
46            }
47        }
48    }
49
37      private static ForkJoinPool mainPool() {
38          return new ForkJoinPool(mainPoolSize);
39      }
# Line 98 | Line 85 | public class CountedCompleterTest extend
85          } catch (Throwable fail) { threadUnexpectedException(fail); }
86      }
87  
88 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
102 <        checkCompletedNormally(a, null);
103 <    }
104 <
105 <    <T> void checkCompletedNormally(CountedCompleter<T> a, T expected) {
88 >    void checkCompletedNormally(CountedCompleter<?> a) {
89          assertTrue(a.isDone());
90          assertFalse(a.isCancelled());
91          assertTrue(a.isCompletedNormally());
92          assertFalse(a.isCompletedAbnormally());
93          assertNull(a.getException());
94 <        assertSame(expected, a.getRawResult());
94 >        assertNull(a.getRawResult());
95  
96          {
97              Thread.currentThread().interrupt();
98              long t0 = System.nanoTime();
99 <            assertSame(expected, a.join());
99 >            assertNull(a.join());
100              assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
101              Thread.interrupted();
102          }
# Line 129 | Line 112 | public class CountedCompleterTest extend
112          assertFalse(a.cancel(false));
113          assertFalse(a.cancel(true));
114          try {
115 <            assertSame(expected, a.get());
115 >            assertNull(a.get());
116          } catch (Throwable fail) { threadUnexpectedException(fail); }
117          try {
118 <            assertSame(expected, a.get(5L, SECONDS));
118 >            assertNull(a.get(5L, SECONDS));
119          } catch (Throwable fail) { threadUnexpectedException(fail); }
120      }
121  
# Line 211 | Line 194 | public class CountedCompleterTest extend
194          } catch (ExecutionException success) {
195              assertSame(t.getClass(), success.getCause().getClass());
196          } catch (Throwable fail) { threadUnexpectedException(fail); }
197 +
198 +        try {
199 +            a.invoke();
200 +            shouldThrow();
201 +        } catch (Throwable ex) {
202 +            assertSame(t, ex);
203 +        }
204      }
205  
206      public static final class FJException extends RuntimeException {
207          FJException() { super(); }
208      }
209  
210 <    static final class NoopCountedCompleter extends CountedCompleter {
211 <        boolean post; // set true if onCompletion called
212 <        NoopCountedCompleter() { super(); }
213 <        NoopCountedCompleter(CountedCompleter p) { super(p); }
214 <        public void compute() {}
215 <        public final void onCompletion(CountedCompleter caller) {
216 <            post = true;
210 >    abstract class CheckedCC extends CountedCompleter<Object> {
211 >        final AtomicInteger computeN = new AtomicInteger(0);
212 >        final AtomicInteger onCompletionN = new AtomicInteger(0);
213 >        final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
214 >        final AtomicInteger setRawResultN = new AtomicInteger(0);
215 >        final AtomicReference<Object> rawResult = new AtomicReference<>(null);
216 >        int computeN() { return computeN.get(); }
217 >        int onCompletionN() { return onCompletionN.get(); }
218 >        int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }
219 >        int setRawResultN() { return setRawResultN.get(); }
220 >
221 >        CheckedCC() { super(); }
222 >        CheckedCC(CountedCompleter p) { super(p); }
223 >        CheckedCC(CountedCompleter p, int n) { super(p, n); }
224 >        abstract void realCompute();
225 >        public final void compute() {
226 >            computeN.incrementAndGet();
227 >            realCompute();
228 >        }
229 >        public void onCompletion(CountedCompleter caller) {
230 >            onCompletionN.incrementAndGet();
231 >            super.onCompletion(caller);
232 >        }
233 >        public boolean onExceptionalCompletion(Throwable ex,
234 >                                               CountedCompleter caller) {
235 >            onExceptionalCompletionN.incrementAndGet();
236 >            assertNotNull(ex);
237 >            assertTrue(isCompletedAbnormally());
238 >            assertTrue(super.onExceptionalCompletion(ex, caller));
239 >            return true;
240 >        }
241 >        protected void setRawResult(Object t) {
242 >            setRawResultN.incrementAndGet();
243 >            rawResult.set(t);
244 >            super.setRawResult(t);
245 >        }
246 >        void checkIncomplete() {
247 >            assertEquals(0, computeN());
248 >            assertEquals(0, onCompletionN());
249 >            assertEquals(0, onExceptionalCompletionN());
250 >            assertEquals(0, setRawResultN());
251 >            checkNotDone(this);
252 >        }
253 >        void checkCompletes(Object rawResult) {
254 >            checkIncomplete();
255 >            complete(rawResult);
256 >            assertEquals(0, computeN());
257 >            assertEquals(1, onCompletionN());
258 >            assertEquals(0, onExceptionalCompletionN());
259 >            assertEquals(1, setRawResultN());
260 >            assertSame(rawResult, this.rawResult.get());
261 >            checkCompletedNormally(this);
262 >        }
263 >        void checkCompletesExceptionally(Throwable ex) {
264 >            checkIncomplete();
265 >            completeExceptionally(ex);
266 >            checkCompletedExceptionally(ex);
267 >        }
268 >        void checkCompletedExceptionally(Throwable ex) {
269 >            assertEquals(0, computeN());
270 >            assertEquals(0, onCompletionN());
271 >            assertEquals(1, onExceptionalCompletionN());
272 >            assertEquals(0, setRawResultN());
273 >            assertNull(this.rawResult.get());
274 >            checkCompletedAbnormally(this, ex);
275          }
276      }
277  
278 +    final class NoopCC extends CheckedCC {
279 +        NoopCC() { super(); }
280 +        NoopCC(CountedCompleter p) { super(p); }
281 +        protected void realCompute() {}
282 +    }
283 +
284      /**
285 <     * A newly constructed CountedCompleter is not completed;
285 >     * A newly constructed CountedCompleter is not completed;
286       * complete() causes completion.
287       */
288      public void testComplete() {
289 <        NoopCountedCompleter a = new NoopCountedCompleter();
290 <        assertFalse(a.isDone());
291 <        assertFalse(a.isCompletedNormally());
292 <        assertFalse(a.isCompletedAbnormally());
293 <        assertFalse(a.isCancelled());
294 <        assertNull(a.getException());
241 <        assertNull(a.getRawResult());
242 <        assertFalse(a.post);
243 <        a.complete(null);
244 <        assertTrue(a.post);
245 <        assertTrue(a.isDone());
246 <        assertTrue(a.isCompletedNormally());
247 <        assertFalse(a.isCompletedAbnormally());
248 <        assertFalse(a.isCancelled());
249 <        assertNull(a.getException());
250 <        assertNull(a.getRawResult());
289 >        for (Object x : new Object[] { Boolean.TRUE, null }) {
290 >            new NoopCC()
291 >                .checkCompletes(x);
292 >            new NoopCC(new NoopCC())
293 >                .checkCompletes(x);
294 >        }
295      }
296  
297      /**
298       * completeExceptionally completes exceptionally
299       */
300      public void testCompleteExceptionally() {
301 <        NoopCountedCompleter a = new NoopCountedCompleter();
302 <        assertFalse(a.isDone());
303 <        assertFalse(a.isCompletedNormally());
304 <        assertFalse(a.isCompletedAbnormally());
305 <        assertFalse(a.isCancelled());
306 <        assertNull(a.getException());
307 <        assertNull(a.getRawResult());
308 <        assertFalse(a.post);
309 <        a.completeExceptionally(new FJException());
310 <        assertFalse(a.post);
311 <        assertTrue(a.isDone());
312 <        assertFalse(a.isCompletedNormally());
313 <        assertTrue(a.isCompletedAbnormally());
314 <        assertFalse(a.isCancelled());
315 <        assertTrue(a.getException() instanceof FJException);
272 <        assertNull(a.getRawResult());
301 >        new NoopCC()
302 >            .checkCompletesExceptionally(new FJException());
303 >        new NoopCC(new NoopCC())
304 >            .checkCompletesExceptionally(new FJException());
305 >    }
306 >
307 >    /**
308 >     * completeExceptionally(null) throws NullPointerException
309 >     */
310 >    public void testCompleteExceptionally_null() {
311 >        try {
312 >            new NoopCC()
313 >                .checkCompletesExceptionally(null);
314 >            shouldThrow();
315 >        } catch (NullPointerException success) {}
316      }
317  
318      /**
319       * setPendingCount sets the reported pending count
320       */
321      public void testSetPendingCount() {
322 <        NoopCountedCompleter a = new NoopCountedCompleter();
322 >        NoopCC a = new NoopCC();
323          assertEquals(0, a.getPendingCount());
324          a.setPendingCount(1);
325          assertEquals(1, a.getPendingCount());
# Line 288 | Line 331 | public class CountedCompleterTest extend
331       * addToPendingCount adds to the reported pending count
332       */
333      public void testAddToPendingCount() {
334 <        NoopCountedCompleter a = new NoopCountedCompleter();
334 >        NoopCC a = new NoopCC();
335          assertEquals(0, a.getPendingCount());
336          a.addToPendingCount(1);
337          assertEquals(1, a.getPendingCount());
# Line 301 | Line 344 | public class CountedCompleterTest extend
344       * count unless zero
345       */
346      public void testDecrementPendingCount() {
347 <        NoopCountedCompleter a = new NoopCountedCompleter();
347 >        NoopCC a = new NoopCC();
348          assertEquals(0, a.getPendingCount());
349          a.addToPendingCount(1);
350          assertEquals(1, a.getPendingCount());
# Line 312 | Line 355 | public class CountedCompleterTest extend
355      }
356  
357      /**
358 +     * compareAndSetPendingCount compares and sets the reported
359 +     * pending count
360 +     */
361 +    public void testCompareAndSetPendingCount() {
362 +        NoopCC a = new NoopCC();
363 +        assertEquals(0, a.getPendingCount());
364 +        assertTrue(a.compareAndSetPendingCount(0, 1));
365 +        assertEquals(1, a.getPendingCount());
366 +        assertTrue(a.compareAndSetPendingCount(1, 2));
367 +        assertEquals(2, a.getPendingCount());
368 +        assertFalse(a.compareAndSetPendingCount(1, 3));
369 +        assertEquals(2, a.getPendingCount());
370 +    }
371 +
372 +    /**
373       * getCompleter returns parent or null if at root
374       */
375      public void testGetCompleter() {
376 <        NoopCountedCompleter a = new NoopCountedCompleter();
376 >        NoopCC a = new NoopCC();
377          assertNull(a.getCompleter());
378 <        CountedCompleter b = new NoopCountedCompleter(a);
379 <        assertEquals(a, b.getCompleter());
378 >        CountedCompleter b = new NoopCC(a);
379 >        assertSame(a, b.getCompleter());
380 >        CountedCompleter c = new NoopCC(b);
381 >        assertSame(b, c.getCompleter());
382      }
383 <    
383 >
384      /**
385       * getRoot returns self if no parent, else parent's root
386       */
387      public void testGetRoot() {
388 <        NoopCountedCompleter a = new NoopCountedCompleter();
389 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
390 <        assertEquals(a, a.getRoot());
391 <        assertEquals(a, b.getRoot());
388 >        NoopCC a = new NoopCC();
389 >        NoopCC b = new NoopCC(a);
390 >        NoopCC c = new NoopCC(b);
391 >        assertSame(a, a.getRoot());
392 >        assertSame(a, b.getRoot());
393 >        assertSame(a, c.getRoot());
394      }
395 <              
395 >
396      /**
397 <     * tryComplete causes completion if pending count is zero
397 >     * tryComplete decrements pending count unless zero, in which case
398 >     * causes completion
399       */
400 <    public void testTryComplete1() {
401 <        NoopCountedCompleter a = new NoopCountedCompleter();
400 >    public void testTryComplete() {
401 >        NoopCC a = new NoopCC();
402          assertEquals(0, a.getPendingCount());
403 +        int n = 3;
404 +        a.setPendingCount(n);
405 +        for (; n > 0; n--) {
406 +            assertEquals(n, a.getPendingCount());
407 +            a.tryComplete();
408 +            a.checkIncomplete();
409 +            assertEquals(n - 1, a.getPendingCount());
410 +        }
411          a.tryComplete();
412 <        assertTrue(a.post);
413 <        assertTrue(a.isDone());
412 >        assertEquals(0, a.computeN());
413 >        assertEquals(1, a.onCompletionN());
414 >        assertEquals(0, a.onExceptionalCompletionN());
415 >        assertEquals(0, a.setRawResultN());
416 >        checkCompletedNormally(a);
417      }
418  
419      /**
420 <     * propagateCompletion causes completion without invokein
421 <     * onCompletion if pending count is zero
420 >     * propagateCompletion decrements pending count unless zero, in
421 >     * which case causes completion, without invoking onCompletion
422       */
423      public void testPropagateCompletion() {
424 <        NoopCountedCompleter a = new NoopCountedCompleter();
424 >        NoopCC a = new NoopCC();
425          assertEquals(0, a.getPendingCount());
426 +        int n = 3;
427 +        a.setPendingCount(n);
428 +        for (; n > 0; n--) {
429 +            assertEquals(n, a.getPendingCount());
430 +            a.propagateCompletion();
431 +            a.checkIncomplete();
432 +            assertEquals(n - 1, a.getPendingCount());
433 +        }
434          a.propagateCompletion();
435 <        assertFalse(a.post);
436 <        assertTrue(a.isDone());
437 <    }
438 <
439 <    /**
358 <     * tryComplete decrments pending count unless zero
359 <     */
360 <    public void testTryComplete2() {
361 <        NoopCountedCompleter a = new NoopCountedCompleter();
362 <        assertEquals(0, a.getPendingCount());
363 <        a.setPendingCount(1);
364 <        a.tryComplete();
365 <        assertFalse(a.post);
366 <        assertFalse(a.isDone());
367 <        assertEquals(0, a.getPendingCount());
368 <        a.tryComplete();
369 <        assertTrue(a.post);
370 <        assertTrue(a.isDone());
435 >        assertEquals(0, a.computeN());
436 >        assertEquals(0, a.onCompletionN());
437 >        assertEquals(0, a.onExceptionalCompletionN());
438 >        assertEquals(0, a.setRawResultN());
439 >        checkCompletedNormally(a);
440      }
441  
442      /**
443       * firstComplete returns this if pending count is zero else null
444       */
445      public void testFirstComplete() {
446 <        NoopCountedCompleter a = new NoopCountedCompleter();
446 >        NoopCC a = new NoopCC();
447          a.setPendingCount(1);
448          assertNull(a.firstComplete());
449 <        assertEquals(a, a.firstComplete());
449 >        a.checkIncomplete();
450 >        assertSame(a, a.firstComplete());
451 >        a.checkIncomplete();
452      }
453  
454      /**
# Line 385 | Line 456 | public class CountedCompleterTest extend
456       * zero else null
457       */
458      public void testNextComplete() {
459 <        NoopCountedCompleter a = new NoopCountedCompleter();
460 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
459 >        NoopCC a = new NoopCC();
460 >        NoopCC b = new NoopCC(a);
461          a.setPendingCount(1);
462          b.setPendingCount(1);
463          assertNull(b.firstComplete());
464 <        CountedCompleter c = b.firstComplete();
465 <        assertEquals(b, c);
466 <        CountedCompleter d = c.nextComplete();
467 <        assertNull(d);
468 <        CountedCompleter e = c.nextComplete();
469 <        assertEquals(a, e);
464 >        assertSame(b, b.firstComplete());
465 >        assertNull(b.nextComplete());
466 >        a.checkIncomplete();
467 >        b.checkIncomplete();
468 >        assertSame(a, b.nextComplete());
469 >        assertSame(a, b.nextComplete());
470 >        a.checkIncomplete();
471 >        b.checkIncomplete();
472 >        assertNull(a.nextComplete());
473 >        b.checkIncomplete();
474 >        checkCompletedNormally(a);
475      }
476  
477      /**
478       * quietlyCompleteRoot completes root task
479       */
480      public void testQuietlyCompleteRoot() {
481 <        NoopCountedCompleter a = new NoopCountedCompleter();
482 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
481 >        NoopCC a = new NoopCC();
482 >        NoopCC b = new NoopCC(a);
483 >        NoopCC c = new NoopCC(b);
484          a.setPendingCount(1);
485          b.setPendingCount(1);
486 <        b.quietlyCompleteRoot();
486 >        c.setPendingCount(1);
487 >        c.quietlyCompleteRoot();
488          assertTrue(a.isDone());
489          assertFalse(b.isDone());
490 +        assertFalse(c.isDone());
491      }
492  
493      // Invocation tests use some interdependent task classes
494      // to better test propagation etc
495  
496 <    
496 >
497      // Version of Fibonacci with different classes for left vs right forks
498 <    static abstract class CCF extends CountedCompleter {
498 >    abstract class CCF extends CheckedCC {
499          int number;
500          int rnumber;
501  
# Line 425 | Line 504 | public class CountedCompleterTest extend
504              this.number = n;
505          }
506  
507 <        public final void compute() {
429 <            CountedCompleter p;
507 >        protected final void realCompute() {
508              CCF f = this;
509              int n = number;
510              while (n >= 2) {
511                  new RCCF(f, n - 2).fork();
512                  f = new LCCF(f, --n);
513              }
514 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
514 >            f.complete(null);
515          }
516      }
517  
518 <    static final class LCCF extends CCF {
518 >    final class LCCF extends CCF {
519 >        public LCCF(int n) { this(null, n); }
520          public LCCF(CountedCompleter parent, int n) {
521              super(parent, n);
522          }
523          public final void onCompletion(CountedCompleter caller) {
524 +            super.onCompletion(caller);
525              CCF p = (CCF)getCompleter();
526              int n = number + rnumber;
527              if (p != null)
# Line 455 | Line 530 | public class CountedCompleterTest extend
530                  number = n;
531          }
532      }
533 <    static final class RCCF extends CCF {
533 >    final class RCCF extends CCF {
534          public RCCF(CountedCompleter parent, int n) {
535              super(parent, n);
536          }
537          public final void onCompletion(CountedCompleter caller) {
538 +            super.onCompletion(caller);
539              CCF p = (CCF)getCompleter();
540              int n = number + rnumber;
541              if (p != null)
# Line 470 | Line 546 | public class CountedCompleterTest extend
546      }
547  
548      // Version of CCF with forced failure in left completions
549 <    static abstract class FailingCCF extends CountedCompleter {
549 >    abstract class FailingCCF extends CheckedCC {
550          int number;
551          int rnumber;
552  
# Line 479 | Line 555 | public class CountedCompleterTest extend
555              this.number = n;
556          }
557  
558 <        public final void compute() {
483 <            CountedCompleter p;
558 >        protected final void realCompute() {
559              FailingCCF f = this;
560              int n = number;
561              while (n >= 2) {
562                  new RFCCF(f, n - 2).fork();
563                  f = new LFCCF(f, --n);
564              }
565 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
565 >            f.complete(null);
566          }
567      }
568  
569 <    static final class LFCCF extends FailingCCF {
569 >    final class LFCCF extends FailingCCF {
570 >        public LFCCF(int n) { this(null, n); }
571          public LFCCF(CountedCompleter parent, int n) {
572              super(parent, n);
573          }
574          public final void onCompletion(CountedCompleter caller) {
575 +            super.onCompletion(caller);
576              FailingCCF p = (FailingCCF)getCompleter();
577              int n = number + rnumber;
578              if (p != null)
# Line 509 | Line 581 | public class CountedCompleterTest extend
581                  number = n;
582          }
583      }
584 <    static final class RFCCF extends FailingCCF {
584 >    final class RFCCF extends FailingCCF {
585          public RFCCF(CountedCompleter parent, int n) {
586              super(parent, n);
587          }
588          public final void onCompletion(CountedCompleter caller) {
589 +            super.onCompletion(caller);
590              completeExceptionally(new FJException());
591          }
592      }
593 <    
593 >
594      /**
595       * invoke returns when task completes normally.
596       * isCompletedAbnormally and isCancelled return false for normally
597       * completed tasks; getRawResult returns null.
598       */
599      public void testInvoke() {
600 <       ForkJoinTask a =  new CheckedFJTask() {
601 <            public void realCompute() {
602 <                CCF f = new LCCF(null, 8);
600 >        ForkJoinTask a = new CheckedRecursiveAction() {
601 >            protected void realCompute() {
602 >                CCF f = new LCCF(8);
603                  assertNull(f.invoke());
604                  assertEquals(21, f.number);
605                  checkCompletedNormally(f);
# Line 540 | Line 613 | public class CountedCompleterTest extend
613       * completed tasks
614       */
615      public void testQuietlyInvoke() {
616 <       ForkJoinTask a =  new CheckedFJTask() {
617 <            public void realCompute() {
618 <                CCF f = new LCCF(null, 8);
616 >        ForkJoinTask a = new CheckedRecursiveAction() {
617 >            protected void realCompute() {
618 >                CCF f = new LCCF(8);
619                  f.quietlyInvoke();
620                  assertEquals(21, f.number);
621                  checkCompletedNormally(f);
# Line 554 | Line 627 | public class CountedCompleterTest extend
627       * join of a forked task returns when task completes
628       */
629      public void testForkJoin() {
630 <       ForkJoinTask a =  new CheckedFJTask() {
631 <            public void realCompute() {
632 <                CCF f = new LCCF(null, 8);
630 >        ForkJoinTask a = new CheckedRecursiveAction() {
631 >            protected void realCompute() {
632 >                CCF f = new LCCF(8);
633                  assertSame(f, f.fork());
634                  assertNull(f.join());
635                  assertEquals(21, f.number);
# Line 569 | Line 642 | public class CountedCompleterTest extend
642       * get of a forked task returns when task completes
643       */
644      public void testForkGet() {
645 <       ForkJoinTask a =  new CheckedFJTask() {
646 <            public void realCompute() throws Exception {
647 <                CCF f = new LCCF(null, 8);
645 >        ForkJoinTask a = new CheckedRecursiveAction() {
646 >            protected void realCompute() throws Exception {
647 >                CCF f = new LCCF(8);
648                  assertSame(f, f.fork());
649                  assertNull(f.get());
650                  assertEquals(21, f.number);
# Line 584 | Line 657 | public class CountedCompleterTest extend
657       * timed get of a forked task returns when task completes
658       */
659      public void testForkTimedGet() {
660 <       ForkJoinTask a =  new CheckedFJTask() {
661 <            public void realCompute() throws Exception {
662 <                CCF f = new LCCF(null, 8);
660 >        ForkJoinTask a = new CheckedRecursiveAction() {
661 >            protected void realCompute() throws Exception {
662 >                CCF f = new LCCF(8);
663                  assertSame(f, f.fork());
664                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
665                  assertEquals(21, f.number);
# Line 599 | Line 672 | public class CountedCompleterTest extend
672       * timed get with null time unit throws NPE
673       */
674      public void testForkTimedGetNPE() {
675 <       ForkJoinTask a =  new CheckedFJTask() {
676 <            public void realCompute() throws Exception {
677 <                CCF f = new LCCF(null, 8);
675 >        ForkJoinTask a = new CheckedRecursiveAction() {
676 >            protected void realCompute() throws Exception {
677 >                CCF f = new LCCF(8);
678                  assertSame(f, f.fork());
679                  try {
680                      f.get(5L, null);
# Line 615 | Line 688 | public class CountedCompleterTest extend
688       * quietlyJoin of a forked task returns when task completes
689       */
690      public void testForkQuietlyJoin() {
691 <       ForkJoinTask a =  new CheckedFJTask() {
692 <            public void realCompute() {
693 <                CCF f = new LCCF(null, 8);
691 >        ForkJoinTask a = new CheckedRecursiveAction() {
692 >            protected void realCompute() {
693 >                CCF f = new LCCF(8);
694                  assertSame(f, f.fork());
695                  f.quietlyJoin();
696                  assertEquals(21, f.number);
# Line 631 | Line 704 | public class CountedCompleterTest extend
704       * getQueuedTaskCount returns 0 when quiescent
705       */
706      public void testForkHelpQuiesce() {
707 <       ForkJoinTask a =  new CheckedFJTask() {
708 <            public void realCompute() {
709 <                CCF f = new LCCF(null, 8);
707 >        ForkJoinTask a = new CheckedRecursiveAction() {
708 >            protected void realCompute() {
709 >                CCF f = new LCCF(8);
710                  assertSame(f, f.fork());
711                  helpQuiesce();
712                  assertEquals(21, f.number);
# Line 647 | Line 720 | public class CountedCompleterTest extend
720       * invoke task throws exception when task completes abnormally
721       */
722      public void testAbnormalInvoke() {
723 <       ForkJoinTask a =  new CheckedFJTask() {
724 <            public void realCompute() {
725 <                FailingCCF f = new LFCCF(null, 8);
723 >        ForkJoinTask a = new CheckedRecursiveAction() {
724 >            protected void realCompute() {
725 >                FailingCCF f = new LFCCF(8);
726                  try {
727                      f.invoke();
728                      shouldThrow();
# Line 664 | Line 737 | public class CountedCompleterTest extend
737       * quietlyInvoke task returns when task completes abnormally
738       */
739      public void testAbnormalQuietlyInvoke() {
740 <       ForkJoinTask a =  new CheckedFJTask() {
741 <            public void realCompute() {
742 <                FailingCCF f = new LFCCF(null, 8);
740 >        ForkJoinTask a = new CheckedRecursiveAction() {
741 >            protected void realCompute() {
742 >                FailingCCF f = new LFCCF(8);
743                  f.quietlyInvoke();
744                  assertTrue(f.getException() instanceof FJException);
745                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 751 | public class CountedCompleterTest extend
751       * join of a forked task throws exception when task completes abnormally
752       */
753      public void testAbnormalForkJoin() {
754 <       ForkJoinTask a =  new CheckedFJTask() {
755 <            public void realCompute() {
756 <                FailingCCF f = new LFCCF(null, 8);
754 >        ForkJoinTask a = new CheckedRecursiveAction() {
755 >            protected void realCompute() {
756 >                FailingCCF f = new LFCCF(8);
757                  assertSame(f, f.fork());
758                  try {
759                      f.join();
# Line 696 | Line 769 | public class CountedCompleterTest extend
769       * get of a forked task throws exception when task completes abnormally
770       */
771      public void testAbnormalForkGet() {
772 <       ForkJoinTask a =  new CheckedFJTask() {
773 <            public void realCompute() throws Exception {
774 <                FailingCCF f = new LFCCF(null, 8);
772 >        ForkJoinTask a = new CheckedRecursiveAction() {
773 >            protected void realCompute() throws Exception {
774 >                FailingCCF f = new LFCCF(8);
775                  assertSame(f, f.fork());
776                  try {
777                      f.get();
# Line 716 | Line 789 | public class CountedCompleterTest extend
789       * timed get of a forked task throws exception when task completes abnormally
790       */
791      public void testAbnormalForkTimedGet() {
792 <       ForkJoinTask a =  new CheckedFJTask() {
793 <            public void realCompute() throws Exception {
794 <                FailingCCF f = new LFCCF(null, 8);
792 >        ForkJoinTask a = new CheckedRecursiveAction() {
793 >            protected void realCompute() throws Exception {
794 >                FailingCCF f = new LFCCF(8);
795                  assertSame(f, f.fork());
796                  try {
797                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 809 | public class CountedCompleterTest extend
809       * quietlyJoin of a forked task returns when task completes abnormally
810       */
811      public void testAbnormalForkQuietlyJoin() {
812 <       ForkJoinTask a =  new CheckedFJTask() {
813 <            public void realCompute() {
814 <                FailingCCF f = new LFCCF(null, 8);
812 >        ForkJoinTask a = new CheckedRecursiveAction() {
813 >            protected void realCompute() {
814 >                FailingCCF f = new LFCCF(8);
815                  assertSame(f, f.fork());
816                  f.quietlyJoin();
817                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 824 | public class CountedCompleterTest extend
824       * invoke task throws exception when task cancelled
825       */
826      public void testCancelledInvoke() {
827 <       ForkJoinTask a =  new CheckedFJTask() {
828 <            public void realCompute() {
829 <                CCF f = new LCCF(null, 8);
827 >        ForkJoinTask a = new CheckedRecursiveAction() {
828 >            protected void realCompute() {
829 >                CCF f = new LCCF(8);
830                  assertTrue(f.cancel(true));
831                  try {
832                      f.invoke();
# Line 769 | Line 842 | public class CountedCompleterTest extend
842       * join of a forked task throws exception when task cancelled
843       */
844      public void testCancelledForkJoin() {
845 <       ForkJoinTask a =  new CheckedFJTask() {
846 <            public void realCompute() {
847 <                CCF f = new LCCF(null, 8);
845 >        ForkJoinTask a = new CheckedRecursiveAction() {
846 >            protected void realCompute() {
847 >                CCF f = new LCCF(8);
848                  assertTrue(f.cancel(true));
849                  assertSame(f, f.fork());
850                  try {
# Line 788 | Line 861 | public class CountedCompleterTest extend
861       * get of a forked task throws exception when task cancelled
862       */
863      public void testCancelledForkGet() {
864 <       ForkJoinTask a =  new CheckedFJTask() {
865 <            public void realCompute() throws Exception {
866 <                CCF f = new LCCF(null, 8);
864 >        ForkJoinTask a = new CheckedRecursiveAction() {
865 >            protected void realCompute() throws Exception {
866 >                CCF f = new LCCF(8);
867                  assertTrue(f.cancel(true));
868                  assertSame(f, f.fork());
869                  try {
# Line 807 | Line 880 | public class CountedCompleterTest extend
880       * timed get of a forked task throws exception when task cancelled
881       */
882      public void testCancelledForkTimedGet() throws Exception {
883 <       ForkJoinTask a =  new CheckedFJTask() {
884 <            public void realCompute() throws Exception {
885 <                CCF f = new LCCF(null, 8);
883 >        ForkJoinTask a = new CheckedRecursiveAction() {
884 >            protected void realCompute() throws Exception {
885 >                CCF f = new LCCF(8);
886                  assertTrue(f.cancel(true));
887                  assertSame(f, f.fork());
888                  try {
# Line 826 | Line 899 | public class CountedCompleterTest extend
899       * quietlyJoin of a forked task returns when task cancelled
900       */
901      public void testCancelledForkQuietlyJoin() {
902 <       ForkJoinTask a =  new CheckedFJTask() {
903 <            public void realCompute() {
904 <                CCF f = new LCCF(null, 8);
902 >        ForkJoinTask a = new CheckedRecursiveAction() {
903 >            protected void realCompute() {
904 >                CCF f = new LCCF(8);
905                  assertTrue(f.cancel(true));
906                  assertSame(f, f.fork());
907                  f.quietlyJoin();
# Line 842 | Line 915 | public class CountedCompleterTest extend
915       */
916      public void testGetPool() {
917          final ForkJoinPool mainPool = mainPool();
918 <       ForkJoinTask a =  new CheckedFJTask() {
919 <            public void realCompute() {
918 >        ForkJoinTask a = new CheckedRecursiveAction() {
919 >            protected void realCompute() {
920                  assertSame(mainPool, getPool());
921              }};
922          testInvokeOnPool(mainPool, a);
# Line 853 | Line 926 | public class CountedCompleterTest extend
926       * getPool of non-FJ task returns null
927       */
928      public void testGetPool2() {
929 <       ForkJoinTask a =  new CheckedFJTask() {
930 <            public void realCompute() {
929 >        ForkJoinTask a = new CheckedRecursiveAction() {
930 >            protected void realCompute() {
931                  assertNull(getPool());
932              }};
933          assertNull(a.invoke());
# Line 864 | Line 937 | public class CountedCompleterTest extend
937       * inForkJoinPool of executing task returns true
938       */
939      public void testInForkJoinPool() {
940 <       ForkJoinTask a =  new CheckedFJTask() {
941 <            public void realCompute() {
940 >        ForkJoinTask a = new CheckedRecursiveAction() {
941 >            protected void realCompute() {
942                  assertTrue(inForkJoinPool());
943              }};
944          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 948 | public class CountedCompleterTest extend
948       * inForkJoinPool of non-FJ task returns false
949       */
950      public void testInForkJoinPool2() {
951 <       ForkJoinTask a =  new CheckedFJTask() {
952 <            public void realCompute() {
951 >        ForkJoinTask a = new CheckedRecursiveAction() {
952 >            protected void realCompute() {
953                  assertFalse(inForkJoinPool());
954              }};
955          assertNull(a.invoke());
# Line 886 | Line 959 | public class CountedCompleterTest extend
959       * setRawResult(null) succeeds
960       */
961      public void testSetRawResult() {
962 <       ForkJoinTask a =  new CheckedFJTask() {
963 <            public void realCompute() {
962 >        ForkJoinTask a = new CheckedRecursiveAction() {
963 >            protected void realCompute() {
964                  setRawResult(null);
965                  assertNull(getRawResult());
966              }};
# Line 898 | Line 971 | public class CountedCompleterTest extend
971       * invoke task throws exception after invoking completeExceptionally
972       */
973      public void testCompleteExceptionally2() {
974 <       ForkJoinTask a =  new CheckedFJTask() {
975 <            public void realCompute() {
976 <                CCF f = new LCCF(null, 8);
977 <                f.completeExceptionally(new FJException());
978 <                try {
979 <                    f.invoke();
980 <                    shouldThrow();
981 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
974 >        ForkJoinTask a = new CheckedRecursiveAction() {
975 >            protected void realCompute() {
976 >                CCF n = new LCCF(8);
977 >                CCF f = new LCCF(n, 8);
978 >                FJException ex = new FJException();
979 >                f.completeExceptionally(ex);
980 >                f.checkCompletedExceptionally(ex);
981 >                n.checkCompletedExceptionally(ex);
982              }};
983          testInvokeOnPool(mainPool(), a);
984      }
# Line 916 | Line 987 | public class CountedCompleterTest extend
987       * invokeAll(t1, t2) invokes all task arguments
988       */
989      public void testInvokeAll2() {
990 <       ForkJoinTask a =  new CheckedFJTask() {
991 <            public void realCompute() {
992 <                CCF f = new LCCF(null, 8);
993 <                CCF g = new LCCF(null, 9);
990 >        ForkJoinTask a = new CheckedRecursiveAction() {
991 >            protected void realCompute() {
992 >                CCF f = new LCCF(8);
993 >                CCF g = new LCCF(9);
994                  invokeAll(f, g);
995                  assertEquals(21, f.number);
996                  assertEquals(34, g.number);
# Line 933 | Line 1004 | public class CountedCompleterTest extend
1004       * invokeAll(tasks) with 1 argument invokes task
1005       */
1006      public void testInvokeAll1() {
1007 <       ForkJoinTask a =  new CheckedFJTask() {
1008 <            public void realCompute() {
1009 <                CCF f = new LCCF(null, 8);
1007 >        ForkJoinTask a = new CheckedRecursiveAction() {
1008 >            protected void realCompute() {
1009 >                CCF f = new LCCF(8);
1010                  invokeAll(f);
1011                  checkCompletedNormally(f);
1012                  assertEquals(21, f.number);
# Line 947 | Line 1018 | public class CountedCompleterTest extend
1018       * invokeAll(tasks) with > 2 argument invokes tasks
1019       */
1020      public void testInvokeAll3() {
1021 <       ForkJoinTask a =  new CheckedFJTask() {
1022 <            public void realCompute() {
1023 <                CCF f = new LCCF(null, 8);
1024 <                CCF g = new LCCF(null, 9);
1025 <                CCF h = new LCCF(null, 7);
1021 >        ForkJoinTask a = new CheckedRecursiveAction() {
1022 >            protected void realCompute() {
1023 >                CCF f = new LCCF(8);
1024 >                CCF g = new LCCF(9);
1025 >                CCF h = new LCCF(7);
1026                  invokeAll(f, g, h);
1027                  assertEquals(21, f.number);
1028                  assertEquals(34, g.number);
# Line 967 | Line 1038 | public class CountedCompleterTest extend
1038       * invokeAll(collection) invokes all tasks in the collection
1039       */
1040      public void testInvokeAllCollection() {
1041 <       ForkJoinTask a =  new CheckedFJTask() {
1042 <            public void realCompute() {
1043 <                CCF f = new LCCF(null, 8);
1044 <                CCF g = new LCCF(null, 9);
1045 <                CCF h = new LCCF(null, 7);
1041 >        ForkJoinTask a = new CheckedRecursiveAction() {
1042 >            protected void realCompute() {
1043 >                CCF f = new LCCF(8);
1044 >                CCF g = new LCCF(9);
1045 >                CCF h = new LCCF(7);
1046                  HashSet set = new HashSet();
1047                  set.add(f);
1048                  set.add(g);
# Line 991 | Line 1062 | public class CountedCompleterTest extend
1062       * invokeAll(tasks) with any null task throws NPE
1063       */
1064      public void testInvokeAllNPE() {
1065 <       ForkJoinTask a =  new CheckedFJTask() {
1066 <            public void realCompute() {
1067 <                CCF f = new LCCF(null, 8);
1068 <                CCF g = new LCCF(null, 9);
1065 >        ForkJoinTask a = new CheckedRecursiveAction() {
1066 >            protected void realCompute() {
1067 >                CCF f = new LCCF(8);
1068 >                CCF g = new LCCF(9);
1069                  CCF h = null;
1070                  try {
1071                      invokeAll(f, g, h);
# Line 1008 | Line 1079 | public class CountedCompleterTest extend
1079       * invokeAll(t1, t2) throw exception if any task does
1080       */
1081      public void testAbnormalInvokeAll2() {
1082 <       ForkJoinTask a =  new CheckedFJTask() {
1083 <            public void realCompute() {
1084 <                CCF f = new LCCF(null, 8);
1085 <                FailingCCF g = new LFCCF(null, 9);
1082 >        ForkJoinTask a = new CheckedRecursiveAction() {
1083 >            protected void realCompute() {
1084 >                CCF f = new LCCF(8);
1085 >                FailingCCF g = new LFCCF(9);
1086                  try {
1087                      invokeAll(f, g);
1088                      shouldThrow();
# Line 1026 | Line 1097 | public class CountedCompleterTest extend
1097       * invokeAll(tasks) with 1 argument throws exception if task does
1098       */
1099      public void testAbnormalInvokeAll1() {
1100 <       ForkJoinTask a =  new CheckedFJTask() {
1101 <            public void realCompute() {
1102 <                FailingCCF g = new LFCCF(null, 9);
1100 >        ForkJoinTask a = new CheckedRecursiveAction() {
1101 >            protected void realCompute() {
1102 >                FailingCCF g = new LFCCF(9);
1103                  try {
1104                      invokeAll(g);
1105                      shouldThrow();
# Line 1043 | Line 1114 | public class CountedCompleterTest extend
1114       * invokeAll(tasks) with > 2 argument throws exception if any task does
1115       */
1116      public void testAbnormalInvokeAll3() {
1117 <       ForkJoinTask a =  new CheckedFJTask() {
1118 <            public void realCompute() {
1119 <                CCF f = new LCCF(null, 8);
1120 <                FailingCCF g = new LFCCF(null, 9);
1121 <                CCF h = new LCCF(null, 7);
1117 >        ForkJoinTask a = new CheckedRecursiveAction() {
1118 >            protected void realCompute() {
1119 >                CCF f = new LCCF(8);
1120 >                FailingCCF g = new LFCCF(9);
1121 >                CCF h = new LCCF(7);
1122                  try {
1123                      invokeAll(f, g, h);
1124                      shouldThrow();
# Line 1062 | Line 1133 | public class CountedCompleterTest extend
1133       * invokeAll(collection)  throws exception if any task does
1134       */
1135      public void testAbnormalInvokeAllCollection() {
1136 <       ForkJoinTask a =  new CheckedFJTask() {
1137 <            public void realCompute() {
1138 <                FailingCCF f = new LFCCF(null, 8);
1139 <                CCF g = new LCCF(null, 9);
1140 <                CCF h = new LCCF(null, 7);
1136 >        ForkJoinTask a = new CheckedRecursiveAction() {
1137 >            protected void realCompute() {
1138 >                FailingCCF f = new LFCCF(8);
1139 >                CCF g = new LCCF(9);
1140 >                CCF h = new LCCF(7);
1141                  HashSet set = new HashSet();
1142                  set.add(f);
1143                  set.add(g);
# Line 1086 | Line 1157 | public class CountedCompleterTest extend
1157       * and suppresses execution
1158       */
1159      public void testTryUnfork() {
1160 <       ForkJoinTask a =  new CheckedFJTask() {
1161 <            public void realCompute() {
1162 <                CCF g = new LCCF(null, 9);
1160 >        ForkJoinTask a = new CheckedRecursiveAction() {
1161 >            protected void realCompute() {
1162 >                CCF g = new LCCF(9);
1163                  assertSame(g, g.fork());
1164 <                CCF f = new LCCF(null, 8);
1164 >                CCF f = new LCCF(8);
1165                  assertSame(f, f.fork());
1166                  assertTrue(f.tryUnfork());
1167                  helpQuiesce();
# Line 1105 | Line 1176 | public class CountedCompleterTest extend
1176       * there are more tasks than threads
1177       */
1178      public void testGetSurplusQueuedTaskCount() {
1179 <       ForkJoinTask a =  new CheckedFJTask() {
1180 <            public void realCompute() {
1181 <                CCF h = new LCCF(null, 7);
1179 >        ForkJoinTask a = new CheckedRecursiveAction() {
1180 >            protected void realCompute() {
1181 >                CCF h = new LCCF(7);
1182                  assertSame(h, h.fork());
1183 <                CCF g = new LCCF(null, 9);
1183 >                CCF g = new LCCF(9);
1184                  assertSame(g, g.fork());
1185 <                CCF f = new LCCF(null, 8);
1185 >                CCF f = new LCCF(8);
1186                  assertSame(f, f.fork());
1187                  assertTrue(getSurplusQueuedTaskCount() > 0);
1188                  helpQuiesce();
# Line 1127 | Line 1198 | public class CountedCompleterTest extend
1198       * peekNextLocalTask returns most recent unexecuted task.
1199       */
1200      public void testPeekNextLocalTask() {
1201 <       ForkJoinTask a =  new CheckedFJTask() {
1202 <            public void realCompute() {
1203 <                CCF g = new LCCF(null, 9);
1201 >        ForkJoinTask a = new CheckedRecursiveAction() {
1202 >            protected void realCompute() {
1203 >                CCF g = new LCCF(9);
1204                  assertSame(g, g.fork());
1205 <                CCF f = new LCCF(null, 8);
1205 >                CCF f = new LCCF(8);
1206                  assertSame(f, f.fork());
1207                  assertSame(f, peekNextLocalTask());
1208                  assertNull(f.join());
# Line 1147 | Line 1218 | public class CountedCompleterTest extend
1218       * executing it
1219       */
1220      public void testPollNextLocalTask() {
1221 <       ForkJoinTask a =  new CheckedFJTask() {
1222 <            public void realCompute() {
1223 <                CCF g = new LCCF(null, 9);
1221 >        ForkJoinTask a = new CheckedRecursiveAction() {
1222 >            protected void realCompute() {
1223 >                CCF g = new LCCF(9);
1224                  assertSame(g, g.fork());
1225 <                CCF f = new LCCF(null, 8);
1225 >                CCF f = new LCCF(8);
1226                  assertSame(f, f.fork());
1227                  assertSame(f, pollNextLocalTask());
1228                  helpQuiesce();
# Line 1166 | Line 1237 | public class CountedCompleterTest extend
1237       * pollTask returns an unexecuted task without executing it
1238       */
1239      public void testPollTask() {
1240 <       ForkJoinTask a =  new CheckedFJTask() {
1241 <            public void realCompute() {
1242 <                CCF g = new LCCF(null, 9);
1240 >        ForkJoinTask a = new CheckedRecursiveAction() {
1241 >            protected void realCompute() {
1242 >                CCF g = new LCCF(9);
1243                  assertSame(g, g.fork());
1244 <                CCF f = new LCCF(null, 8);
1244 >                CCF f = new LCCF(8);
1245                  assertSame(f, f.fork());
1246                  assertSame(f, pollTask());
1247                  helpQuiesce();
# Line 1184 | Line 1255 | public class CountedCompleterTest extend
1255       * peekNextLocalTask returns least recent unexecuted task in async mode
1256       */
1257      public void testPeekNextLocalTaskAsync() {
1258 <       ForkJoinTask a =  new CheckedFJTask() {
1259 <            public void realCompute() {
1260 <                CCF g = new LCCF(null, 9);
1258 >        ForkJoinTask a = new CheckedRecursiveAction() {
1259 >            protected void realCompute() {
1260 >                CCF g = new LCCF(9);
1261                  assertSame(g, g.fork());
1262 <                CCF f = new LCCF(null, 8);
1262 >                CCF f = new LCCF(8);
1263                  assertSame(f, f.fork());
1264                  assertSame(g, peekNextLocalTask());
1265                  assertNull(f.join());
# Line 1205 | Line 1276 | public class CountedCompleterTest extend
1276       * executing it, in async mode
1277       */
1278      public void testPollNextLocalTaskAsync() {
1279 <       ForkJoinTask a =  new CheckedFJTask() {
1280 <            public void realCompute() {
1281 <                CCF g = new LCCF(null, 9);
1279 >        ForkJoinTask a = new CheckedRecursiveAction() {
1280 >            protected void realCompute() {
1281 >                CCF g = new LCCF(9);
1282                  assertSame(g, g.fork());
1283 <                CCF f = new LCCF(null, 8);
1283 >                CCF f = new LCCF(8);
1284                  assertSame(f, f.fork());
1285                  assertSame(g, pollNextLocalTask());
1286                  helpQuiesce();
# Line 1225 | Line 1296 | public class CountedCompleterTest extend
1296       * async mode
1297       */
1298      public void testPollTaskAsync() {
1299 <       ForkJoinTask a =  new CheckedFJTask() {
1300 <            public void realCompute() {
1301 <                CCF g = new LCCF(null, 9);
1299 >        ForkJoinTask a = new CheckedRecursiveAction() {
1300 >            protected void realCompute() {
1301 >                CCF g = new LCCF(9);
1302                  assertSame(g, g.fork());
1303 <                CCF f = new LCCF(null, 8);
1303 >                CCF f = new LCCF(8);
1304                  assertSame(f, f.fork());
1305                  assertSame(g, pollTask());
1306                  helpQuiesce();
# Line 1248 | Line 1319 | public class CountedCompleterTest extend
1319       * completed tasks; getRawResult returns null.
1320       */
1321      public void testInvokeSingleton() {
1322 <       ForkJoinTask a =  new CheckedFJTask() {
1323 <            public void realCompute() {
1324 <                CCF f = new LCCF(null, 8);
1322 >        ForkJoinTask a = new CheckedRecursiveAction() {
1323 >            protected void realCompute() {
1324 >                CCF f = new LCCF(8);
1325                  assertNull(f.invoke());
1326                  assertEquals(21, f.number);
1327                  checkCompletedNormally(f);
# Line 1264 | Line 1335 | public class CountedCompleterTest extend
1335       * completed tasks
1336       */
1337      public void testQuietlyInvokeSingleton() {
1338 <       ForkJoinTask a =  new CheckedFJTask() {
1339 <            public void realCompute() {
1340 <                CCF f = new LCCF(null, 8);
1338 >        ForkJoinTask a = new CheckedRecursiveAction() {
1339 >            protected void realCompute() {
1340 >                CCF f = new LCCF(8);
1341                  f.quietlyInvoke();
1342                  assertEquals(21, f.number);
1343                  checkCompletedNormally(f);
# Line 1278 | Line 1349 | public class CountedCompleterTest extend
1349       * join of a forked task returns when task completes
1350       */
1351      public void testForkJoinSingleton() {
1352 <       ForkJoinTask a =  new CheckedFJTask() {
1353 <            public void realCompute() {
1354 <                CCF f = new LCCF(null, 8);
1352 >        ForkJoinTask a = new CheckedRecursiveAction() {
1353 >            protected void realCompute() {
1354 >                CCF f = new LCCF(8);
1355                  assertSame(f, f.fork());
1356                  assertNull(f.join());
1357                  assertEquals(21, f.number);
# Line 1293 | Line 1364 | public class CountedCompleterTest extend
1364       * get of a forked task returns when task completes
1365       */
1366      public void testForkGetSingleton() {
1367 <       ForkJoinTask a =  new CheckedFJTask() {
1368 <            public void realCompute() throws Exception {
1369 <                CCF f = new LCCF(null, 8);
1367 >        ForkJoinTask a = new CheckedRecursiveAction() {
1368 >            protected void realCompute() throws Exception {
1369 >                CCF f = new LCCF(8);
1370                  assertSame(f, f.fork());
1371                  assertNull(f.get());
1372                  assertEquals(21, f.number);
# Line 1308 | Line 1379 | public class CountedCompleterTest extend
1379       * timed get of a forked task returns when task completes
1380       */
1381      public void testForkTimedGetSingleton() {
1382 <       ForkJoinTask a =  new CheckedFJTask() {
1383 <            public void realCompute() throws Exception {
1384 <                CCF f = new LCCF(null, 8);
1382 >        ForkJoinTask a = new CheckedRecursiveAction() {
1383 >            protected void realCompute() throws Exception {
1384 >                CCF f = new LCCF(8);
1385                  assertSame(f, f.fork());
1386                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1387                  assertEquals(21, f.number);
# Line 1323 | Line 1394 | public class CountedCompleterTest extend
1394       * timed get with null time unit throws NPE
1395       */
1396      public void testForkTimedGetNPESingleton() {
1397 <       ForkJoinTask a =  new CheckedFJTask() {
1398 <            public void realCompute() throws Exception {
1399 <                CCF f = new LCCF(null, 8);
1397 >        ForkJoinTask a = new CheckedRecursiveAction() {
1398 >            protected void realCompute() throws Exception {
1399 >                CCF f = new LCCF(8);
1400                  assertSame(f, f.fork());
1401                  try {
1402                      f.get(5L, null);
# Line 1339 | Line 1410 | public class CountedCompleterTest extend
1410       * quietlyJoin of a forked task returns when task completes
1411       */
1412      public void testForkQuietlyJoinSingleton() {
1413 <       ForkJoinTask a =  new CheckedFJTask() {
1414 <            public void realCompute() {
1415 <                CCF f = new LCCF(null, 8);
1413 >        ForkJoinTask a = new CheckedRecursiveAction() {
1414 >            protected void realCompute() {
1415 >                CCF f = new LCCF(8);
1416                  assertSame(f, f.fork());
1417                  f.quietlyJoin();
1418                  assertEquals(21, f.number);
# Line 1355 | Line 1426 | public class CountedCompleterTest extend
1426       * getQueuedTaskCount returns 0 when quiescent
1427       */
1428      public void testForkHelpQuiesceSingleton() {
1429 <       ForkJoinTask a =  new CheckedFJTask() {
1430 <            public void realCompute() {
1431 <                CCF f = new LCCF(null, 8);
1429 >        ForkJoinTask a = new CheckedRecursiveAction() {
1430 >            protected void realCompute() {
1431 >                CCF f = new LCCF(8);
1432                  assertSame(f, f.fork());
1433                  helpQuiesce();
1434                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1442 | public class CountedCompleterTest extend
1442       * invoke task throws exception when task completes abnormally
1443       */
1444      public void testAbnormalInvokeSingleton() {
1445 <       ForkJoinTask a =  new CheckedFJTask() {
1446 <            public void realCompute() {
1447 <                FailingCCF f = new LFCCF(null, 8);
1445 >        ForkJoinTask a = new CheckedRecursiveAction() {
1446 >            protected void realCompute() {
1447 >                FailingCCF f = new LFCCF(8);
1448                  try {
1449                      f.invoke();
1450                      shouldThrow();
# Line 1388 | Line 1459 | public class CountedCompleterTest extend
1459       * quietlyInvoke task returns when task completes abnormally
1460       */
1461      public void testAbnormalQuietlyInvokeSingleton() {
1462 <       ForkJoinTask a =  new CheckedFJTask() {
1463 <            public void realCompute() {
1464 <                FailingCCF f = new LFCCF(null, 8);
1462 >        ForkJoinTask a = new CheckedRecursiveAction() {
1463 >            protected void realCompute() {
1464 >                FailingCCF f = new LFCCF(8);
1465                  f.quietlyInvoke();
1466                  assertTrue(f.getException() instanceof FJException);
1467                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1473 | public class CountedCompleterTest extend
1473       * join of a forked task throws exception when task completes abnormally
1474       */
1475      public void testAbnormalForkJoinSingleton() {
1476 <       ForkJoinTask a =  new CheckedFJTask() {
1477 <            public void realCompute() {
1478 <                FailingCCF f = new LFCCF(null, 8);
1476 >        ForkJoinTask a = new CheckedRecursiveAction() {
1477 >            protected void realCompute() {
1478 >                FailingCCF f = new LFCCF(8);
1479                  assertSame(f, f.fork());
1480                  try {
1481                      f.join();
# Line 1420 | Line 1491 | public class CountedCompleterTest extend
1491       * get of a forked task throws exception when task completes abnormally
1492       */
1493      public void testAbnormalForkGetSingleton() {
1494 <       ForkJoinTask a =  new CheckedFJTask() {
1495 <            public void realCompute() throws Exception {
1496 <                FailingCCF f = new LFCCF(null, 8);
1494 >        ForkJoinTask a = new CheckedRecursiveAction() {
1495 >            protected void realCompute() throws Exception {
1496 >                FailingCCF f = new LFCCF(8);
1497                  assertSame(f, f.fork());
1498                  try {
1499                      f.get();
# Line 1440 | Line 1511 | public class CountedCompleterTest extend
1511       * timed get of a forked task throws exception when task completes abnormally
1512       */
1513      public void testAbnormalForkTimedGetSingleton() {
1514 <       ForkJoinTask a =  new CheckedFJTask() {
1515 <            public void realCompute() throws Exception {
1516 <                FailingCCF f = new LFCCF(null, 8);
1514 >        ForkJoinTask a = new CheckedRecursiveAction() {
1515 >            protected void realCompute() throws Exception {
1516 >                FailingCCF f = new LFCCF(8);
1517                  assertSame(f, f.fork());
1518                  try {
1519                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1531 | public class CountedCompleterTest extend
1531       * quietlyJoin of a forked task returns when task completes abnormally
1532       */
1533      public void testAbnormalForkQuietlyJoinSingleton() {
1534 <       ForkJoinTask a =  new CheckedFJTask() {
1535 <            public void realCompute() {
1536 <                FailingCCF f = new LFCCF(null, 8);
1534 >        ForkJoinTask a = new CheckedRecursiveAction() {
1535 >            protected void realCompute() {
1536 >                FailingCCF f = new LFCCF(8);
1537                  assertSame(f, f.fork());
1538                  f.quietlyJoin();
1539                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1546 | public class CountedCompleterTest extend
1546       * invoke task throws exception when task cancelled
1547       */
1548      public void testCancelledInvokeSingleton() {
1549 <       ForkJoinTask a =  new CheckedFJTask() {
1550 <            public void realCompute() {
1551 <                CCF f = new LCCF(null, 8);
1549 >        ForkJoinTask a = new CheckedRecursiveAction() {
1550 >            protected void realCompute() {
1551 >                CCF f = new LCCF(8);
1552                  assertTrue(f.cancel(true));
1553                  try {
1554                      f.invoke();
# Line 1493 | Line 1564 | public class CountedCompleterTest extend
1564       * join of a forked task throws exception when task cancelled
1565       */
1566      public void testCancelledForkJoinSingleton() {
1567 <       ForkJoinTask a =  new CheckedFJTask() {
1568 <            public void realCompute() {
1569 <                CCF f = new LCCF(null, 8);
1567 >        ForkJoinTask a = new CheckedRecursiveAction() {
1568 >            protected void realCompute() {
1569 >                CCF f = new LCCF(8);
1570                  assertTrue(f.cancel(true));
1571                  assertSame(f, f.fork());
1572                  try {
# Line 1512 | Line 1583 | public class CountedCompleterTest extend
1583       * get of a forked task throws exception when task cancelled
1584       */
1585      public void testCancelledForkGetSingleton() {
1586 <       ForkJoinTask a =  new CheckedFJTask() {
1587 <            public void realCompute() throws Exception {
1588 <                CCF f = new LCCF(null, 8);
1586 >        ForkJoinTask a = new CheckedRecursiveAction() {
1587 >            protected void realCompute() throws Exception {
1588 >                CCF f = new LCCF(8);
1589                  assertTrue(f.cancel(true));
1590                  assertSame(f, f.fork());
1591                  try {
# Line 1531 | Line 1602 | public class CountedCompleterTest extend
1602       * timed get of a forked task throws exception when task cancelled
1603       */
1604      public void testCancelledForkTimedGetSingleton() throws Exception {
1605 <       ForkJoinTask a =  new CheckedFJTask() {
1606 <            public void realCompute() throws Exception {
1607 <                CCF f = new LCCF(null, 8);
1605 >        ForkJoinTask a = new CheckedRecursiveAction() {
1606 >            protected void realCompute() throws Exception {
1607 >                CCF f = new LCCF(8);
1608                  assertTrue(f.cancel(true));
1609                  assertSame(f, f.fork());
1610                  try {
# Line 1550 | Line 1621 | public class CountedCompleterTest extend
1621       * quietlyJoin of a forked task returns when task cancelled
1622       */
1623      public void testCancelledForkQuietlyJoinSingleton() {
1624 <       ForkJoinTask a =  new CheckedFJTask() {
1625 <            public void realCompute() {
1626 <                CCF f = new LCCF(null, 8);
1624 >        ForkJoinTask a = new CheckedRecursiveAction() {
1625 >            protected void realCompute() {
1626 >                CCF f = new LCCF(8);
1627                  assertTrue(f.cancel(true));
1628                  assertSame(f, f.fork());
1629                  f.quietlyJoin();
# Line 1565 | Line 1636 | public class CountedCompleterTest extend
1636       * invoke task throws exception after invoking completeExceptionally
1637       */
1638      public void testCompleteExceptionallySingleton() {
1639 <       ForkJoinTask a =  new CheckedFJTask() {
1640 <            public void realCompute() {
1641 <                CCF f = new LCCF(null, 8);
1642 <                f.completeExceptionally(new FJException());
1643 <                try {
1644 <                    f.invoke();
1645 <                    shouldThrow();
1646 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1639 >        ForkJoinTask a = new CheckedRecursiveAction() {
1640 >            protected void realCompute() {
1641 >                CCF n = new LCCF(8);
1642 >                CCF f = new LCCF(n, 8);
1643 >                FJException ex = new FJException();
1644 >                f.completeExceptionally(ex);
1645 >                f.checkCompletedExceptionally(ex);
1646 >                n.checkCompletedExceptionally(ex);
1647              }};
1648          testInvokeOnPool(singletonPool(), a);
1649      }
# Line 1583 | Line 1652 | public class CountedCompleterTest extend
1652       * invokeAll(t1, t2) invokes all task arguments
1653       */
1654      public void testInvokeAll2Singleton() {
1655 <       ForkJoinTask a =  new CheckedFJTask() {
1656 <            public void realCompute() {
1657 <                CCF f = new LCCF(null, 8);
1658 <                CCF g = new LCCF(null, 9);
1655 >        ForkJoinTask a = new CheckedRecursiveAction() {
1656 >            protected void realCompute() {
1657 >                CCF f = new LCCF(8);
1658 >                CCF g = new LCCF(9);
1659                  invokeAll(f, g);
1660                  assertEquals(21, f.number);
1661                  assertEquals(34, g.number);
# Line 1600 | Line 1669 | public class CountedCompleterTest extend
1669       * invokeAll(tasks) with 1 argument invokes task
1670       */
1671      public void testInvokeAll1Singleton() {
1672 <       ForkJoinTask a =  new CheckedFJTask() {
1673 <            public void realCompute() {
1674 <                CCF f = new LCCF(null, 8);
1672 >        ForkJoinTask a = new CheckedRecursiveAction() {
1673 >            protected void realCompute() {
1674 >                CCF f = new LCCF(8);
1675                  invokeAll(f);
1676                  checkCompletedNormally(f);
1677                  assertEquals(21, f.number);
# Line 1614 | Line 1683 | public class CountedCompleterTest extend
1683       * invokeAll(tasks) with > 2 argument invokes tasks
1684       */
1685      public void testInvokeAll3Singleton() {
1686 <       ForkJoinTask a =  new CheckedFJTask() {
1687 <            public void realCompute() {
1688 <                CCF f = new LCCF(null, 8);
1689 <                CCF g = new LCCF(null, 9);
1690 <                CCF h = new LCCF(null, 7);
1686 >        ForkJoinTask a = new CheckedRecursiveAction() {
1687 >            protected void realCompute() {
1688 >                CCF f = new LCCF(8);
1689 >                CCF g = new LCCF(9);
1690 >                CCF h = new LCCF(7);
1691                  invokeAll(f, g, h);
1692                  assertEquals(21, f.number);
1693                  assertEquals(34, g.number);
# Line 1634 | Line 1703 | public class CountedCompleterTest extend
1703       * invokeAll(collection) invokes all tasks in the collection
1704       */
1705      public void testInvokeAllCollectionSingleton() {
1706 <       ForkJoinTask a =  new CheckedFJTask() {
1707 <            public void realCompute() {
1708 <                CCF f = new LCCF(null, 8);
1709 <                CCF g = new LCCF(null, 9);
1710 <                CCF h = new LCCF(null, 7);
1706 >        ForkJoinTask a = new CheckedRecursiveAction() {
1707 >            protected void realCompute() {
1708 >                CCF f = new LCCF(8);
1709 >                CCF g = new LCCF(9);
1710 >                CCF h = new LCCF(7);
1711                  HashSet set = new HashSet();
1712                  set.add(f);
1713                  set.add(g);
# Line 1658 | Line 1727 | public class CountedCompleterTest extend
1727       * invokeAll(tasks) with any null task throws NPE
1728       */
1729      public void testInvokeAllNPESingleton() {
1730 <       ForkJoinTask a =  new CheckedFJTask() {
1731 <            public void realCompute() {
1732 <                CCF f = new LCCF(null, 8);
1733 <                CCF g = new LCCF(null, 9);
1730 >        ForkJoinTask a = new CheckedRecursiveAction() {
1731 >            protected void realCompute() {
1732 >                CCF f = new LCCF(8);
1733 >                CCF g = new LCCF(9);
1734                  CCF h = null;
1735                  try {
1736                      invokeAll(f, g, h);
# Line 1675 | Line 1744 | public class CountedCompleterTest extend
1744       * invokeAll(t1, t2) throw exception if any task does
1745       */
1746      public void testAbnormalInvokeAll2Singleton() {
1747 <       ForkJoinTask a =  new CheckedFJTask() {
1748 <            public void realCompute() {
1749 <                CCF f = new LCCF(null, 8);
1750 <                FailingCCF g = new LFCCF(null, 9);
1747 >        ForkJoinTask a = new CheckedRecursiveAction() {
1748 >            protected void realCompute() {
1749 >                CCF f = new LCCF(8);
1750 >                FailingCCF g = new LFCCF(9);
1751                  try {
1752                      invokeAll(f, g);
1753                      shouldThrow();
# Line 1693 | Line 1762 | public class CountedCompleterTest extend
1762       * invokeAll(tasks) with 1 argument throws exception if task does
1763       */
1764      public void testAbnormalInvokeAll1Singleton() {
1765 <       ForkJoinTask a =  new CheckedFJTask() {
1766 <            public void realCompute() {
1767 <                FailingCCF g = new LFCCF(null, 9);
1765 >        ForkJoinTask a = new CheckedRecursiveAction() {
1766 >            protected void realCompute() {
1767 >                FailingCCF g = new LFCCF(9);
1768                  try {
1769                      invokeAll(g);
1770                      shouldThrow();
# Line 1710 | Line 1779 | public class CountedCompleterTest extend
1779       * invokeAll(tasks) with > 2 argument throws exception if any task does
1780       */
1781      public void testAbnormalInvokeAll3Singleton() {
1782 <       ForkJoinTask a =  new CheckedFJTask() {
1783 <            public void realCompute() {
1784 <                CCF f = new LCCF(null, 8);
1785 <                FailingCCF g = new LFCCF(null, 9);
1786 <                CCF h = new LCCF(null, 7);
1782 >        ForkJoinTask a = new CheckedRecursiveAction() {
1783 >            protected void realCompute() {
1784 >                CCF f = new LCCF(8);
1785 >                FailingCCF g = new LFCCF(9);
1786 >                CCF h = new LCCF(7);
1787                  try {
1788                      invokeAll(f, g, h);
1789                      shouldThrow();
# Line 1729 | Line 1798 | public class CountedCompleterTest extend
1798       * invokeAll(collection)  throws exception if any task does
1799       */
1800      public void testAbnormalInvokeAllCollectionSingleton() {
1801 <       ForkJoinTask a =  new CheckedFJTask() {
1802 <            public void realCompute() {
1803 <                FailingCCF f = new LFCCF(null, 8);
1804 <                CCF g = new LCCF(null, 9);
1805 <                CCF h = new LCCF(null, 7);
1801 >        ForkJoinTask a = new CheckedRecursiveAction() {
1802 >            protected void realCompute() {
1803 >                FailingCCF f = new LFCCF(8);
1804 >                CCF g = new LCCF(9);
1805 >                CCF h = new LCCF(7);
1806                  HashSet set = new HashSet();
1807                  set.add(f);
1808                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines