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.10 by jsr166, Thu Jun 6 00:40:13 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 >            int pendingCount = getPendingCount();
256 >            complete(rawResult);
257 >            assertEquals(pendingCount, getPendingCount());
258 >            assertEquals(0, computeN());
259 >            assertEquals(1, onCompletionN());
260 >            assertEquals(0, onExceptionalCompletionN());
261 >            assertEquals(1, setRawResultN());
262 >            assertSame(rawResult, this.rawResult.get());
263 >            checkCompletedNormally(this);
264 >        }
265 >        void checkCompletesExceptionally(Throwable ex) {
266 >            checkIncomplete();
267 >            completeExceptionally(ex);
268 >            checkCompletedExceptionally(ex);
269 >        }
270 >        void checkCompletedExceptionally(Throwable ex) {
271 >            assertEquals(0, computeN());
272 >            assertEquals(0, onCompletionN());
273 >            assertEquals(1, onExceptionalCompletionN());
274 >            assertEquals(0, setRawResultN());
275 >            assertNull(this.rawResult.get());
276 >            checkCompletedAbnormally(this, ex);
277          }
278      }
279  
280 +    final class NoopCC extends CheckedCC {
281 +        NoopCC() { super(); }
282 +        NoopCC(CountedCompleter p) { super(p); }
283 +        protected void realCompute() {}
284 +    }
285 +
286      /**
287 <     * A newly constructed CountedCompleter is not completed;
288 <     * complete() causes completion.
287 >     * A newly constructed CountedCompleter is not completed;
288 >     * complete() causes completion. pendingCount is ignored.
289       */
290      public void testComplete() {
291 <        NoopCountedCompleter a = new NoopCountedCompleter();
292 <        assertFalse(a.isDone());
293 <        assertFalse(a.isCompletedNormally());
294 <        assertFalse(a.isCompletedAbnormally());
295 <        assertFalse(a.isCancelled());
296 <        assertNull(a.getException());
297 <        assertNull(a.getRawResult());
298 <        assertFalse(a.post);
299 <        a.complete(null);
300 <        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());
291 >        for (Object x : new Object[] { Boolean.TRUE, null }) {
292 >            for (int pendingCount : new int[] { 0, 42 }) {
293 >                testComplete(new NoopCC(), x, pendingCount);
294 >                testComplete(new NoopCC(new NoopCC()), x, pendingCount);
295 >            }
296 >        }
297 >    }
298 >    void testComplete(NoopCC cc, Object x, int pendingCount) {
299 >        cc.setPendingCount(pendingCount);
300 >        cc.checkCompletes(x);
301      }
302  
303      /**
304       * completeExceptionally completes exceptionally
305       */
306      public void testCompleteExceptionally() {
307 <        NoopCountedCompleter a = new NoopCountedCompleter();
308 <        assertFalse(a.isDone());
309 <        assertFalse(a.isCompletedNormally());
310 <        assertFalse(a.isCompletedAbnormally());
311 <        assertFalse(a.isCancelled());
312 <        assertNull(a.getException());
313 <        assertNull(a.getRawResult());
314 <        assertFalse(a.post);
315 <        a.completeExceptionally(new FJException());
316 <        assertFalse(a.post);
317 <        assertTrue(a.isDone());
318 <        assertFalse(a.isCompletedNormally());
319 <        assertTrue(a.isCompletedAbnormally());
320 <        assertFalse(a.isCancelled());
321 <        assertTrue(a.getException() instanceof FJException);
272 <        assertNull(a.getRawResult());
307 >        new NoopCC()
308 >            .checkCompletesExceptionally(new FJException());
309 >        new NoopCC(new NoopCC())
310 >            .checkCompletesExceptionally(new FJException());
311 >    }
312 >
313 >    /**
314 >     * completeExceptionally(null) throws NullPointerException
315 >     */
316 >    public void testCompleteExceptionally_null() {
317 >        try {
318 >            new NoopCC()
319 >                .checkCompletesExceptionally(null);
320 >            shouldThrow();
321 >        } catch (NullPointerException success) {}
322      }
323  
324      /**
325       * setPendingCount sets the reported pending count
326       */
327      public void testSetPendingCount() {
328 <        NoopCountedCompleter a = new NoopCountedCompleter();
328 >        NoopCC a = new NoopCC();
329          assertEquals(0, a.getPendingCount());
330          a.setPendingCount(1);
331          assertEquals(1, a.getPendingCount());
# Line 288 | Line 337 | public class CountedCompleterTest extend
337       * addToPendingCount adds to the reported pending count
338       */
339      public void testAddToPendingCount() {
340 <        NoopCountedCompleter a = new NoopCountedCompleter();
340 >        NoopCC a = new NoopCC();
341          assertEquals(0, a.getPendingCount());
342          a.addToPendingCount(1);
343          assertEquals(1, a.getPendingCount());
# Line 301 | Line 350 | public class CountedCompleterTest extend
350       * count unless zero
351       */
352      public void testDecrementPendingCount() {
353 <        NoopCountedCompleter a = new NoopCountedCompleter();
353 >        NoopCC a = new NoopCC();
354          assertEquals(0, a.getPendingCount());
355          a.addToPendingCount(1);
356          assertEquals(1, a.getPendingCount());
# Line 312 | Line 361 | public class CountedCompleterTest extend
361      }
362  
363      /**
364 +     * compareAndSetPendingCount compares and sets the reported
365 +     * pending count
366 +     */
367 +    public void testCompareAndSetPendingCount() {
368 +        NoopCC a = new NoopCC();
369 +        assertEquals(0, a.getPendingCount());
370 +        assertTrue(a.compareAndSetPendingCount(0, 1));
371 +        assertEquals(1, a.getPendingCount());
372 +        assertTrue(a.compareAndSetPendingCount(1, 2));
373 +        assertEquals(2, a.getPendingCount());
374 +        assertFalse(a.compareAndSetPendingCount(1, 3));
375 +        assertEquals(2, a.getPendingCount());
376 +    }
377 +
378 +    /**
379       * getCompleter returns parent or null if at root
380       */
381      public void testGetCompleter() {
382 <        NoopCountedCompleter a = new NoopCountedCompleter();
382 >        NoopCC a = new NoopCC();
383          assertNull(a.getCompleter());
384 <        CountedCompleter b = new NoopCountedCompleter(a);
385 <        assertEquals(a, b.getCompleter());
384 >        CountedCompleter b = new NoopCC(a);
385 >        assertSame(a, b.getCompleter());
386 >        CountedCompleter c = new NoopCC(b);
387 >        assertSame(b, c.getCompleter());
388      }
389 <    
389 >
390      /**
391       * getRoot returns self if no parent, else parent's root
392       */
393      public void testGetRoot() {
394 <        NoopCountedCompleter a = new NoopCountedCompleter();
395 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
396 <        assertEquals(a, a.getRoot());
397 <        assertEquals(a, b.getRoot());
394 >        NoopCC a = new NoopCC();
395 >        NoopCC b = new NoopCC(a);
396 >        NoopCC c = new NoopCC(b);
397 >        assertSame(a, a.getRoot());
398 >        assertSame(a, b.getRoot());
399 >        assertSame(a, c.getRoot());
400      }
401 <              
401 >
402      /**
403 <     * tryComplete causes completion if pending count is zero
403 >     * tryComplete decrements pending count unless zero, in which case
404 >     * causes completion
405       */
406 <    public void testTryComplete1() {
407 <        NoopCountedCompleter a = new NoopCountedCompleter();
406 >    public void testTryComplete() {
407 >        NoopCC a = new NoopCC();
408          assertEquals(0, a.getPendingCount());
409 +        int n = 3;
410 +        a.setPendingCount(n);
411 +        for (; n > 0; n--) {
412 +            assertEquals(n, a.getPendingCount());
413 +            a.tryComplete();
414 +            a.checkIncomplete();
415 +            assertEquals(n - 1, a.getPendingCount());
416 +        }
417          a.tryComplete();
418 <        assertTrue(a.post);
419 <        assertTrue(a.isDone());
418 >        assertEquals(0, a.computeN());
419 >        assertEquals(1, a.onCompletionN());
420 >        assertEquals(0, a.onExceptionalCompletionN());
421 >        assertEquals(0, a.setRawResultN());
422 >        checkCompletedNormally(a);
423      }
424  
425      /**
426 <     * propagateCompletion causes completion without invokein
427 <     * onCompletion if pending count is zero
426 >     * propagateCompletion decrements pending count unless zero, in
427 >     * which case causes completion, without invoking onCompletion
428       */
429      public void testPropagateCompletion() {
430 <        NoopCountedCompleter a = new NoopCountedCompleter();
430 >        NoopCC a = new NoopCC();
431          assertEquals(0, a.getPendingCount());
432 +        int n = 3;
433 +        a.setPendingCount(n);
434 +        for (; n > 0; n--) {
435 +            assertEquals(n, a.getPendingCount());
436 +            a.propagateCompletion();
437 +            a.checkIncomplete();
438 +            assertEquals(n - 1, a.getPendingCount());
439 +        }
440          a.propagateCompletion();
441 <        assertFalse(a.post);
442 <        assertTrue(a.isDone());
443 <    }
444 <
445 <    /**
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());
441 >        assertEquals(0, a.computeN());
442 >        assertEquals(0, a.onCompletionN());
443 >        assertEquals(0, a.onExceptionalCompletionN());
444 >        assertEquals(0, a.setRawResultN());
445 >        checkCompletedNormally(a);
446      }
447  
448      /**
449       * firstComplete returns this if pending count is zero else null
450       */
451      public void testFirstComplete() {
452 <        NoopCountedCompleter a = new NoopCountedCompleter();
452 >        NoopCC a = new NoopCC();
453          a.setPendingCount(1);
454          assertNull(a.firstComplete());
455 <        assertEquals(a, a.firstComplete());
455 >        a.checkIncomplete();
456 >        assertSame(a, a.firstComplete());
457 >        a.checkIncomplete();
458      }
459  
460      /**
# Line 385 | Line 462 | public class CountedCompleterTest extend
462       * zero else null
463       */
464      public void testNextComplete() {
465 <        NoopCountedCompleter a = new NoopCountedCompleter();
466 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
465 >        NoopCC a = new NoopCC();
466 >        NoopCC b = new NoopCC(a);
467          a.setPendingCount(1);
468          b.setPendingCount(1);
469          assertNull(b.firstComplete());
470 <        CountedCompleter c = b.firstComplete();
471 <        assertEquals(b, c);
472 <        CountedCompleter d = c.nextComplete();
473 <        assertNull(d);
474 <        CountedCompleter e = c.nextComplete();
475 <        assertEquals(a, e);
470 >        assertSame(b, b.firstComplete());
471 >        assertNull(b.nextComplete());
472 >        a.checkIncomplete();
473 >        b.checkIncomplete();
474 >        assertSame(a, b.nextComplete());
475 >        assertSame(a, b.nextComplete());
476 >        a.checkIncomplete();
477 >        b.checkIncomplete();
478 >        assertNull(a.nextComplete());
479 >        b.checkIncomplete();
480 >        checkCompletedNormally(a);
481      }
482  
483      /**
484       * quietlyCompleteRoot completes root task
485       */
486      public void testQuietlyCompleteRoot() {
487 <        NoopCountedCompleter a = new NoopCountedCompleter();
488 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
487 >        NoopCC a = new NoopCC();
488 >        NoopCC b = new NoopCC(a);
489 >        NoopCC c = new NoopCC(b);
490          a.setPendingCount(1);
491          b.setPendingCount(1);
492 <        b.quietlyCompleteRoot();
492 >        c.setPendingCount(1);
493 >        c.quietlyCompleteRoot();
494          assertTrue(a.isDone());
495          assertFalse(b.isDone());
496 +        assertFalse(c.isDone());
497      }
498  
499      // Invocation tests use some interdependent task classes
500      // to better test propagation etc
501  
502 <    
502 >
503      // Version of Fibonacci with different classes for left vs right forks
504 <    static abstract class CCF extends CountedCompleter {
504 >    abstract class CCF extends CheckedCC {
505          int number;
506          int rnumber;
507  
# Line 425 | Line 510 | public class CountedCompleterTest extend
510              this.number = n;
511          }
512  
513 <        public final void compute() {
429 <            CountedCompleter p;
513 >        protected final void realCompute() {
514              CCF f = this;
515              int n = number;
516              while (n >= 2) {
517                  new RCCF(f, n - 2).fork();
518                  f = new LCCF(f, --n);
519              }
520 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
520 >            f.complete(null);
521          }
522      }
523  
524 <    static final class LCCF extends CCF {
524 >    final class LCCF extends CCF {
525 >        public LCCF(int n) { this(null, n); }
526          public LCCF(CountedCompleter parent, int n) {
527              super(parent, n);
528          }
529          public final void onCompletion(CountedCompleter caller) {
530 +            super.onCompletion(caller);
531              CCF p = (CCF)getCompleter();
532              int n = number + rnumber;
533              if (p != null)
# Line 455 | Line 536 | public class CountedCompleterTest extend
536                  number = n;
537          }
538      }
539 <    static final class RCCF extends CCF {
539 >    final class RCCF extends CCF {
540          public RCCF(CountedCompleter parent, int n) {
541              super(parent, n);
542          }
543          public final void onCompletion(CountedCompleter caller) {
544 +            super.onCompletion(caller);
545              CCF p = (CCF)getCompleter();
546              int n = number + rnumber;
547              if (p != null)
# Line 470 | Line 552 | public class CountedCompleterTest extend
552      }
553  
554      // Version of CCF with forced failure in left completions
555 <    static abstract class FailingCCF extends CountedCompleter {
555 >    abstract class FailingCCF extends CheckedCC {
556          int number;
557          int rnumber;
558  
# Line 479 | Line 561 | public class CountedCompleterTest extend
561              this.number = n;
562          }
563  
564 <        public final void compute() {
483 <            CountedCompleter p;
564 >        protected final void realCompute() {
565              FailingCCF f = this;
566              int n = number;
567              while (n >= 2) {
568                  new RFCCF(f, n - 2).fork();
569                  f = new LFCCF(f, --n);
570              }
571 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
571 >            f.complete(null);
572          }
573      }
574  
575 <    static final class LFCCF extends FailingCCF {
575 >    final class LFCCF extends FailingCCF {
576 >        public LFCCF(int n) { this(null, n); }
577          public LFCCF(CountedCompleter parent, int n) {
578              super(parent, n);
579          }
580          public final void onCompletion(CountedCompleter caller) {
581 +            super.onCompletion(caller);
582              FailingCCF p = (FailingCCF)getCompleter();
583              int n = number + rnumber;
584              if (p != null)
# Line 509 | Line 587 | public class CountedCompleterTest extend
587                  number = n;
588          }
589      }
590 <    static final class RFCCF extends FailingCCF {
590 >    final class RFCCF extends FailingCCF {
591          public RFCCF(CountedCompleter parent, int n) {
592              super(parent, n);
593          }
594          public final void onCompletion(CountedCompleter caller) {
595 +            super.onCompletion(caller);
596              completeExceptionally(new FJException());
597          }
598      }
599 <    
599 >
600      /**
601       * invoke returns when task completes normally.
602       * isCompletedAbnormally and isCancelled return false for normally
603       * completed tasks; getRawResult returns null.
604       */
605      public void testInvoke() {
606 <       ForkJoinTask a =  new CheckedFJTask() {
607 <            public void realCompute() {
608 <                CCF f = new LCCF(null, 8);
606 >        ForkJoinTask a = new CheckedRecursiveAction() {
607 >            protected void realCompute() {
608 >                CCF f = new LCCF(8);
609                  assertNull(f.invoke());
610                  assertEquals(21, f.number);
611                  checkCompletedNormally(f);
# Line 540 | Line 619 | public class CountedCompleterTest extend
619       * completed tasks
620       */
621      public void testQuietlyInvoke() {
622 <       ForkJoinTask a =  new CheckedFJTask() {
623 <            public void realCompute() {
624 <                CCF f = new LCCF(null, 8);
622 >        ForkJoinTask a = new CheckedRecursiveAction() {
623 >            protected void realCompute() {
624 >                CCF f = new LCCF(8);
625                  f.quietlyInvoke();
626                  assertEquals(21, f.number);
627                  checkCompletedNormally(f);
# Line 554 | Line 633 | public class CountedCompleterTest extend
633       * join of a forked task returns when task completes
634       */
635      public void testForkJoin() {
636 <       ForkJoinTask a =  new CheckedFJTask() {
637 <            public void realCompute() {
638 <                CCF f = new LCCF(null, 8);
636 >        ForkJoinTask a = new CheckedRecursiveAction() {
637 >            protected void realCompute() {
638 >                CCF f = new LCCF(8);
639                  assertSame(f, f.fork());
640                  assertNull(f.join());
641                  assertEquals(21, f.number);
# Line 569 | Line 648 | public class CountedCompleterTest extend
648       * get of a forked task returns when task completes
649       */
650      public void testForkGet() {
651 <       ForkJoinTask a =  new CheckedFJTask() {
652 <            public void realCompute() throws Exception {
653 <                CCF f = new LCCF(null, 8);
651 >        ForkJoinTask a = new CheckedRecursiveAction() {
652 >            protected void realCompute() throws Exception {
653 >                CCF f = new LCCF(8);
654                  assertSame(f, f.fork());
655                  assertNull(f.get());
656                  assertEquals(21, f.number);
# Line 584 | Line 663 | public class CountedCompleterTest extend
663       * timed get of a forked task returns when task completes
664       */
665      public void testForkTimedGet() {
666 <       ForkJoinTask a =  new CheckedFJTask() {
667 <            public void realCompute() throws Exception {
668 <                CCF f = new LCCF(null, 8);
666 >        ForkJoinTask a = new CheckedRecursiveAction() {
667 >            protected void realCompute() throws Exception {
668 >                CCF f = new LCCF(8);
669                  assertSame(f, f.fork());
670                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
671                  assertEquals(21, f.number);
# Line 599 | Line 678 | public class CountedCompleterTest extend
678       * timed get with null time unit throws NPE
679       */
680      public void testForkTimedGetNPE() {
681 <       ForkJoinTask a =  new CheckedFJTask() {
682 <            public void realCompute() throws Exception {
683 <                CCF f = new LCCF(null, 8);
681 >        ForkJoinTask a = new CheckedRecursiveAction() {
682 >            protected void realCompute() throws Exception {
683 >                CCF f = new LCCF(8);
684                  assertSame(f, f.fork());
685                  try {
686                      f.get(5L, null);
# Line 615 | Line 694 | public class CountedCompleterTest extend
694       * quietlyJoin of a forked task returns when task completes
695       */
696      public void testForkQuietlyJoin() {
697 <       ForkJoinTask a =  new CheckedFJTask() {
698 <            public void realCompute() {
699 <                CCF f = new LCCF(null, 8);
697 >        ForkJoinTask a = new CheckedRecursiveAction() {
698 >            protected void realCompute() {
699 >                CCF f = new LCCF(8);
700                  assertSame(f, f.fork());
701                  f.quietlyJoin();
702                  assertEquals(21, f.number);
# Line 631 | Line 710 | public class CountedCompleterTest extend
710       * getQueuedTaskCount returns 0 when quiescent
711       */
712      public void testForkHelpQuiesce() {
713 <       ForkJoinTask a =  new CheckedFJTask() {
714 <            public void realCompute() {
715 <                CCF f = new LCCF(null, 8);
713 >        ForkJoinTask a = new CheckedRecursiveAction() {
714 >            protected void realCompute() {
715 >                CCF f = new LCCF(8);
716                  assertSame(f, f.fork());
717                  helpQuiesce();
718                  assertEquals(21, f.number);
# Line 647 | Line 726 | public class CountedCompleterTest extend
726       * invoke task throws exception when task completes abnormally
727       */
728      public void testAbnormalInvoke() {
729 <       ForkJoinTask a =  new CheckedFJTask() {
730 <            public void realCompute() {
731 <                FailingCCF f = new LFCCF(null, 8);
729 >        ForkJoinTask a = new CheckedRecursiveAction() {
730 >            protected void realCompute() {
731 >                FailingCCF f = new LFCCF(8);
732                  try {
733                      f.invoke();
734                      shouldThrow();
# Line 664 | Line 743 | public class CountedCompleterTest extend
743       * quietlyInvoke task returns when task completes abnormally
744       */
745      public void testAbnormalQuietlyInvoke() {
746 <       ForkJoinTask a =  new CheckedFJTask() {
747 <            public void realCompute() {
748 <                FailingCCF f = new LFCCF(null, 8);
746 >        ForkJoinTask a = new CheckedRecursiveAction() {
747 >            protected void realCompute() {
748 >                FailingCCF f = new LFCCF(8);
749                  f.quietlyInvoke();
750                  assertTrue(f.getException() instanceof FJException);
751                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 757 | public class CountedCompleterTest extend
757       * join of a forked task throws exception when task completes abnormally
758       */
759      public void testAbnormalForkJoin() {
760 <       ForkJoinTask a =  new CheckedFJTask() {
761 <            public void realCompute() {
762 <                FailingCCF f = new LFCCF(null, 8);
760 >        ForkJoinTask a = new CheckedRecursiveAction() {
761 >            protected void realCompute() {
762 >                FailingCCF f = new LFCCF(8);
763                  assertSame(f, f.fork());
764                  try {
765                      f.join();
# Line 696 | Line 775 | public class CountedCompleterTest extend
775       * get of a forked task throws exception when task completes abnormally
776       */
777      public void testAbnormalForkGet() {
778 <       ForkJoinTask a =  new CheckedFJTask() {
779 <            public void realCompute() throws Exception {
780 <                FailingCCF f = new LFCCF(null, 8);
778 >        ForkJoinTask a = new CheckedRecursiveAction() {
779 >            protected void realCompute() throws Exception {
780 >                FailingCCF f = new LFCCF(8);
781                  assertSame(f, f.fork());
782                  try {
783                      f.get();
# Line 716 | Line 795 | public class CountedCompleterTest extend
795       * timed get of a forked task throws exception when task completes abnormally
796       */
797      public void testAbnormalForkTimedGet() {
798 <       ForkJoinTask a =  new CheckedFJTask() {
799 <            public void realCompute() throws Exception {
800 <                FailingCCF f = new LFCCF(null, 8);
798 >        ForkJoinTask a = new CheckedRecursiveAction() {
799 >            protected void realCompute() throws Exception {
800 >                FailingCCF f = new LFCCF(8);
801                  assertSame(f, f.fork());
802                  try {
803                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 815 | public class CountedCompleterTest extend
815       * quietlyJoin of a forked task returns when task completes abnormally
816       */
817      public void testAbnormalForkQuietlyJoin() {
818 <       ForkJoinTask a =  new CheckedFJTask() {
819 <            public void realCompute() {
820 <                FailingCCF f = new LFCCF(null, 8);
818 >        ForkJoinTask a = new CheckedRecursiveAction() {
819 >            protected void realCompute() {
820 >                FailingCCF f = new LFCCF(8);
821                  assertSame(f, f.fork());
822                  f.quietlyJoin();
823                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 830 | public class CountedCompleterTest extend
830       * invoke task throws exception when task cancelled
831       */
832      public void testCancelledInvoke() {
833 <       ForkJoinTask a =  new CheckedFJTask() {
834 <            public void realCompute() {
835 <                CCF f = new LCCF(null, 8);
833 >        ForkJoinTask a = new CheckedRecursiveAction() {
834 >            protected void realCompute() {
835 >                CCF f = new LCCF(8);
836                  assertTrue(f.cancel(true));
837                  try {
838                      f.invoke();
# Line 769 | Line 848 | public class CountedCompleterTest extend
848       * join of a forked task throws exception when task cancelled
849       */
850      public void testCancelledForkJoin() {
851 <       ForkJoinTask a =  new CheckedFJTask() {
852 <            public void realCompute() {
853 <                CCF f = new LCCF(null, 8);
851 >        ForkJoinTask a = new CheckedRecursiveAction() {
852 >            protected void realCompute() {
853 >                CCF f = new LCCF(8);
854                  assertTrue(f.cancel(true));
855                  assertSame(f, f.fork());
856                  try {
# Line 788 | Line 867 | public class CountedCompleterTest extend
867       * get of a forked task throws exception when task cancelled
868       */
869      public void testCancelledForkGet() {
870 <       ForkJoinTask a =  new CheckedFJTask() {
871 <            public void realCompute() throws Exception {
872 <                CCF f = new LCCF(null, 8);
870 >        ForkJoinTask a = new CheckedRecursiveAction() {
871 >            protected void realCompute() throws Exception {
872 >                CCF f = new LCCF(8);
873                  assertTrue(f.cancel(true));
874                  assertSame(f, f.fork());
875                  try {
# Line 807 | Line 886 | public class CountedCompleterTest extend
886       * timed get of a forked task throws exception when task cancelled
887       */
888      public void testCancelledForkTimedGet() throws Exception {
889 <       ForkJoinTask a =  new CheckedFJTask() {
890 <            public void realCompute() throws Exception {
891 <                CCF f = new LCCF(null, 8);
889 >        ForkJoinTask a = new CheckedRecursiveAction() {
890 >            protected void realCompute() throws Exception {
891 >                CCF f = new LCCF(8);
892                  assertTrue(f.cancel(true));
893                  assertSame(f, f.fork());
894                  try {
# Line 826 | Line 905 | public class CountedCompleterTest extend
905       * quietlyJoin of a forked task returns when task cancelled
906       */
907      public void testCancelledForkQuietlyJoin() {
908 <       ForkJoinTask a =  new CheckedFJTask() {
909 <            public void realCompute() {
910 <                CCF f = new LCCF(null, 8);
908 >        ForkJoinTask a = new CheckedRecursiveAction() {
909 >            protected void realCompute() {
910 >                CCF f = new LCCF(8);
911                  assertTrue(f.cancel(true));
912                  assertSame(f, f.fork());
913                  f.quietlyJoin();
# Line 842 | Line 921 | public class CountedCompleterTest extend
921       */
922      public void testGetPool() {
923          final ForkJoinPool mainPool = mainPool();
924 <       ForkJoinTask a =  new CheckedFJTask() {
925 <            public void realCompute() {
924 >        ForkJoinTask a = new CheckedRecursiveAction() {
925 >            protected void realCompute() {
926                  assertSame(mainPool, getPool());
927              }};
928          testInvokeOnPool(mainPool, a);
# Line 853 | Line 932 | public class CountedCompleterTest extend
932       * getPool of non-FJ task returns null
933       */
934      public void testGetPool2() {
935 <       ForkJoinTask a =  new CheckedFJTask() {
936 <            public void realCompute() {
935 >        ForkJoinTask a = new CheckedRecursiveAction() {
936 >            protected void realCompute() {
937                  assertNull(getPool());
938              }};
939          assertNull(a.invoke());
# Line 864 | Line 943 | public class CountedCompleterTest extend
943       * inForkJoinPool of executing task returns true
944       */
945      public void testInForkJoinPool() {
946 <       ForkJoinTask a =  new CheckedFJTask() {
947 <            public void realCompute() {
946 >        ForkJoinTask a = new CheckedRecursiveAction() {
947 >            protected void realCompute() {
948                  assertTrue(inForkJoinPool());
949              }};
950          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 954 | public class CountedCompleterTest extend
954       * inForkJoinPool of non-FJ task returns false
955       */
956      public void testInForkJoinPool2() {
957 <       ForkJoinTask a =  new CheckedFJTask() {
958 <            public void realCompute() {
957 >        ForkJoinTask a = new CheckedRecursiveAction() {
958 >            protected void realCompute() {
959                  assertFalse(inForkJoinPool());
960              }};
961          assertNull(a.invoke());
# Line 886 | Line 965 | public class CountedCompleterTest extend
965       * setRawResult(null) succeeds
966       */
967      public void testSetRawResult() {
968 <       ForkJoinTask a =  new CheckedFJTask() {
969 <            public void realCompute() {
968 >        ForkJoinTask a = new CheckedRecursiveAction() {
969 >            protected void realCompute() {
970                  setRawResult(null);
971                  assertNull(getRawResult());
972              }};
# Line 898 | Line 977 | public class CountedCompleterTest extend
977       * invoke task throws exception after invoking completeExceptionally
978       */
979      public void testCompleteExceptionally2() {
980 <       ForkJoinTask a =  new CheckedFJTask() {
981 <            public void realCompute() {
982 <                CCF f = new LCCF(null, 8);
983 <                f.completeExceptionally(new FJException());
984 <                try {
985 <                    f.invoke();
986 <                    shouldThrow();
987 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
980 >        ForkJoinTask a = new CheckedRecursiveAction() {
981 >            protected void realCompute() {
982 >                CCF n = new LCCF(8);
983 >                CCF f = new LCCF(n, 8);
984 >                FJException ex = new FJException();
985 >                f.completeExceptionally(ex);
986 >                f.checkCompletedExceptionally(ex);
987 >                n.checkCompletedExceptionally(ex);
988              }};
989          testInvokeOnPool(mainPool(), a);
990      }
# Line 916 | Line 993 | public class CountedCompleterTest extend
993       * invokeAll(t1, t2) invokes all task arguments
994       */
995      public void testInvokeAll2() {
996 <       ForkJoinTask a =  new CheckedFJTask() {
997 <            public void realCompute() {
998 <                CCF f = new LCCF(null, 8);
999 <                CCF g = new LCCF(null, 9);
996 >        ForkJoinTask a = new CheckedRecursiveAction() {
997 >            protected void realCompute() {
998 >                CCF f = new LCCF(8);
999 >                CCF g = new LCCF(9);
1000                  invokeAll(f, g);
1001                  assertEquals(21, f.number);
1002                  assertEquals(34, g.number);
# Line 933 | Line 1010 | public class CountedCompleterTest extend
1010       * invokeAll(tasks) with 1 argument invokes task
1011       */
1012      public void testInvokeAll1() {
1013 <       ForkJoinTask a =  new CheckedFJTask() {
1014 <            public void realCompute() {
1015 <                CCF f = new LCCF(null, 8);
1013 >        ForkJoinTask a = new CheckedRecursiveAction() {
1014 >            protected void realCompute() {
1015 >                CCF f = new LCCF(8);
1016                  invokeAll(f);
1017                  checkCompletedNormally(f);
1018                  assertEquals(21, f.number);
# Line 947 | Line 1024 | public class CountedCompleterTest extend
1024       * invokeAll(tasks) with > 2 argument invokes tasks
1025       */
1026      public void testInvokeAll3() {
1027 <       ForkJoinTask a =  new CheckedFJTask() {
1028 <            public void realCompute() {
1029 <                CCF f = new LCCF(null, 8);
1030 <                CCF g = new LCCF(null, 9);
1031 <                CCF h = new LCCF(null, 7);
1027 >        ForkJoinTask a = new CheckedRecursiveAction() {
1028 >            protected void realCompute() {
1029 >                CCF f = new LCCF(8);
1030 >                CCF g = new LCCF(9);
1031 >                CCF h = new LCCF(7);
1032                  invokeAll(f, g, h);
1033                  assertEquals(21, f.number);
1034                  assertEquals(34, g.number);
# Line 967 | Line 1044 | public class CountedCompleterTest extend
1044       * invokeAll(collection) invokes all tasks in the collection
1045       */
1046      public void testInvokeAllCollection() {
1047 <       ForkJoinTask a =  new CheckedFJTask() {
1048 <            public void realCompute() {
1049 <                CCF f = new LCCF(null, 8);
1050 <                CCF g = new LCCF(null, 9);
1051 <                CCF h = new LCCF(null, 7);
1047 >        ForkJoinTask a = new CheckedRecursiveAction() {
1048 >            protected void realCompute() {
1049 >                CCF f = new LCCF(8);
1050 >                CCF g = new LCCF(9);
1051 >                CCF h = new LCCF(7);
1052                  HashSet set = new HashSet();
1053                  set.add(f);
1054                  set.add(g);
# Line 991 | Line 1068 | public class CountedCompleterTest extend
1068       * invokeAll(tasks) with any null task throws NPE
1069       */
1070      public void testInvokeAllNPE() {
1071 <       ForkJoinTask a =  new CheckedFJTask() {
1072 <            public void realCompute() {
1073 <                CCF f = new LCCF(null, 8);
1074 <                CCF g = new LCCF(null, 9);
1071 >        ForkJoinTask a = new CheckedRecursiveAction() {
1072 >            protected void realCompute() {
1073 >                CCF f = new LCCF(8);
1074 >                CCF g = new LCCF(9);
1075                  CCF h = null;
1076                  try {
1077                      invokeAll(f, g, h);
# Line 1008 | Line 1085 | public class CountedCompleterTest extend
1085       * invokeAll(t1, t2) throw exception if any task does
1086       */
1087      public void testAbnormalInvokeAll2() {
1088 <       ForkJoinTask a =  new CheckedFJTask() {
1089 <            public void realCompute() {
1090 <                CCF f = new LCCF(null, 8);
1091 <                FailingCCF g = new LFCCF(null, 9);
1088 >        ForkJoinTask a = new CheckedRecursiveAction() {
1089 >            protected void realCompute() {
1090 >                CCF f = new LCCF(8);
1091 >                FailingCCF g = new LFCCF(9);
1092                  try {
1093                      invokeAll(f, g);
1094                      shouldThrow();
# Line 1026 | Line 1103 | public class CountedCompleterTest extend
1103       * invokeAll(tasks) with 1 argument throws exception if task does
1104       */
1105      public void testAbnormalInvokeAll1() {
1106 <       ForkJoinTask a =  new CheckedFJTask() {
1107 <            public void realCompute() {
1108 <                FailingCCF g = new LFCCF(null, 9);
1106 >        ForkJoinTask a = new CheckedRecursiveAction() {
1107 >            protected void realCompute() {
1108 >                FailingCCF g = new LFCCF(9);
1109                  try {
1110                      invokeAll(g);
1111                      shouldThrow();
# Line 1043 | Line 1120 | public class CountedCompleterTest extend
1120       * invokeAll(tasks) with > 2 argument throws exception if any task does
1121       */
1122      public void testAbnormalInvokeAll3() {
1123 <       ForkJoinTask a =  new CheckedFJTask() {
1124 <            public void realCompute() {
1125 <                CCF f = new LCCF(null, 8);
1126 <                FailingCCF g = new LFCCF(null, 9);
1127 <                CCF h = new LCCF(null, 7);
1123 >        ForkJoinTask a = new CheckedRecursiveAction() {
1124 >            protected void realCompute() {
1125 >                CCF f = new LCCF(8);
1126 >                FailingCCF g = new LFCCF(9);
1127 >                CCF h = new LCCF(7);
1128                  try {
1129                      invokeAll(f, g, h);
1130                      shouldThrow();
# Line 1062 | Line 1139 | public class CountedCompleterTest extend
1139       * invokeAll(collection)  throws exception if any task does
1140       */
1141      public void testAbnormalInvokeAllCollection() {
1142 <       ForkJoinTask a =  new CheckedFJTask() {
1143 <            public void realCompute() {
1144 <                FailingCCF f = new LFCCF(null, 8);
1145 <                CCF g = new LCCF(null, 9);
1146 <                CCF h = new LCCF(null, 7);
1142 >        ForkJoinTask a = new CheckedRecursiveAction() {
1143 >            protected void realCompute() {
1144 >                FailingCCF f = new LFCCF(8);
1145 >                CCF g = new LCCF(9);
1146 >                CCF h = new LCCF(7);
1147                  HashSet set = new HashSet();
1148                  set.add(f);
1149                  set.add(g);
# Line 1086 | Line 1163 | public class CountedCompleterTest extend
1163       * and suppresses execution
1164       */
1165      public void testTryUnfork() {
1166 <       ForkJoinTask a =  new CheckedFJTask() {
1167 <            public void realCompute() {
1168 <                CCF g = new LCCF(null, 9);
1166 >        ForkJoinTask a = new CheckedRecursiveAction() {
1167 >            protected void realCompute() {
1168 >                CCF g = new LCCF(9);
1169                  assertSame(g, g.fork());
1170 <                CCF f = new LCCF(null, 8);
1170 >                CCF f = new LCCF(8);
1171                  assertSame(f, f.fork());
1172                  assertTrue(f.tryUnfork());
1173                  helpQuiesce();
# Line 1105 | Line 1182 | public class CountedCompleterTest extend
1182       * there are more tasks than threads
1183       */
1184      public void testGetSurplusQueuedTaskCount() {
1185 <       ForkJoinTask a =  new CheckedFJTask() {
1186 <            public void realCompute() {
1187 <                CCF h = new LCCF(null, 7);
1185 >        ForkJoinTask a = new CheckedRecursiveAction() {
1186 >            protected void realCompute() {
1187 >                CCF h = new LCCF(7);
1188                  assertSame(h, h.fork());
1189 <                CCF g = new LCCF(null, 9);
1189 >                CCF g = new LCCF(9);
1190                  assertSame(g, g.fork());
1191 <                CCF f = new LCCF(null, 8);
1191 >                CCF f = new LCCF(8);
1192                  assertSame(f, f.fork());
1193                  assertTrue(getSurplusQueuedTaskCount() > 0);
1194                  helpQuiesce();
# Line 1127 | Line 1204 | public class CountedCompleterTest extend
1204       * peekNextLocalTask returns most recent unexecuted task.
1205       */
1206      public void testPeekNextLocalTask() {
1207 <       ForkJoinTask a =  new CheckedFJTask() {
1208 <            public void realCompute() {
1209 <                CCF g = new LCCF(null, 9);
1207 >        ForkJoinTask a = new CheckedRecursiveAction() {
1208 >            protected void realCompute() {
1209 >                CCF g = new LCCF(9);
1210                  assertSame(g, g.fork());
1211 <                CCF f = new LCCF(null, 8);
1211 >                CCF f = new LCCF(8);
1212                  assertSame(f, f.fork());
1213                  assertSame(f, peekNextLocalTask());
1214                  assertNull(f.join());
# Line 1147 | Line 1224 | public class CountedCompleterTest extend
1224       * executing it
1225       */
1226      public void testPollNextLocalTask() {
1227 <       ForkJoinTask a =  new CheckedFJTask() {
1228 <            public void realCompute() {
1229 <                CCF g = new LCCF(null, 9);
1227 >        ForkJoinTask a = new CheckedRecursiveAction() {
1228 >            protected void realCompute() {
1229 >                CCF g = new LCCF(9);
1230                  assertSame(g, g.fork());
1231 <                CCF f = new LCCF(null, 8);
1231 >                CCF f = new LCCF(8);
1232                  assertSame(f, f.fork());
1233                  assertSame(f, pollNextLocalTask());
1234                  helpQuiesce();
# Line 1166 | Line 1243 | public class CountedCompleterTest extend
1243       * pollTask returns an unexecuted task without executing it
1244       */
1245      public void testPollTask() {
1246 <       ForkJoinTask a =  new CheckedFJTask() {
1247 <            public void realCompute() {
1248 <                CCF g = new LCCF(null, 9);
1246 >        ForkJoinTask a = new CheckedRecursiveAction() {
1247 >            protected void realCompute() {
1248 >                CCF g = new LCCF(9);
1249                  assertSame(g, g.fork());
1250 <                CCF f = new LCCF(null, 8);
1250 >                CCF f = new LCCF(8);
1251                  assertSame(f, f.fork());
1252                  assertSame(f, pollTask());
1253                  helpQuiesce();
# Line 1184 | Line 1261 | public class CountedCompleterTest extend
1261       * peekNextLocalTask returns least recent unexecuted task in async mode
1262       */
1263      public void testPeekNextLocalTaskAsync() {
1264 <       ForkJoinTask a =  new CheckedFJTask() {
1265 <            public void realCompute() {
1266 <                CCF g = new LCCF(null, 9);
1264 >        ForkJoinTask a = new CheckedRecursiveAction() {
1265 >            protected void realCompute() {
1266 >                CCF g = new LCCF(9);
1267                  assertSame(g, g.fork());
1268 <                CCF f = new LCCF(null, 8);
1268 >                CCF f = new LCCF(8);
1269                  assertSame(f, f.fork());
1270                  assertSame(g, peekNextLocalTask());
1271                  assertNull(f.join());
# Line 1205 | Line 1282 | public class CountedCompleterTest extend
1282       * executing it, in async mode
1283       */
1284      public void testPollNextLocalTaskAsync() {
1285 <       ForkJoinTask a =  new CheckedFJTask() {
1286 <            public void realCompute() {
1287 <                CCF g = new LCCF(null, 9);
1285 >        ForkJoinTask a = new CheckedRecursiveAction() {
1286 >            protected void realCompute() {
1287 >                CCF g = new LCCF(9);
1288                  assertSame(g, g.fork());
1289 <                CCF f = new LCCF(null, 8);
1289 >                CCF f = new LCCF(8);
1290                  assertSame(f, f.fork());
1291                  assertSame(g, pollNextLocalTask());
1292                  helpQuiesce();
# Line 1225 | Line 1302 | public class CountedCompleterTest extend
1302       * async mode
1303       */
1304      public void testPollTaskAsync() {
1305 <       ForkJoinTask a =  new CheckedFJTask() {
1306 <            public void realCompute() {
1307 <                CCF g = new LCCF(null, 9);
1305 >        ForkJoinTask a = new CheckedRecursiveAction() {
1306 >            protected void realCompute() {
1307 >                CCF g = new LCCF(9);
1308                  assertSame(g, g.fork());
1309 <                CCF f = new LCCF(null, 8);
1309 >                CCF f = new LCCF(8);
1310                  assertSame(f, f.fork());
1311                  assertSame(g, pollTask());
1312                  helpQuiesce();
# Line 1248 | Line 1325 | public class CountedCompleterTest extend
1325       * completed tasks; getRawResult returns null.
1326       */
1327      public void testInvokeSingleton() {
1328 <       ForkJoinTask a =  new CheckedFJTask() {
1329 <            public void realCompute() {
1330 <                CCF f = new LCCF(null, 8);
1328 >        ForkJoinTask a = new CheckedRecursiveAction() {
1329 >            protected void realCompute() {
1330 >                CCF f = new LCCF(8);
1331                  assertNull(f.invoke());
1332                  assertEquals(21, f.number);
1333                  checkCompletedNormally(f);
# Line 1264 | Line 1341 | public class CountedCompleterTest extend
1341       * completed tasks
1342       */
1343      public void testQuietlyInvokeSingleton() {
1344 <       ForkJoinTask a =  new CheckedFJTask() {
1345 <            public void realCompute() {
1346 <                CCF f = new LCCF(null, 8);
1344 >        ForkJoinTask a = new CheckedRecursiveAction() {
1345 >            protected void realCompute() {
1346 >                CCF f = new LCCF(8);
1347                  f.quietlyInvoke();
1348                  assertEquals(21, f.number);
1349                  checkCompletedNormally(f);
# Line 1278 | Line 1355 | public class CountedCompleterTest extend
1355       * join of a forked task returns when task completes
1356       */
1357      public void testForkJoinSingleton() {
1358 <       ForkJoinTask a =  new CheckedFJTask() {
1359 <            public void realCompute() {
1360 <                CCF f = new LCCF(null, 8);
1358 >        ForkJoinTask a = new CheckedRecursiveAction() {
1359 >            protected void realCompute() {
1360 >                CCF f = new LCCF(8);
1361                  assertSame(f, f.fork());
1362                  assertNull(f.join());
1363                  assertEquals(21, f.number);
# Line 1293 | Line 1370 | public class CountedCompleterTest extend
1370       * get of a forked task returns when task completes
1371       */
1372      public void testForkGetSingleton() {
1373 <       ForkJoinTask a =  new CheckedFJTask() {
1374 <            public void realCompute() throws Exception {
1375 <                CCF f = new LCCF(null, 8);
1373 >        ForkJoinTask a = new CheckedRecursiveAction() {
1374 >            protected void realCompute() throws Exception {
1375 >                CCF f = new LCCF(8);
1376                  assertSame(f, f.fork());
1377                  assertNull(f.get());
1378                  assertEquals(21, f.number);
# Line 1308 | Line 1385 | public class CountedCompleterTest extend
1385       * timed get of a forked task returns when task completes
1386       */
1387      public void testForkTimedGetSingleton() {
1388 <       ForkJoinTask a =  new CheckedFJTask() {
1389 <            public void realCompute() throws Exception {
1390 <                CCF f = new LCCF(null, 8);
1388 >        ForkJoinTask a = new CheckedRecursiveAction() {
1389 >            protected void realCompute() throws Exception {
1390 >                CCF f = new LCCF(8);
1391                  assertSame(f, f.fork());
1392                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1393                  assertEquals(21, f.number);
# Line 1323 | Line 1400 | public class CountedCompleterTest extend
1400       * timed get with null time unit throws NPE
1401       */
1402      public void testForkTimedGetNPESingleton() {
1403 <       ForkJoinTask a =  new CheckedFJTask() {
1404 <            public void realCompute() throws Exception {
1405 <                CCF f = new LCCF(null, 8);
1403 >        ForkJoinTask a = new CheckedRecursiveAction() {
1404 >            protected void realCompute() throws Exception {
1405 >                CCF f = new LCCF(8);
1406                  assertSame(f, f.fork());
1407                  try {
1408                      f.get(5L, null);
# Line 1339 | Line 1416 | public class CountedCompleterTest extend
1416       * quietlyJoin of a forked task returns when task completes
1417       */
1418      public void testForkQuietlyJoinSingleton() {
1419 <       ForkJoinTask a =  new CheckedFJTask() {
1420 <            public void realCompute() {
1421 <                CCF f = new LCCF(null, 8);
1419 >        ForkJoinTask a = new CheckedRecursiveAction() {
1420 >            protected void realCompute() {
1421 >                CCF f = new LCCF(8);
1422                  assertSame(f, f.fork());
1423                  f.quietlyJoin();
1424                  assertEquals(21, f.number);
# Line 1355 | Line 1432 | public class CountedCompleterTest extend
1432       * getQueuedTaskCount returns 0 when quiescent
1433       */
1434      public void testForkHelpQuiesceSingleton() {
1435 <       ForkJoinTask a =  new CheckedFJTask() {
1436 <            public void realCompute() {
1437 <                CCF f = new LCCF(null, 8);
1435 >        ForkJoinTask a = new CheckedRecursiveAction() {
1436 >            protected void realCompute() {
1437 >                CCF f = new LCCF(8);
1438                  assertSame(f, f.fork());
1439                  helpQuiesce();
1440                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1448 | public class CountedCompleterTest extend
1448       * invoke task throws exception when task completes abnormally
1449       */
1450      public void testAbnormalInvokeSingleton() {
1451 <       ForkJoinTask a =  new CheckedFJTask() {
1452 <            public void realCompute() {
1453 <                FailingCCF f = new LFCCF(null, 8);
1451 >        ForkJoinTask a = new CheckedRecursiveAction() {
1452 >            protected void realCompute() {
1453 >                FailingCCF f = new LFCCF(8);
1454                  try {
1455                      f.invoke();
1456                      shouldThrow();
# Line 1388 | Line 1465 | public class CountedCompleterTest extend
1465       * quietlyInvoke task returns when task completes abnormally
1466       */
1467      public void testAbnormalQuietlyInvokeSingleton() {
1468 <       ForkJoinTask a =  new CheckedFJTask() {
1469 <            public void realCompute() {
1470 <                FailingCCF f = new LFCCF(null, 8);
1468 >        ForkJoinTask a = new CheckedRecursiveAction() {
1469 >            protected void realCompute() {
1470 >                FailingCCF f = new LFCCF(8);
1471                  f.quietlyInvoke();
1472                  assertTrue(f.getException() instanceof FJException);
1473                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1479 | public class CountedCompleterTest extend
1479       * join of a forked task throws exception when task completes abnormally
1480       */
1481      public void testAbnormalForkJoinSingleton() {
1482 <       ForkJoinTask a =  new CheckedFJTask() {
1483 <            public void realCompute() {
1484 <                FailingCCF f = new LFCCF(null, 8);
1482 >        ForkJoinTask a = new CheckedRecursiveAction() {
1483 >            protected void realCompute() {
1484 >                FailingCCF f = new LFCCF(8);
1485                  assertSame(f, f.fork());
1486                  try {
1487                      f.join();
# Line 1420 | Line 1497 | public class CountedCompleterTest extend
1497       * get of a forked task throws exception when task completes abnormally
1498       */
1499      public void testAbnormalForkGetSingleton() {
1500 <       ForkJoinTask a =  new CheckedFJTask() {
1501 <            public void realCompute() throws Exception {
1502 <                FailingCCF f = new LFCCF(null, 8);
1500 >        ForkJoinTask a = new CheckedRecursiveAction() {
1501 >            protected void realCompute() throws Exception {
1502 >                FailingCCF f = new LFCCF(8);
1503                  assertSame(f, f.fork());
1504                  try {
1505                      f.get();
# Line 1440 | Line 1517 | public class CountedCompleterTest extend
1517       * timed get of a forked task throws exception when task completes abnormally
1518       */
1519      public void testAbnormalForkTimedGetSingleton() {
1520 <       ForkJoinTask a =  new CheckedFJTask() {
1521 <            public void realCompute() throws Exception {
1522 <                FailingCCF f = new LFCCF(null, 8);
1520 >        ForkJoinTask a = new CheckedRecursiveAction() {
1521 >            protected void realCompute() throws Exception {
1522 >                FailingCCF f = new LFCCF(8);
1523                  assertSame(f, f.fork());
1524                  try {
1525                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1537 | public class CountedCompleterTest extend
1537       * quietlyJoin of a forked task returns when task completes abnormally
1538       */
1539      public void testAbnormalForkQuietlyJoinSingleton() {
1540 <       ForkJoinTask a =  new CheckedFJTask() {
1541 <            public void realCompute() {
1542 <                FailingCCF f = new LFCCF(null, 8);
1540 >        ForkJoinTask a = new CheckedRecursiveAction() {
1541 >            protected void realCompute() {
1542 >                FailingCCF f = new LFCCF(8);
1543                  assertSame(f, f.fork());
1544                  f.quietlyJoin();
1545                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1552 | public class CountedCompleterTest extend
1552       * invoke task throws exception when task cancelled
1553       */
1554      public void testCancelledInvokeSingleton() {
1555 <       ForkJoinTask a =  new CheckedFJTask() {
1556 <            public void realCompute() {
1557 <                CCF f = new LCCF(null, 8);
1555 >        ForkJoinTask a = new CheckedRecursiveAction() {
1556 >            protected void realCompute() {
1557 >                CCF f = new LCCF(8);
1558                  assertTrue(f.cancel(true));
1559                  try {
1560                      f.invoke();
# Line 1493 | Line 1570 | public class CountedCompleterTest extend
1570       * join of a forked task throws exception when task cancelled
1571       */
1572      public void testCancelledForkJoinSingleton() {
1573 <       ForkJoinTask a =  new CheckedFJTask() {
1574 <            public void realCompute() {
1575 <                CCF f = new LCCF(null, 8);
1573 >        ForkJoinTask a = new CheckedRecursiveAction() {
1574 >            protected void realCompute() {
1575 >                CCF f = new LCCF(8);
1576                  assertTrue(f.cancel(true));
1577                  assertSame(f, f.fork());
1578                  try {
# Line 1512 | Line 1589 | public class CountedCompleterTest extend
1589       * get of a forked task throws exception when task cancelled
1590       */
1591      public void testCancelledForkGetSingleton() {
1592 <       ForkJoinTask a =  new CheckedFJTask() {
1593 <            public void realCompute() throws Exception {
1594 <                CCF f = new LCCF(null, 8);
1592 >        ForkJoinTask a = new CheckedRecursiveAction() {
1593 >            protected void realCompute() throws Exception {
1594 >                CCF f = new LCCF(8);
1595                  assertTrue(f.cancel(true));
1596                  assertSame(f, f.fork());
1597                  try {
# Line 1531 | Line 1608 | public class CountedCompleterTest extend
1608       * timed get of a forked task throws exception when task cancelled
1609       */
1610      public void testCancelledForkTimedGetSingleton() throws Exception {
1611 <       ForkJoinTask a =  new CheckedFJTask() {
1612 <            public void realCompute() throws Exception {
1613 <                CCF f = new LCCF(null, 8);
1611 >        ForkJoinTask a = new CheckedRecursiveAction() {
1612 >            protected void realCompute() throws Exception {
1613 >                CCF f = new LCCF(8);
1614                  assertTrue(f.cancel(true));
1615                  assertSame(f, f.fork());
1616                  try {
# Line 1550 | Line 1627 | public class CountedCompleterTest extend
1627       * quietlyJoin of a forked task returns when task cancelled
1628       */
1629      public void testCancelledForkQuietlyJoinSingleton() {
1630 <       ForkJoinTask a =  new CheckedFJTask() {
1631 <            public void realCompute() {
1632 <                CCF f = new LCCF(null, 8);
1630 >        ForkJoinTask a = new CheckedRecursiveAction() {
1631 >            protected void realCompute() {
1632 >                CCF f = new LCCF(8);
1633                  assertTrue(f.cancel(true));
1634                  assertSame(f, f.fork());
1635                  f.quietlyJoin();
# Line 1565 | Line 1642 | public class CountedCompleterTest extend
1642       * invoke task throws exception after invoking completeExceptionally
1643       */
1644      public void testCompleteExceptionallySingleton() {
1645 <       ForkJoinTask a =  new CheckedFJTask() {
1646 <            public void realCompute() {
1647 <                CCF f = new LCCF(null, 8);
1648 <                f.completeExceptionally(new FJException());
1649 <                try {
1650 <                    f.invoke();
1651 <                    shouldThrow();
1652 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1645 >        ForkJoinTask a = new CheckedRecursiveAction() {
1646 >            protected void realCompute() {
1647 >                CCF n = new LCCF(8);
1648 >                CCF f = new LCCF(n, 8);
1649 >                FJException ex = new FJException();
1650 >                f.completeExceptionally(ex);
1651 >                f.checkCompletedExceptionally(ex);
1652 >                n.checkCompletedExceptionally(ex);
1653              }};
1654          testInvokeOnPool(singletonPool(), a);
1655      }
# Line 1583 | Line 1658 | public class CountedCompleterTest extend
1658       * invokeAll(t1, t2) invokes all task arguments
1659       */
1660      public void testInvokeAll2Singleton() {
1661 <       ForkJoinTask a =  new CheckedFJTask() {
1662 <            public void realCompute() {
1663 <                CCF f = new LCCF(null, 8);
1664 <                CCF g = new LCCF(null, 9);
1661 >        ForkJoinTask a = new CheckedRecursiveAction() {
1662 >            protected void realCompute() {
1663 >                CCF f = new LCCF(8);
1664 >                CCF g = new LCCF(9);
1665                  invokeAll(f, g);
1666                  assertEquals(21, f.number);
1667                  assertEquals(34, g.number);
# Line 1600 | Line 1675 | public class CountedCompleterTest extend
1675       * invokeAll(tasks) with 1 argument invokes task
1676       */
1677      public void testInvokeAll1Singleton() {
1678 <       ForkJoinTask a =  new CheckedFJTask() {
1679 <            public void realCompute() {
1680 <                CCF f = new LCCF(null, 8);
1678 >        ForkJoinTask a = new CheckedRecursiveAction() {
1679 >            protected void realCompute() {
1680 >                CCF f = new LCCF(8);
1681                  invokeAll(f);
1682                  checkCompletedNormally(f);
1683                  assertEquals(21, f.number);
# Line 1614 | Line 1689 | public class CountedCompleterTest extend
1689       * invokeAll(tasks) with > 2 argument invokes tasks
1690       */
1691      public void testInvokeAll3Singleton() {
1692 <       ForkJoinTask a =  new CheckedFJTask() {
1693 <            public void realCompute() {
1694 <                CCF f = new LCCF(null, 8);
1695 <                CCF g = new LCCF(null, 9);
1696 <                CCF h = new LCCF(null, 7);
1692 >        ForkJoinTask a = new CheckedRecursiveAction() {
1693 >            protected void realCompute() {
1694 >                CCF f = new LCCF(8);
1695 >                CCF g = new LCCF(9);
1696 >                CCF h = new LCCF(7);
1697                  invokeAll(f, g, h);
1698                  assertEquals(21, f.number);
1699                  assertEquals(34, g.number);
# Line 1634 | Line 1709 | public class CountedCompleterTest extend
1709       * invokeAll(collection) invokes all tasks in the collection
1710       */
1711      public void testInvokeAllCollectionSingleton() {
1712 <       ForkJoinTask a =  new CheckedFJTask() {
1713 <            public void realCompute() {
1714 <                CCF f = new LCCF(null, 8);
1715 <                CCF g = new LCCF(null, 9);
1716 <                CCF h = new LCCF(null, 7);
1712 >        ForkJoinTask a = new CheckedRecursiveAction() {
1713 >            protected void realCompute() {
1714 >                CCF f = new LCCF(8);
1715 >                CCF g = new LCCF(9);
1716 >                CCF h = new LCCF(7);
1717                  HashSet set = new HashSet();
1718                  set.add(f);
1719                  set.add(g);
# Line 1658 | Line 1733 | public class CountedCompleterTest extend
1733       * invokeAll(tasks) with any null task throws NPE
1734       */
1735      public void testInvokeAllNPESingleton() {
1736 <       ForkJoinTask a =  new CheckedFJTask() {
1737 <            public void realCompute() {
1738 <                CCF f = new LCCF(null, 8);
1739 <                CCF g = new LCCF(null, 9);
1736 >        ForkJoinTask a = new CheckedRecursiveAction() {
1737 >            protected void realCompute() {
1738 >                CCF f = new LCCF(8);
1739 >                CCF g = new LCCF(9);
1740                  CCF h = null;
1741                  try {
1742                      invokeAll(f, g, h);
# Line 1675 | Line 1750 | public class CountedCompleterTest extend
1750       * invokeAll(t1, t2) throw exception if any task does
1751       */
1752      public void testAbnormalInvokeAll2Singleton() {
1753 <       ForkJoinTask a =  new CheckedFJTask() {
1754 <            public void realCompute() {
1755 <                CCF f = new LCCF(null, 8);
1756 <                FailingCCF g = new LFCCF(null, 9);
1753 >        ForkJoinTask a = new CheckedRecursiveAction() {
1754 >            protected void realCompute() {
1755 >                CCF f = new LCCF(8);
1756 >                FailingCCF g = new LFCCF(9);
1757                  try {
1758                      invokeAll(f, g);
1759                      shouldThrow();
# Line 1693 | Line 1768 | public class CountedCompleterTest extend
1768       * invokeAll(tasks) with 1 argument throws exception if task does
1769       */
1770      public void testAbnormalInvokeAll1Singleton() {
1771 <       ForkJoinTask a =  new CheckedFJTask() {
1772 <            public void realCompute() {
1773 <                FailingCCF g = new LFCCF(null, 9);
1771 >        ForkJoinTask a = new CheckedRecursiveAction() {
1772 >            protected void realCompute() {
1773 >                FailingCCF g = new LFCCF(9);
1774                  try {
1775                      invokeAll(g);
1776                      shouldThrow();
# Line 1710 | Line 1785 | public class CountedCompleterTest extend
1785       * invokeAll(tasks) with > 2 argument throws exception if any task does
1786       */
1787      public void testAbnormalInvokeAll3Singleton() {
1788 <       ForkJoinTask a =  new CheckedFJTask() {
1789 <            public void realCompute() {
1790 <                CCF f = new LCCF(null, 8);
1791 <                FailingCCF g = new LFCCF(null, 9);
1792 <                CCF h = new LCCF(null, 7);
1788 >        ForkJoinTask a = new CheckedRecursiveAction() {
1789 >            protected void realCompute() {
1790 >                CCF f = new LCCF(8);
1791 >                FailingCCF g = new LFCCF(9);
1792 >                CCF h = new LCCF(7);
1793                  try {
1794                      invokeAll(f, g, h);
1795                      shouldThrow();
# Line 1729 | Line 1804 | public class CountedCompleterTest extend
1804       * invokeAll(collection)  throws exception if any task does
1805       */
1806      public void testAbnormalInvokeAllCollectionSingleton() {
1807 <       ForkJoinTask a =  new CheckedFJTask() {
1808 <            public void realCompute() {
1809 <                FailingCCF f = new LFCCF(null, 8);
1810 <                CCF g = new LCCF(null, 9);
1811 <                CCF h = new LCCF(null, 7);
1807 >        ForkJoinTask a = new CheckedRecursiveAction() {
1808 >            protected void realCompute() {
1809 >                FailingCCF f = new LFCCF(8);
1810 >                CCF g = new LCCF(9);
1811 >                CCF h = new LCCF(7);
1812                  HashSet set = new HashSet();
1813                  set.add(f);
1814                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines