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.5 by jsr166, Tue Apr 16 05:49:18 2013 UTC vs.
Revision 1.8 by jsr166, Tue Jun 4 23:07:11 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;
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  
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  
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 invoking
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 decrements 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());
# Line 385 | Line 454 | public class CountedCompleterTest extend
454       * zero else null
455       */
456      public void testNextComplete() {
457 <        NoopCountedCompleter a = new NoopCountedCompleter();
458 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
457 >        NoopCC a = new NoopCC();
458 >        NoopCC b = new NoopCC(a);
459          a.setPendingCount(1);
460          b.setPendingCount(1);
461          assertNull(b.firstComplete());
462          CountedCompleter c = b.firstComplete();
463 <        assertEquals(b, c);
463 >        assertSame(b, c);
464          CountedCompleter d = c.nextComplete();
465          assertNull(d);
466          CountedCompleter e = c.nextComplete();
467 <        assertEquals(a, e);
467 >        assertSame(a, e);
468      }
469  
470      /**
471       * quietlyCompleteRoot completes root task
472       */
473      public void testQuietlyCompleteRoot() {
474 <        NoopCountedCompleter a = new NoopCountedCompleter();
475 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
474 >        NoopCC a = new NoopCC();
475 >        NoopCC b = new NoopCC(a);
476 >        NoopCC c = new NoopCC(b);
477          a.setPendingCount(1);
478          b.setPendingCount(1);
479 <        b.quietlyCompleteRoot();
479 >        c.setPendingCount(1);
480 >        c.quietlyCompleteRoot();
481          assertTrue(a.isDone());
482          assertFalse(b.isDone());
483 +        assertFalse(c.isDone());
484      }
485  
486      // Invocation tests use some interdependent task classes
# Line 416 | Line 488 | public class CountedCompleterTest extend
488  
489  
490      // Version of Fibonacci with different classes for left vs right forks
491 <    abstract static class CCF extends CountedCompleter {
491 >    abstract class CCF extends CheckedCC {
492          int number;
493          int rnumber;
494  
# Line 425 | Line 497 | public class CountedCompleterTest extend
497              this.number = n;
498          }
499  
500 <        public final void compute() {
429 <            CountedCompleter p;
500 >        protected final void realCompute() {
501              CCF f = this;
502              int n = number;
503              while (n >= 2) {
504                  new RCCF(f, n - 2).fork();
505                  f = new LCCF(f, --n);
506              }
507 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
507 >            f.complete(null);
508          }
509      }
510  
511 <    static final class LCCF extends CCF {
511 >    final class LCCF extends CCF {
512 >        public LCCF(int n) { this(null, n); }
513          public LCCF(CountedCompleter parent, int n) {
514              super(parent, n);
515          }
516          public final void onCompletion(CountedCompleter caller) {
517 +            super.onCompletion(caller);
518              CCF p = (CCF)getCompleter();
519              int n = number + rnumber;
520              if (p != null)
# Line 455 | Line 523 | public class CountedCompleterTest extend
523                  number = n;
524          }
525      }
526 <    static final class RCCF extends CCF {
526 >    final class RCCF extends CCF {
527          public RCCF(CountedCompleter parent, int n) {
528              super(parent, n);
529          }
530          public final void onCompletion(CountedCompleter caller) {
531 +            super.onCompletion(caller);
532              CCF p = (CCF)getCompleter();
533              int n = number + rnumber;
534              if (p != null)
# Line 470 | Line 539 | public class CountedCompleterTest extend
539      }
540  
541      // Version of CCF with forced failure in left completions
542 <    abstract static class FailingCCF extends CountedCompleter {
542 >    abstract class FailingCCF extends CheckedCC {
543          int number;
544          int rnumber;
545  
# Line 479 | Line 548 | public class CountedCompleterTest extend
548              this.number = n;
549          }
550  
551 <        public final void compute() {
483 <            CountedCompleter p;
551 >        protected final void realCompute() {
552              FailingCCF f = this;
553              int n = number;
554              while (n >= 2) {
555                  new RFCCF(f, n - 2).fork();
556                  f = new LFCCF(f, --n);
557              }
558 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
558 >            f.complete(null);
559          }
560      }
561  
562 <    static final class LFCCF extends FailingCCF {
562 >    final class LFCCF extends FailingCCF {
563 >        public LFCCF(int n) { this(null, n); }
564          public LFCCF(CountedCompleter parent, int n) {
565              super(parent, n);
566          }
567          public final void onCompletion(CountedCompleter caller) {
568 +            super.onCompletion(caller);
569              FailingCCF p = (FailingCCF)getCompleter();
570              int n = number + rnumber;
571              if (p != null)
# Line 509 | Line 574 | public class CountedCompleterTest extend
574                  number = n;
575          }
576      }
577 <    static final class RFCCF extends FailingCCF {
577 >    final class RFCCF extends FailingCCF {
578          public RFCCF(CountedCompleter parent, int n) {
579              super(parent, n);
580          }
581          public final void onCompletion(CountedCompleter caller) {
582 +            super.onCompletion(caller);
583              completeExceptionally(new FJException());
584          }
585      }
# Line 524 | Line 590 | public class CountedCompleterTest extend
590       * completed tasks; getRawResult returns null.
591       */
592      public void testInvoke() {
593 <       ForkJoinTask a = new CheckedFJTask() {
594 <            public void realCompute() {
595 <                CCF f = new LCCF(null, 8);
593 >        ForkJoinTask a = new CheckedRecursiveAction() {
594 >            protected void realCompute() {
595 >                CCF f = new LCCF(8);
596                  assertNull(f.invoke());
597                  assertEquals(21, f.number);
598                  checkCompletedNormally(f);
# Line 540 | Line 606 | public class CountedCompleterTest extend
606       * completed tasks
607       */
608      public void testQuietlyInvoke() {
609 <       ForkJoinTask a = new CheckedFJTask() {
610 <            public void realCompute() {
611 <                CCF f = new LCCF(null, 8);
609 >        ForkJoinTask a = new CheckedRecursiveAction() {
610 >            protected void realCompute() {
611 >                CCF f = new LCCF(8);
612                  f.quietlyInvoke();
613                  assertEquals(21, f.number);
614                  checkCompletedNormally(f);
# Line 554 | Line 620 | public class CountedCompleterTest extend
620       * join of a forked task returns when task completes
621       */
622      public void testForkJoin() {
623 <       ForkJoinTask a = new CheckedFJTask() {
624 <            public void realCompute() {
625 <                CCF f = new LCCF(null, 8);
623 >        ForkJoinTask a = new CheckedRecursiveAction() {
624 >            protected void realCompute() {
625 >                CCF f = new LCCF(8);
626                  assertSame(f, f.fork());
627                  assertNull(f.join());
628                  assertEquals(21, f.number);
# Line 569 | Line 635 | public class CountedCompleterTest extend
635       * get of a forked task returns when task completes
636       */
637      public void testForkGet() {
638 <       ForkJoinTask a = new CheckedFJTask() {
639 <            public void realCompute() throws Exception {
640 <                CCF f = new LCCF(null, 8);
638 >        ForkJoinTask a = new CheckedRecursiveAction() {
639 >            protected void realCompute() throws Exception {
640 >                CCF f = new LCCF(8);
641                  assertSame(f, f.fork());
642                  assertNull(f.get());
643                  assertEquals(21, f.number);
# Line 584 | Line 650 | public class CountedCompleterTest extend
650       * timed get of a forked task returns when task completes
651       */
652      public void testForkTimedGet() {
653 <       ForkJoinTask a = new CheckedFJTask() {
654 <            public void realCompute() throws Exception {
655 <                CCF f = new LCCF(null, 8);
653 >        ForkJoinTask a = new CheckedRecursiveAction() {
654 >            protected void realCompute() throws Exception {
655 >                CCF f = new LCCF(8);
656                  assertSame(f, f.fork());
657                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
658                  assertEquals(21, f.number);
# Line 599 | Line 665 | public class CountedCompleterTest extend
665       * timed get with null time unit throws NPE
666       */
667      public void testForkTimedGetNPE() {
668 <       ForkJoinTask a = new CheckedFJTask() {
669 <            public void realCompute() throws Exception {
670 <                CCF f = new LCCF(null, 8);
668 >        ForkJoinTask a = new CheckedRecursiveAction() {
669 >            protected void realCompute() throws Exception {
670 >                CCF f = new LCCF(8);
671                  assertSame(f, f.fork());
672                  try {
673                      f.get(5L, null);
# Line 615 | Line 681 | public class CountedCompleterTest extend
681       * quietlyJoin of a forked task returns when task completes
682       */
683      public void testForkQuietlyJoin() {
684 <       ForkJoinTask a = new CheckedFJTask() {
685 <            public void realCompute() {
686 <                CCF f = new LCCF(null, 8);
684 >        ForkJoinTask a = new CheckedRecursiveAction() {
685 >            protected void realCompute() {
686 >                CCF f = new LCCF(8);
687                  assertSame(f, f.fork());
688                  f.quietlyJoin();
689                  assertEquals(21, f.number);
# Line 631 | Line 697 | public class CountedCompleterTest extend
697       * getQueuedTaskCount returns 0 when quiescent
698       */
699      public void testForkHelpQuiesce() {
700 <       ForkJoinTask a = new CheckedFJTask() {
701 <            public void realCompute() {
702 <                CCF f = new LCCF(null, 8);
700 >        ForkJoinTask a = new CheckedRecursiveAction() {
701 >            protected void realCompute() {
702 >                CCF f = new LCCF(8);
703                  assertSame(f, f.fork());
704                  helpQuiesce();
705                  assertEquals(21, f.number);
# Line 647 | Line 713 | public class CountedCompleterTest extend
713       * invoke task throws exception when task completes abnormally
714       */
715      public void testAbnormalInvoke() {
716 <       ForkJoinTask a = new CheckedFJTask() {
717 <            public void realCompute() {
718 <                FailingCCF f = new LFCCF(null, 8);
716 >        ForkJoinTask a = new CheckedRecursiveAction() {
717 >            protected void realCompute() {
718 >                FailingCCF f = new LFCCF(8);
719                  try {
720                      f.invoke();
721                      shouldThrow();
# Line 664 | Line 730 | public class CountedCompleterTest extend
730       * quietlyInvoke task returns when task completes abnormally
731       */
732      public void testAbnormalQuietlyInvoke() {
733 <       ForkJoinTask a = new CheckedFJTask() {
734 <            public void realCompute() {
735 <                FailingCCF f = new LFCCF(null, 8);
733 >        ForkJoinTask a = new CheckedRecursiveAction() {
734 >            protected void realCompute() {
735 >                FailingCCF f = new LFCCF(8);
736                  f.quietlyInvoke();
737                  assertTrue(f.getException() instanceof FJException);
738                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 744 | public class CountedCompleterTest extend
744       * join of a forked task throws exception when task completes abnormally
745       */
746      public void testAbnormalForkJoin() {
747 <       ForkJoinTask a = new CheckedFJTask() {
748 <            public void realCompute() {
749 <                FailingCCF f = new LFCCF(null, 8);
747 >        ForkJoinTask a = new CheckedRecursiveAction() {
748 >            protected void realCompute() {
749 >                FailingCCF f = new LFCCF(8);
750                  assertSame(f, f.fork());
751                  try {
752                      f.join();
# Line 696 | Line 762 | public class CountedCompleterTest extend
762       * get of a forked task throws exception when task completes abnormally
763       */
764      public void testAbnormalForkGet() {
765 <       ForkJoinTask a = new CheckedFJTask() {
766 <            public void realCompute() throws Exception {
767 <                FailingCCF f = new LFCCF(null, 8);
765 >        ForkJoinTask a = new CheckedRecursiveAction() {
766 >            protected void realCompute() throws Exception {
767 >                FailingCCF f = new LFCCF(8);
768                  assertSame(f, f.fork());
769                  try {
770                      f.get();
# Line 716 | Line 782 | public class CountedCompleterTest extend
782       * timed get of a forked task throws exception when task completes abnormally
783       */
784      public void testAbnormalForkTimedGet() {
785 <       ForkJoinTask a = new CheckedFJTask() {
786 <            public void realCompute() throws Exception {
787 <                FailingCCF f = new LFCCF(null, 8);
785 >        ForkJoinTask a = new CheckedRecursiveAction() {
786 >            protected void realCompute() throws Exception {
787 >                FailingCCF f = new LFCCF(8);
788                  assertSame(f, f.fork());
789                  try {
790                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 802 | public class CountedCompleterTest extend
802       * quietlyJoin of a forked task returns when task completes abnormally
803       */
804      public void testAbnormalForkQuietlyJoin() {
805 <       ForkJoinTask a = new CheckedFJTask() {
806 <            public void realCompute() {
807 <                FailingCCF f = new LFCCF(null, 8);
805 >        ForkJoinTask a = new CheckedRecursiveAction() {
806 >            protected void realCompute() {
807 >                FailingCCF f = new LFCCF(8);
808                  assertSame(f, f.fork());
809                  f.quietlyJoin();
810                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 817 | public class CountedCompleterTest extend
817       * invoke task throws exception when task cancelled
818       */
819      public void testCancelledInvoke() {
820 <       ForkJoinTask a = new CheckedFJTask() {
821 <            public void realCompute() {
822 <                CCF f = new LCCF(null, 8);
820 >        ForkJoinTask a = new CheckedRecursiveAction() {
821 >            protected void realCompute() {
822 >                CCF f = new LCCF(8);
823                  assertTrue(f.cancel(true));
824                  try {
825                      f.invoke();
# Line 769 | Line 835 | public class CountedCompleterTest extend
835       * join of a forked task throws exception when task cancelled
836       */
837      public void testCancelledForkJoin() {
838 <       ForkJoinTask a = new CheckedFJTask() {
839 <            public void realCompute() {
840 <                CCF f = new LCCF(null, 8);
838 >        ForkJoinTask a = new CheckedRecursiveAction() {
839 >            protected void realCompute() {
840 >                CCF f = new LCCF(8);
841                  assertTrue(f.cancel(true));
842                  assertSame(f, f.fork());
843                  try {
# Line 788 | Line 854 | public class CountedCompleterTest extend
854       * get of a forked task throws exception when task cancelled
855       */
856      public void testCancelledForkGet() {
857 <       ForkJoinTask a = new CheckedFJTask() {
858 <            public void realCompute() throws Exception {
859 <                CCF f = new LCCF(null, 8);
857 >        ForkJoinTask a = new CheckedRecursiveAction() {
858 >            protected void realCompute() throws Exception {
859 >                CCF f = new LCCF(8);
860                  assertTrue(f.cancel(true));
861                  assertSame(f, f.fork());
862                  try {
# Line 807 | Line 873 | public class CountedCompleterTest extend
873       * timed get of a forked task throws exception when task cancelled
874       */
875      public void testCancelledForkTimedGet() throws Exception {
876 <       ForkJoinTask a = new CheckedFJTask() {
877 <            public void realCompute() throws Exception {
878 <                CCF f = new LCCF(null, 8);
876 >        ForkJoinTask a = new CheckedRecursiveAction() {
877 >            protected void realCompute() throws Exception {
878 >                CCF f = new LCCF(8);
879                  assertTrue(f.cancel(true));
880                  assertSame(f, f.fork());
881                  try {
# Line 826 | Line 892 | public class CountedCompleterTest extend
892       * quietlyJoin of a forked task returns when task cancelled
893       */
894      public void testCancelledForkQuietlyJoin() {
895 <       ForkJoinTask a = new CheckedFJTask() {
896 <            public void realCompute() {
897 <                CCF f = new LCCF(null, 8);
895 >        ForkJoinTask a = new CheckedRecursiveAction() {
896 >            protected void realCompute() {
897 >                CCF f = new LCCF(8);
898                  assertTrue(f.cancel(true));
899                  assertSame(f, f.fork());
900                  f.quietlyJoin();
# Line 842 | Line 908 | public class CountedCompleterTest extend
908       */
909      public void testGetPool() {
910          final ForkJoinPool mainPool = mainPool();
911 <       ForkJoinTask a = new CheckedFJTask() {
912 <            public void realCompute() {
911 >        ForkJoinTask a = new CheckedRecursiveAction() {
912 >            protected void realCompute() {
913                  assertSame(mainPool, getPool());
914              }};
915          testInvokeOnPool(mainPool, a);
# Line 853 | Line 919 | public class CountedCompleterTest extend
919       * getPool of non-FJ task returns null
920       */
921      public void testGetPool2() {
922 <       ForkJoinTask a = new CheckedFJTask() {
923 <            public void realCompute() {
922 >        ForkJoinTask a = new CheckedRecursiveAction() {
923 >            protected void realCompute() {
924                  assertNull(getPool());
925              }};
926          assertNull(a.invoke());
# Line 864 | Line 930 | public class CountedCompleterTest extend
930       * inForkJoinPool of executing task returns true
931       */
932      public void testInForkJoinPool() {
933 <       ForkJoinTask a = new CheckedFJTask() {
934 <            public void realCompute() {
933 >        ForkJoinTask a = new CheckedRecursiveAction() {
934 >            protected void realCompute() {
935                  assertTrue(inForkJoinPool());
936              }};
937          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 941 | public class CountedCompleterTest extend
941       * inForkJoinPool of non-FJ task returns false
942       */
943      public void testInForkJoinPool2() {
944 <       ForkJoinTask a = new CheckedFJTask() {
945 <            public void realCompute() {
944 >        ForkJoinTask a = new CheckedRecursiveAction() {
945 >            protected void realCompute() {
946                  assertFalse(inForkJoinPool());
947              }};
948          assertNull(a.invoke());
# Line 886 | Line 952 | public class CountedCompleterTest extend
952       * setRawResult(null) succeeds
953       */
954      public void testSetRawResult() {
955 <       ForkJoinTask a = new CheckedFJTask() {
956 <            public void realCompute() {
955 >        ForkJoinTask a = new CheckedRecursiveAction() {
956 >            protected void realCompute() {
957                  setRawResult(null);
958                  assertNull(getRawResult());
959              }};
# Line 898 | Line 964 | public class CountedCompleterTest extend
964       * invoke task throws exception after invoking completeExceptionally
965       */
966      public void testCompleteExceptionally2() {
967 <       ForkJoinTask a = new CheckedFJTask() {
968 <            public void realCompute() {
969 <                CCF f = new LCCF(null, 8);
970 <                f.completeExceptionally(new FJException());
971 <                try {
972 <                    f.invoke();
973 <                    shouldThrow();
974 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
967 >        ForkJoinTask a = new CheckedRecursiveAction() {
968 >            protected void realCompute() {
969 >                CCF n = new LCCF(8);
970 >                CCF f = new LCCF(n, 8);
971 >                FJException ex = new FJException();
972 >                f.completeExceptionally(ex);
973 >                f.checkCompletedExceptionally(ex);
974 >                n.checkCompletedExceptionally(ex);
975              }};
976          testInvokeOnPool(mainPool(), a);
977      }
# Line 916 | Line 980 | public class CountedCompleterTest extend
980       * invokeAll(t1, t2) invokes all task arguments
981       */
982      public void testInvokeAll2() {
983 <       ForkJoinTask a = new CheckedFJTask() {
984 <            public void realCompute() {
985 <                CCF f = new LCCF(null, 8);
986 <                CCF g = new LCCF(null, 9);
983 >        ForkJoinTask a = new CheckedRecursiveAction() {
984 >            protected void realCompute() {
985 >                CCF f = new LCCF(8);
986 >                CCF g = new LCCF(9);
987                  invokeAll(f, g);
988                  assertEquals(21, f.number);
989                  assertEquals(34, g.number);
# Line 933 | Line 997 | public class CountedCompleterTest extend
997       * invokeAll(tasks) with 1 argument invokes task
998       */
999      public void testInvokeAll1() {
1000 <       ForkJoinTask a = new CheckedFJTask() {
1001 <            public void realCompute() {
1002 <                CCF f = new LCCF(null, 8);
1000 >        ForkJoinTask a = new CheckedRecursiveAction() {
1001 >            protected void realCompute() {
1002 >                CCF f = new LCCF(8);
1003                  invokeAll(f);
1004                  checkCompletedNormally(f);
1005                  assertEquals(21, f.number);
# Line 947 | Line 1011 | public class CountedCompleterTest extend
1011       * invokeAll(tasks) with > 2 argument invokes tasks
1012       */
1013      public void testInvokeAll3() {
1014 <       ForkJoinTask a = new CheckedFJTask() {
1015 <            public void realCompute() {
1016 <                CCF f = new LCCF(null, 8);
1017 <                CCF g = new LCCF(null, 9);
1018 <                CCF h = new LCCF(null, 7);
1014 >        ForkJoinTask a = new CheckedRecursiveAction() {
1015 >            protected void realCompute() {
1016 >                CCF f = new LCCF(8);
1017 >                CCF g = new LCCF(9);
1018 >                CCF h = new LCCF(7);
1019                  invokeAll(f, g, h);
1020                  assertEquals(21, f.number);
1021                  assertEquals(34, g.number);
# Line 967 | Line 1031 | public class CountedCompleterTest extend
1031       * invokeAll(collection) invokes all tasks in the collection
1032       */
1033      public void testInvokeAllCollection() {
1034 <       ForkJoinTask a = new CheckedFJTask() {
1035 <            public void realCompute() {
1036 <                CCF f = new LCCF(null, 8);
1037 <                CCF g = new LCCF(null, 9);
1038 <                CCF h = new LCCF(null, 7);
1034 >        ForkJoinTask a = new CheckedRecursiveAction() {
1035 >            protected void realCompute() {
1036 >                CCF f = new LCCF(8);
1037 >                CCF g = new LCCF(9);
1038 >                CCF h = new LCCF(7);
1039                  HashSet set = new HashSet();
1040                  set.add(f);
1041                  set.add(g);
# Line 991 | Line 1055 | public class CountedCompleterTest extend
1055       * invokeAll(tasks) with any null task throws NPE
1056       */
1057      public void testInvokeAllNPE() {
1058 <       ForkJoinTask a = new CheckedFJTask() {
1059 <            public void realCompute() {
1060 <                CCF f = new LCCF(null, 8);
1061 <                CCF g = new LCCF(null, 9);
1058 >        ForkJoinTask a = new CheckedRecursiveAction() {
1059 >            protected void realCompute() {
1060 >                CCF f = new LCCF(8);
1061 >                CCF g = new LCCF(9);
1062                  CCF h = null;
1063                  try {
1064                      invokeAll(f, g, h);
# Line 1008 | Line 1072 | public class CountedCompleterTest extend
1072       * invokeAll(t1, t2) throw exception if any task does
1073       */
1074      public void testAbnormalInvokeAll2() {
1075 <       ForkJoinTask a = new CheckedFJTask() {
1076 <            public void realCompute() {
1077 <                CCF f = new LCCF(null, 8);
1078 <                FailingCCF g = new LFCCF(null, 9);
1075 >        ForkJoinTask a = new CheckedRecursiveAction() {
1076 >            protected void realCompute() {
1077 >                CCF f = new LCCF(8);
1078 >                FailingCCF g = new LFCCF(9);
1079                  try {
1080                      invokeAll(f, g);
1081                      shouldThrow();
# Line 1026 | Line 1090 | public class CountedCompleterTest extend
1090       * invokeAll(tasks) with 1 argument throws exception if task does
1091       */
1092      public void testAbnormalInvokeAll1() {
1093 <       ForkJoinTask a = new CheckedFJTask() {
1094 <            public void realCompute() {
1095 <                FailingCCF g = new LFCCF(null, 9);
1093 >        ForkJoinTask a = new CheckedRecursiveAction() {
1094 >            protected void realCompute() {
1095 >                FailingCCF g = new LFCCF(9);
1096                  try {
1097                      invokeAll(g);
1098                      shouldThrow();
# Line 1043 | Line 1107 | public class CountedCompleterTest extend
1107       * invokeAll(tasks) with > 2 argument throws exception if any task does
1108       */
1109      public void testAbnormalInvokeAll3() {
1110 <       ForkJoinTask a = new CheckedFJTask() {
1111 <            public void realCompute() {
1112 <                CCF f = new LCCF(null, 8);
1113 <                FailingCCF g = new LFCCF(null, 9);
1114 <                CCF h = new LCCF(null, 7);
1110 >        ForkJoinTask a = new CheckedRecursiveAction() {
1111 >            protected void realCompute() {
1112 >                CCF f = new LCCF(8);
1113 >                FailingCCF g = new LFCCF(9);
1114 >                CCF h = new LCCF(7);
1115                  try {
1116                      invokeAll(f, g, h);
1117                      shouldThrow();
# Line 1062 | Line 1126 | public class CountedCompleterTest extend
1126       * invokeAll(collection)  throws exception if any task does
1127       */
1128      public void testAbnormalInvokeAllCollection() {
1129 <       ForkJoinTask a = new CheckedFJTask() {
1130 <            public void realCompute() {
1131 <                FailingCCF f = new LFCCF(null, 8);
1132 <                CCF g = new LCCF(null, 9);
1133 <                CCF h = new LCCF(null, 7);
1129 >        ForkJoinTask a = new CheckedRecursiveAction() {
1130 >            protected void realCompute() {
1131 >                FailingCCF f = new LFCCF(8);
1132 >                CCF g = new LCCF(9);
1133 >                CCF h = new LCCF(7);
1134                  HashSet set = new HashSet();
1135                  set.add(f);
1136                  set.add(g);
# Line 1086 | Line 1150 | public class CountedCompleterTest extend
1150       * and suppresses execution
1151       */
1152      public void testTryUnfork() {
1153 <       ForkJoinTask a = new CheckedFJTask() {
1154 <            public void realCompute() {
1155 <                CCF g = new LCCF(null, 9);
1153 >        ForkJoinTask a = new CheckedRecursiveAction() {
1154 >            protected void realCompute() {
1155 >                CCF g = new LCCF(9);
1156                  assertSame(g, g.fork());
1157 <                CCF f = new LCCF(null, 8);
1157 >                CCF f = new LCCF(8);
1158                  assertSame(f, f.fork());
1159                  assertTrue(f.tryUnfork());
1160                  helpQuiesce();
# Line 1105 | Line 1169 | public class CountedCompleterTest extend
1169       * there are more tasks than threads
1170       */
1171      public void testGetSurplusQueuedTaskCount() {
1172 <       ForkJoinTask a = new CheckedFJTask() {
1173 <            public void realCompute() {
1174 <                CCF h = new LCCF(null, 7);
1172 >        ForkJoinTask a = new CheckedRecursiveAction() {
1173 >            protected void realCompute() {
1174 >                CCF h = new LCCF(7);
1175                  assertSame(h, h.fork());
1176 <                CCF g = new LCCF(null, 9);
1176 >                CCF g = new LCCF(9);
1177                  assertSame(g, g.fork());
1178 <                CCF f = new LCCF(null, 8);
1178 >                CCF f = new LCCF(8);
1179                  assertSame(f, f.fork());
1180                  assertTrue(getSurplusQueuedTaskCount() > 0);
1181                  helpQuiesce();
# Line 1127 | Line 1191 | public class CountedCompleterTest extend
1191       * peekNextLocalTask returns most recent unexecuted task.
1192       */
1193      public void testPeekNextLocalTask() {
1194 <       ForkJoinTask a = new CheckedFJTask() {
1195 <            public void realCompute() {
1196 <                CCF g = new LCCF(null, 9);
1194 >        ForkJoinTask a = new CheckedRecursiveAction() {
1195 >            protected void realCompute() {
1196 >                CCF g = new LCCF(9);
1197                  assertSame(g, g.fork());
1198 <                CCF f = new LCCF(null, 8);
1198 >                CCF f = new LCCF(8);
1199                  assertSame(f, f.fork());
1200                  assertSame(f, peekNextLocalTask());
1201                  assertNull(f.join());
# Line 1147 | Line 1211 | public class CountedCompleterTest extend
1211       * executing it
1212       */
1213      public void testPollNextLocalTask() {
1214 <       ForkJoinTask a = new CheckedFJTask() {
1215 <            public void realCompute() {
1216 <                CCF g = new LCCF(null, 9);
1214 >        ForkJoinTask a = new CheckedRecursiveAction() {
1215 >            protected void realCompute() {
1216 >                CCF g = new LCCF(9);
1217                  assertSame(g, g.fork());
1218 <                CCF f = new LCCF(null, 8);
1218 >                CCF f = new LCCF(8);
1219                  assertSame(f, f.fork());
1220                  assertSame(f, pollNextLocalTask());
1221                  helpQuiesce();
# Line 1166 | Line 1230 | public class CountedCompleterTest extend
1230       * pollTask returns an unexecuted task without executing it
1231       */
1232      public void testPollTask() {
1233 <       ForkJoinTask a = new CheckedFJTask() {
1234 <            public void realCompute() {
1235 <                CCF g = new LCCF(null, 9);
1233 >        ForkJoinTask a = new CheckedRecursiveAction() {
1234 >            protected void realCompute() {
1235 >                CCF g = new LCCF(9);
1236                  assertSame(g, g.fork());
1237 <                CCF f = new LCCF(null, 8);
1237 >                CCF f = new LCCF(8);
1238                  assertSame(f, f.fork());
1239                  assertSame(f, pollTask());
1240                  helpQuiesce();
# Line 1184 | Line 1248 | public class CountedCompleterTest extend
1248       * peekNextLocalTask returns least recent unexecuted task in async mode
1249       */
1250      public void testPeekNextLocalTaskAsync() {
1251 <       ForkJoinTask a = new CheckedFJTask() {
1252 <            public void realCompute() {
1253 <                CCF g = new LCCF(null, 9);
1251 >        ForkJoinTask a = new CheckedRecursiveAction() {
1252 >            protected void realCompute() {
1253 >                CCF g = new LCCF(9);
1254                  assertSame(g, g.fork());
1255 <                CCF f = new LCCF(null, 8);
1255 >                CCF f = new LCCF(8);
1256                  assertSame(f, f.fork());
1257                  assertSame(g, peekNextLocalTask());
1258                  assertNull(f.join());
# Line 1205 | Line 1269 | public class CountedCompleterTest extend
1269       * executing it, in async mode
1270       */
1271      public void testPollNextLocalTaskAsync() {
1272 <       ForkJoinTask a = new CheckedFJTask() {
1273 <            public void realCompute() {
1274 <                CCF g = new LCCF(null, 9);
1272 >        ForkJoinTask a = new CheckedRecursiveAction() {
1273 >            protected void realCompute() {
1274 >                CCF g = new LCCF(9);
1275                  assertSame(g, g.fork());
1276 <                CCF f = new LCCF(null, 8);
1276 >                CCF f = new LCCF(8);
1277                  assertSame(f, f.fork());
1278                  assertSame(g, pollNextLocalTask());
1279                  helpQuiesce();
# Line 1225 | Line 1289 | public class CountedCompleterTest extend
1289       * async mode
1290       */
1291      public void testPollTaskAsync() {
1292 <       ForkJoinTask a = new CheckedFJTask() {
1293 <            public void realCompute() {
1294 <                CCF g = new LCCF(null, 9);
1292 >        ForkJoinTask a = new CheckedRecursiveAction() {
1293 >            protected void realCompute() {
1294 >                CCF g = new LCCF(9);
1295                  assertSame(g, g.fork());
1296 <                CCF f = new LCCF(null, 8);
1296 >                CCF f = new LCCF(8);
1297                  assertSame(f, f.fork());
1298                  assertSame(g, pollTask());
1299                  helpQuiesce();
# Line 1248 | Line 1312 | public class CountedCompleterTest extend
1312       * completed tasks; getRawResult returns null.
1313       */
1314      public void testInvokeSingleton() {
1315 <       ForkJoinTask a = new CheckedFJTask() {
1316 <            public void realCompute() {
1317 <                CCF f = new LCCF(null, 8);
1315 >        ForkJoinTask a = new CheckedRecursiveAction() {
1316 >            protected void realCompute() {
1317 >                CCF f = new LCCF(8);
1318                  assertNull(f.invoke());
1319                  assertEquals(21, f.number);
1320                  checkCompletedNormally(f);
# Line 1264 | Line 1328 | public class CountedCompleterTest extend
1328       * completed tasks
1329       */
1330      public void testQuietlyInvokeSingleton() {
1331 <       ForkJoinTask a = new CheckedFJTask() {
1332 <            public void realCompute() {
1333 <                CCF f = new LCCF(null, 8);
1331 >        ForkJoinTask a = new CheckedRecursiveAction() {
1332 >            protected void realCompute() {
1333 >                CCF f = new LCCF(8);
1334                  f.quietlyInvoke();
1335                  assertEquals(21, f.number);
1336                  checkCompletedNormally(f);
# Line 1278 | Line 1342 | public class CountedCompleterTest extend
1342       * join of a forked task returns when task completes
1343       */
1344      public void testForkJoinSingleton() {
1345 <       ForkJoinTask a = new CheckedFJTask() {
1346 <            public void realCompute() {
1347 <                CCF f = new LCCF(null, 8);
1345 >        ForkJoinTask a = new CheckedRecursiveAction() {
1346 >            protected void realCompute() {
1347 >                CCF f = new LCCF(8);
1348                  assertSame(f, f.fork());
1349                  assertNull(f.join());
1350                  assertEquals(21, f.number);
# Line 1293 | Line 1357 | public class CountedCompleterTest extend
1357       * get of a forked task returns when task completes
1358       */
1359      public void testForkGetSingleton() {
1360 <       ForkJoinTask a = new CheckedFJTask() {
1361 <            public void realCompute() throws Exception {
1362 <                CCF f = new LCCF(null, 8);
1360 >        ForkJoinTask a = new CheckedRecursiveAction() {
1361 >            protected void realCompute() throws Exception {
1362 >                CCF f = new LCCF(8);
1363                  assertSame(f, f.fork());
1364                  assertNull(f.get());
1365                  assertEquals(21, f.number);
# Line 1308 | Line 1372 | public class CountedCompleterTest extend
1372       * timed get of a forked task returns when task completes
1373       */
1374      public void testForkTimedGetSingleton() {
1375 <       ForkJoinTask a = new CheckedFJTask() {
1376 <            public void realCompute() throws Exception {
1377 <                CCF f = new LCCF(null, 8);
1375 >        ForkJoinTask a = new CheckedRecursiveAction() {
1376 >            protected void realCompute() throws Exception {
1377 >                CCF f = new LCCF(8);
1378                  assertSame(f, f.fork());
1379                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1380                  assertEquals(21, f.number);
# Line 1323 | Line 1387 | public class CountedCompleterTest extend
1387       * timed get with null time unit throws NPE
1388       */
1389      public void testForkTimedGetNPESingleton() {
1390 <       ForkJoinTask a = new CheckedFJTask() {
1391 <            public void realCompute() throws Exception {
1392 <                CCF f = new LCCF(null, 8);
1390 >        ForkJoinTask a = new CheckedRecursiveAction() {
1391 >            protected void realCompute() throws Exception {
1392 >                CCF f = new LCCF(8);
1393                  assertSame(f, f.fork());
1394                  try {
1395                      f.get(5L, null);
# Line 1339 | Line 1403 | public class CountedCompleterTest extend
1403       * quietlyJoin of a forked task returns when task completes
1404       */
1405      public void testForkQuietlyJoinSingleton() {
1406 <       ForkJoinTask a = new CheckedFJTask() {
1407 <            public void realCompute() {
1408 <                CCF f = new LCCF(null, 8);
1406 >        ForkJoinTask a = new CheckedRecursiveAction() {
1407 >            protected void realCompute() {
1408 >                CCF f = new LCCF(8);
1409                  assertSame(f, f.fork());
1410                  f.quietlyJoin();
1411                  assertEquals(21, f.number);
# Line 1355 | Line 1419 | public class CountedCompleterTest extend
1419       * getQueuedTaskCount returns 0 when quiescent
1420       */
1421      public void testForkHelpQuiesceSingleton() {
1422 <       ForkJoinTask a = new CheckedFJTask() {
1423 <            public void realCompute() {
1424 <                CCF f = new LCCF(null, 8);
1422 >        ForkJoinTask a = new CheckedRecursiveAction() {
1423 >            protected void realCompute() {
1424 >                CCF f = new LCCF(8);
1425                  assertSame(f, f.fork());
1426                  helpQuiesce();
1427                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1435 | public class CountedCompleterTest extend
1435       * invoke task throws exception when task completes abnormally
1436       */
1437      public void testAbnormalInvokeSingleton() {
1438 <       ForkJoinTask a = new CheckedFJTask() {
1439 <            public void realCompute() {
1440 <                FailingCCF f = new LFCCF(null, 8);
1438 >        ForkJoinTask a = new CheckedRecursiveAction() {
1439 >            protected void realCompute() {
1440 >                FailingCCF f = new LFCCF(8);
1441                  try {
1442                      f.invoke();
1443                      shouldThrow();
# Line 1388 | Line 1452 | public class CountedCompleterTest extend
1452       * quietlyInvoke task returns when task completes abnormally
1453       */
1454      public void testAbnormalQuietlyInvokeSingleton() {
1455 <       ForkJoinTask a = new CheckedFJTask() {
1456 <            public void realCompute() {
1457 <                FailingCCF f = new LFCCF(null, 8);
1455 >        ForkJoinTask a = new CheckedRecursiveAction() {
1456 >            protected void realCompute() {
1457 >                FailingCCF f = new LFCCF(8);
1458                  f.quietlyInvoke();
1459                  assertTrue(f.getException() instanceof FJException);
1460                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1466 | public class CountedCompleterTest extend
1466       * join of a forked task throws exception when task completes abnormally
1467       */
1468      public void testAbnormalForkJoinSingleton() {
1469 <       ForkJoinTask a = new CheckedFJTask() {
1470 <            public void realCompute() {
1471 <                FailingCCF f = new LFCCF(null, 8);
1469 >        ForkJoinTask a = new CheckedRecursiveAction() {
1470 >            protected void realCompute() {
1471 >                FailingCCF f = new LFCCF(8);
1472                  assertSame(f, f.fork());
1473                  try {
1474                      f.join();
# Line 1420 | Line 1484 | public class CountedCompleterTest extend
1484       * get of a forked task throws exception when task completes abnormally
1485       */
1486      public void testAbnormalForkGetSingleton() {
1487 <       ForkJoinTask a = new CheckedFJTask() {
1488 <            public void realCompute() throws Exception {
1489 <                FailingCCF f = new LFCCF(null, 8);
1487 >        ForkJoinTask a = new CheckedRecursiveAction() {
1488 >            protected void realCompute() throws Exception {
1489 >                FailingCCF f = new LFCCF(8);
1490                  assertSame(f, f.fork());
1491                  try {
1492                      f.get();
# Line 1440 | Line 1504 | public class CountedCompleterTest extend
1504       * timed get of a forked task throws exception when task completes abnormally
1505       */
1506      public void testAbnormalForkTimedGetSingleton() {
1507 <       ForkJoinTask a = new CheckedFJTask() {
1508 <            public void realCompute() throws Exception {
1509 <                FailingCCF f = new LFCCF(null, 8);
1507 >        ForkJoinTask a = new CheckedRecursiveAction() {
1508 >            protected void realCompute() throws Exception {
1509 >                FailingCCF f = new LFCCF(8);
1510                  assertSame(f, f.fork());
1511                  try {
1512                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1524 | public class CountedCompleterTest extend
1524       * quietlyJoin of a forked task returns when task completes abnormally
1525       */
1526      public void testAbnormalForkQuietlyJoinSingleton() {
1527 <       ForkJoinTask a = new CheckedFJTask() {
1528 <            public void realCompute() {
1529 <                FailingCCF f = new LFCCF(null, 8);
1527 >        ForkJoinTask a = new CheckedRecursiveAction() {
1528 >            protected void realCompute() {
1529 >                FailingCCF f = new LFCCF(8);
1530                  assertSame(f, f.fork());
1531                  f.quietlyJoin();
1532                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1539 | public class CountedCompleterTest extend
1539       * invoke task throws exception when task cancelled
1540       */
1541      public void testCancelledInvokeSingleton() {
1542 <       ForkJoinTask a = new CheckedFJTask() {
1543 <            public void realCompute() {
1544 <                CCF f = new LCCF(null, 8);
1542 >        ForkJoinTask a = new CheckedRecursiveAction() {
1543 >            protected void realCompute() {
1544 >                CCF f = new LCCF(8);
1545                  assertTrue(f.cancel(true));
1546                  try {
1547                      f.invoke();
# Line 1493 | Line 1557 | public class CountedCompleterTest extend
1557       * join of a forked task throws exception when task cancelled
1558       */
1559      public void testCancelledForkJoinSingleton() {
1560 <       ForkJoinTask a = new CheckedFJTask() {
1561 <            public void realCompute() {
1562 <                CCF f = new LCCF(null, 8);
1560 >        ForkJoinTask a = new CheckedRecursiveAction() {
1561 >            protected void realCompute() {
1562 >                CCF f = new LCCF(8);
1563                  assertTrue(f.cancel(true));
1564                  assertSame(f, f.fork());
1565                  try {
# Line 1512 | Line 1576 | public class CountedCompleterTest extend
1576       * get of a forked task throws exception when task cancelled
1577       */
1578      public void testCancelledForkGetSingleton() {
1579 <       ForkJoinTask a = new CheckedFJTask() {
1580 <            public void realCompute() throws Exception {
1581 <                CCF f = new LCCF(null, 8);
1579 >        ForkJoinTask a = new CheckedRecursiveAction() {
1580 >            protected void realCompute() throws Exception {
1581 >                CCF f = new LCCF(8);
1582                  assertTrue(f.cancel(true));
1583                  assertSame(f, f.fork());
1584                  try {
# Line 1531 | Line 1595 | public class CountedCompleterTest extend
1595       * timed get of a forked task throws exception when task cancelled
1596       */
1597      public void testCancelledForkTimedGetSingleton() throws Exception {
1598 <       ForkJoinTask a = new CheckedFJTask() {
1599 <            public void realCompute() throws Exception {
1600 <                CCF f = new LCCF(null, 8);
1598 >        ForkJoinTask a = new CheckedRecursiveAction() {
1599 >            protected void realCompute() throws Exception {
1600 >                CCF f = new LCCF(8);
1601                  assertTrue(f.cancel(true));
1602                  assertSame(f, f.fork());
1603                  try {
# Line 1550 | Line 1614 | public class CountedCompleterTest extend
1614       * quietlyJoin of a forked task returns when task cancelled
1615       */
1616      public void testCancelledForkQuietlyJoinSingleton() {
1617 <       ForkJoinTask a = new CheckedFJTask() {
1618 <            public void realCompute() {
1619 <                CCF f = new LCCF(null, 8);
1617 >        ForkJoinTask a = new CheckedRecursiveAction() {
1618 >            protected void realCompute() {
1619 >                CCF f = new LCCF(8);
1620                  assertTrue(f.cancel(true));
1621                  assertSame(f, f.fork());
1622                  f.quietlyJoin();
# Line 1565 | Line 1629 | public class CountedCompleterTest extend
1629       * invoke task throws exception after invoking completeExceptionally
1630       */
1631      public void testCompleteExceptionallySingleton() {
1632 <       ForkJoinTask a = new CheckedFJTask() {
1633 <            public void realCompute() {
1634 <                CCF f = new LCCF(null, 8);
1635 <                f.completeExceptionally(new FJException());
1636 <                try {
1637 <                    f.invoke();
1638 <                    shouldThrow();
1639 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1632 >        ForkJoinTask a = new CheckedRecursiveAction() {
1633 >            protected void realCompute() {
1634 >                CCF n = new LCCF(8);
1635 >                CCF f = new LCCF(n, 8);
1636 >                FJException ex = new FJException();
1637 >                f.completeExceptionally(ex);
1638 >                f.checkCompletedExceptionally(ex);
1639 >                n.checkCompletedExceptionally(ex);
1640              }};
1641          testInvokeOnPool(singletonPool(), a);
1642      }
# Line 1583 | Line 1645 | public class CountedCompleterTest extend
1645       * invokeAll(t1, t2) invokes all task arguments
1646       */
1647      public void testInvokeAll2Singleton() {
1648 <       ForkJoinTask a = new CheckedFJTask() {
1649 <            public void realCompute() {
1650 <                CCF f = new LCCF(null, 8);
1651 <                CCF g = new LCCF(null, 9);
1648 >        ForkJoinTask a = new CheckedRecursiveAction() {
1649 >            protected void realCompute() {
1650 >                CCF f = new LCCF(8);
1651 >                CCF g = new LCCF(9);
1652                  invokeAll(f, g);
1653                  assertEquals(21, f.number);
1654                  assertEquals(34, g.number);
# Line 1600 | Line 1662 | public class CountedCompleterTest extend
1662       * invokeAll(tasks) with 1 argument invokes task
1663       */
1664      public void testInvokeAll1Singleton() {
1665 <       ForkJoinTask a = new CheckedFJTask() {
1666 <            public void realCompute() {
1667 <                CCF f = new LCCF(null, 8);
1665 >        ForkJoinTask a = new CheckedRecursiveAction() {
1666 >            protected void realCompute() {
1667 >                CCF f = new LCCF(8);
1668                  invokeAll(f);
1669                  checkCompletedNormally(f);
1670                  assertEquals(21, f.number);
# Line 1614 | Line 1676 | public class CountedCompleterTest extend
1676       * invokeAll(tasks) with > 2 argument invokes tasks
1677       */
1678      public void testInvokeAll3Singleton() {
1679 <       ForkJoinTask a = new CheckedFJTask() {
1680 <            public void realCompute() {
1681 <                CCF f = new LCCF(null, 8);
1682 <                CCF g = new LCCF(null, 9);
1683 <                CCF h = new LCCF(null, 7);
1679 >        ForkJoinTask a = new CheckedRecursiveAction() {
1680 >            protected void realCompute() {
1681 >                CCF f = new LCCF(8);
1682 >                CCF g = new LCCF(9);
1683 >                CCF h = new LCCF(7);
1684                  invokeAll(f, g, h);
1685                  assertEquals(21, f.number);
1686                  assertEquals(34, g.number);
# Line 1634 | Line 1696 | public class CountedCompleterTest extend
1696       * invokeAll(collection) invokes all tasks in the collection
1697       */
1698      public void testInvokeAllCollectionSingleton() {
1699 <       ForkJoinTask a = new CheckedFJTask() {
1700 <            public void realCompute() {
1701 <                CCF f = new LCCF(null, 8);
1702 <                CCF g = new LCCF(null, 9);
1703 <                CCF h = new LCCF(null, 7);
1699 >        ForkJoinTask a = new CheckedRecursiveAction() {
1700 >            protected void realCompute() {
1701 >                CCF f = new LCCF(8);
1702 >                CCF g = new LCCF(9);
1703 >                CCF h = new LCCF(7);
1704                  HashSet set = new HashSet();
1705                  set.add(f);
1706                  set.add(g);
# Line 1658 | Line 1720 | public class CountedCompleterTest extend
1720       * invokeAll(tasks) with any null task throws NPE
1721       */
1722      public void testInvokeAllNPESingleton() {
1723 <       ForkJoinTask a = new CheckedFJTask() {
1724 <            public void realCompute() {
1725 <                CCF f = new LCCF(null, 8);
1726 <                CCF g = new LCCF(null, 9);
1723 >        ForkJoinTask a = new CheckedRecursiveAction() {
1724 >            protected void realCompute() {
1725 >                CCF f = new LCCF(8);
1726 >                CCF g = new LCCF(9);
1727                  CCF h = null;
1728                  try {
1729                      invokeAll(f, g, h);
# Line 1675 | Line 1737 | public class CountedCompleterTest extend
1737       * invokeAll(t1, t2) throw exception if any task does
1738       */
1739      public void testAbnormalInvokeAll2Singleton() {
1740 <       ForkJoinTask a = new CheckedFJTask() {
1741 <            public void realCompute() {
1742 <                CCF f = new LCCF(null, 8);
1743 <                FailingCCF g = new LFCCF(null, 9);
1740 >        ForkJoinTask a = new CheckedRecursiveAction() {
1741 >            protected void realCompute() {
1742 >                CCF f = new LCCF(8);
1743 >                FailingCCF g = new LFCCF(9);
1744                  try {
1745                      invokeAll(f, g);
1746                      shouldThrow();
# Line 1693 | Line 1755 | public class CountedCompleterTest extend
1755       * invokeAll(tasks) with 1 argument throws exception if task does
1756       */
1757      public void testAbnormalInvokeAll1Singleton() {
1758 <       ForkJoinTask a = new CheckedFJTask() {
1759 <            public void realCompute() {
1760 <                FailingCCF g = new LFCCF(null, 9);
1758 >        ForkJoinTask a = new CheckedRecursiveAction() {
1759 >            protected void realCompute() {
1760 >                FailingCCF g = new LFCCF(9);
1761                  try {
1762                      invokeAll(g);
1763                      shouldThrow();
# Line 1710 | Line 1772 | public class CountedCompleterTest extend
1772       * invokeAll(tasks) with > 2 argument throws exception if any task does
1773       */
1774      public void testAbnormalInvokeAll3Singleton() {
1775 <       ForkJoinTask a = new CheckedFJTask() {
1776 <            public void realCompute() {
1777 <                CCF f = new LCCF(null, 8);
1778 <                FailingCCF g = new LFCCF(null, 9);
1779 <                CCF h = new LCCF(null, 7);
1775 >        ForkJoinTask a = new CheckedRecursiveAction() {
1776 >            protected void realCompute() {
1777 >                CCF f = new LCCF(8);
1778 >                FailingCCF g = new LFCCF(9);
1779 >                CCF h = new LCCF(7);
1780                  try {
1781                      invokeAll(f, g, h);
1782                      shouldThrow();
# Line 1729 | Line 1791 | public class CountedCompleterTest extend
1791       * invokeAll(collection)  throws exception if any task does
1792       */
1793      public void testAbnormalInvokeAllCollectionSingleton() {
1794 <       ForkJoinTask a = new CheckedFJTask() {
1795 <            public void realCompute() {
1796 <                FailingCCF f = new LFCCF(null, 8);
1797 <                CCF g = new LCCF(null, 9);
1798 <                CCF h = new LCCF(null, 7);
1794 >        ForkJoinTask a = new CheckedRecursiveAction() {
1795 >            protected void realCompute() {
1796 >                FailingCCF f = new LFCCF(8);
1797 >                CCF g = new LCCF(9);
1798 >                CCF h = new LCCF(7);
1799                  HashSet set = new HashSet();
1800                  set.add(f);
1801                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines