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.18 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import java.util.concurrent.ExecutionException;
6 >
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13 + import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.CountedCompleter;
11 import java.util.concurrent.ForkJoinWorkerThread;
12 import java.util.concurrent.RecursiveAction;
13 import java.util.concurrent.TimeUnit;
16   import java.util.concurrent.TimeoutException;
17 < import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
18 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import static java.util.concurrent.TimeUnit.SECONDS;
20 < import java.util.HashSet;
21 < import junit.framework.*;
17 > import java.util.concurrent.atomic.AtomicInteger;
18 > import java.util.concurrent.atomic.AtomicReference;
19 >
20 > import junit.framework.Test;
21 > import junit.framework.TestSuite;
22  
23   public class CountedCompleterTest extends JSR166TestCase {
24  
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28  
29      public static Test suite() {
# 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 success) {
202 +            assertSame(t, success);
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<Object>(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.
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  
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  
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 invoking
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 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());
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 <
503 <    // Version of Fibonacci with different classes for left vs right forks
504 <    abstract static class CCF extends CountedCompleter {
502 >    /**
503 >     * Version of Fibonacci with different classes for left vs right forks
504 >     */
505 >    abstract class CCF extends CheckedCC {
506          int number;
507          int rnumber;
508  
# Line 425 | Line 511 | public class CountedCompleterTest extend
511              this.number = n;
512          }
513  
514 <        public final void compute() {
429 <            CountedCompleter p;
514 >        protected final void realCompute() {
515              CCF f = this;
516              int n = number;
517              while (n >= 2) {
518                  new RCCF(f, n - 2).fork();
519                  f = new LCCF(f, --n);
520              }
521 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
521 >            f.complete(null);
522          }
523      }
524  
525 <    static final class LCCF extends CCF {
525 >    final class LCCF extends CCF {
526 >        public LCCF(int n) { this(null, n); }
527          public LCCF(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 455 | Line 537 | public class CountedCompleterTest extend
537                  number = n;
538          }
539      }
540 <    static final class RCCF extends CCF {
540 >    final class RCCF extends CCF {
541          public RCCF(CountedCompleter parent, int n) {
542              super(parent, n);
543          }
544          public final void onCompletion(CountedCompleter caller) {
545 +            super.onCompletion(caller);
546              CCF p = (CCF)getCompleter();
547              int n = number + rnumber;
548              if (p != null)
# Line 470 | Line 553 | public class CountedCompleterTest extend
553      }
554  
555      // Version of CCF with forced failure in left completions
556 <    abstract static class FailingCCF extends CountedCompleter {
556 >    abstract class FailingCCF extends CheckedCC {
557          int number;
558          int rnumber;
559  
# Line 479 | Line 562 | public class CountedCompleterTest extend
562              this.number = n;
563          }
564  
565 <        public final void compute() {
483 <            CountedCompleter p;
565 >        protected final void realCompute() {
566              FailingCCF f = this;
567              int n = number;
568              while (n >= 2) {
569                  new RFCCF(f, n - 2).fork();
570                  f = new LFCCF(f, --n);
571              }
572 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
572 >            f.complete(null);
573          }
574      }
575  
576 <    static final class LFCCF extends FailingCCF {
576 >    final class LFCCF extends FailingCCF {
577 >        public LFCCF(int n) { this(null, n); }
578          public LFCCF(CountedCompleter parent, int n) {
579              super(parent, n);
580          }
581          public final void onCompletion(CountedCompleter caller) {
582 +            super.onCompletion(caller);
583              FailingCCF p = (FailingCCF)getCompleter();
584              int n = number + rnumber;
585              if (p != null)
# Line 509 | Line 588 | public class CountedCompleterTest extend
588                  number = n;
589          }
590      }
591 <    static final class RFCCF extends FailingCCF {
591 >    final class RFCCF extends FailingCCF {
592          public RFCCF(CountedCompleter parent, int n) {
593              super(parent, n);
594          }
595          public final void onCompletion(CountedCompleter caller) {
596 +            super.onCompletion(caller);
597              completeExceptionally(new FJException());
598          }
599      }
# Line 524 | Line 604 | public class CountedCompleterTest extend
604       * completed tasks; getRawResult returns null.
605       */
606      public void testInvoke() {
607 <       ForkJoinTask a = new CheckedFJTask() {
608 <            public void realCompute() {
609 <                CCF f = new LCCF(null, 8);
607 >        ForkJoinTask a = new CheckedRecursiveAction() {
608 >            protected void realCompute() {
609 >                CCF f = new LCCF(8);
610                  assertNull(f.invoke());
611                  assertEquals(21, f.number);
612                  checkCompletedNormally(f);
# Line 540 | Line 620 | public class CountedCompleterTest extend
620       * completed tasks
621       */
622      public void testQuietlyInvoke() {
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                  f.quietlyInvoke();
627                  assertEquals(21, f.number);
628                  checkCompletedNormally(f);
# Line 554 | Line 634 | public class CountedCompleterTest extend
634       * join of a forked task returns when task completes
635       */
636      public void testForkJoin() {
637 <       ForkJoinTask a = new CheckedFJTask() {
638 <            public void realCompute() {
639 <                CCF f = new LCCF(null, 8);
637 >        ForkJoinTask a = new CheckedRecursiveAction() {
638 >            protected void realCompute() {
639 >                CCF f = new LCCF(8);
640                  assertSame(f, f.fork());
641                  assertNull(f.join());
642                  assertEquals(21, f.number);
# Line 569 | Line 649 | public class CountedCompleterTest extend
649       * get of a forked task returns when task completes
650       */
651      public void testForkGet() {
652 <       ForkJoinTask a = new CheckedFJTask() {
653 <            public void realCompute() throws Exception {
654 <                CCF f = new LCCF(null, 8);
652 >        ForkJoinTask a = new CheckedRecursiveAction() {
653 >            protected void realCompute() throws Exception {
654 >                CCF f = new LCCF(8);
655                  assertSame(f, f.fork());
656                  assertNull(f.get());
657                  assertEquals(21, f.number);
# Line 584 | Line 664 | public class CountedCompleterTest extend
664       * timed get of a forked task returns when task completes
665       */
666      public void testForkTimedGet() {
667 <       ForkJoinTask a = new CheckedFJTask() {
668 <            public void realCompute() throws Exception {
669 <                CCF f = new LCCF(null, 8);
667 >        ForkJoinTask a = new CheckedRecursiveAction() {
668 >            protected void realCompute() throws Exception {
669 >                CCF f = new LCCF(8);
670                  assertSame(f, f.fork());
671                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
672                  assertEquals(21, f.number);
# Line 599 | Line 679 | public class CountedCompleterTest extend
679       * timed get with null time unit throws NPE
680       */
681      public void testForkTimedGetNPE() {
682 <       ForkJoinTask a = new CheckedFJTask() {
683 <            public void realCompute() throws Exception {
684 <                CCF f = new LCCF(null, 8);
682 >        ForkJoinTask a = new CheckedRecursiveAction() {
683 >            protected void realCompute() throws Exception {
684 >                CCF f = new LCCF(8);
685                  assertSame(f, f.fork());
686                  try {
687                      f.get(5L, null);
# Line 615 | Line 695 | public class CountedCompleterTest extend
695       * quietlyJoin of a forked task returns when task completes
696       */
697      public void testForkQuietlyJoin() {
698 <       ForkJoinTask a = new CheckedFJTask() {
699 <            public void realCompute() {
700 <                CCF f = new LCCF(null, 8);
698 >        ForkJoinTask a = new CheckedRecursiveAction() {
699 >            protected void realCompute() {
700 >                CCF f = new LCCF(8);
701                  assertSame(f, f.fork());
702                  f.quietlyJoin();
703                  assertEquals(21, f.number);
# Line 631 | Line 711 | public class CountedCompleterTest extend
711       * getQueuedTaskCount returns 0 when quiescent
712       */
713      public void testForkHelpQuiesce() {
714 <       ForkJoinTask a = new CheckedFJTask() {
715 <            public void realCompute() {
716 <                CCF f = new LCCF(null, 8);
714 >        ForkJoinTask a = new CheckedRecursiveAction() {
715 >            protected void realCompute() {
716 >                CCF f = new LCCF(8);
717                  assertSame(f, f.fork());
718                  helpQuiesce();
719                  assertEquals(21, f.number);
# Line 647 | Line 727 | public class CountedCompleterTest extend
727       * invoke task throws exception when task completes abnormally
728       */
729      public void testAbnormalInvoke() {
730 <       ForkJoinTask a = new CheckedFJTask() {
731 <            public void realCompute() {
732 <                FailingCCF f = new LFCCF(null, 8);
730 >        ForkJoinTask a = new CheckedRecursiveAction() {
731 >            protected void realCompute() {
732 >                FailingCCF f = new LFCCF(8);
733                  try {
734                      f.invoke();
735                      shouldThrow();
# Line 664 | Line 744 | public class CountedCompleterTest extend
744       * quietlyInvoke task returns when task completes abnormally
745       */
746      public void testAbnormalQuietlyInvoke() {
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                  f.quietlyInvoke();
751                  assertTrue(f.getException() instanceof FJException);
752                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 758 | public class CountedCompleterTest extend
758       * join of a forked task throws exception when task completes abnormally
759       */
760      public void testAbnormalForkJoin() {
761 <       ForkJoinTask a = new CheckedFJTask() {
762 <            public void realCompute() {
763 <                FailingCCF f = new LFCCF(null, 8);
761 >        ForkJoinTask a = new CheckedRecursiveAction() {
762 >            protected void realCompute() {
763 >                FailingCCF f = new LFCCF(8);
764                  assertSame(f, f.fork());
765                  try {
766                      f.join();
# Line 696 | Line 776 | public class CountedCompleterTest extend
776       * get of a forked task throws exception when task completes abnormally
777       */
778      public void testAbnormalForkGet() {
779 <       ForkJoinTask a = new CheckedFJTask() {
780 <            public void realCompute() throws Exception {
781 <                FailingCCF f = new LFCCF(null, 8);
779 >        ForkJoinTask a = new CheckedRecursiveAction() {
780 >            protected void realCompute() throws Exception {
781 >                FailingCCF f = new LFCCF(8);
782                  assertSame(f, f.fork());
783                  try {
784                      f.get();
# Line 716 | Line 796 | public class CountedCompleterTest extend
796       * timed get of a forked task throws exception when task completes abnormally
797       */
798      public void testAbnormalForkTimedGet() {
799 <       ForkJoinTask a = new CheckedFJTask() {
800 <            public void realCompute() throws Exception {
801 <                FailingCCF f = new LFCCF(null, 8);
799 >        ForkJoinTask a = new CheckedRecursiveAction() {
800 >            protected void realCompute() throws Exception {
801 >                FailingCCF f = new LFCCF(8);
802                  assertSame(f, f.fork());
803                  try {
804                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 816 | public class CountedCompleterTest extend
816       * quietlyJoin of a forked task returns when task completes abnormally
817       */
818      public void testAbnormalForkQuietlyJoin() {
819 <       ForkJoinTask a = new CheckedFJTask() {
820 <            public void realCompute() {
821 <                FailingCCF f = new LFCCF(null, 8);
819 >        ForkJoinTask a = new CheckedRecursiveAction() {
820 >            protected void realCompute() {
821 >                FailingCCF f = new LFCCF(8);
822                  assertSame(f, f.fork());
823                  f.quietlyJoin();
824                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 831 | public class CountedCompleterTest extend
831       * invoke task throws exception when task cancelled
832       */
833      public void testCancelledInvoke() {
834 <       ForkJoinTask a = new CheckedFJTask() {
835 <            public void realCompute() {
836 <                CCF f = new LCCF(null, 8);
834 >        ForkJoinTask a = new CheckedRecursiveAction() {
835 >            protected void realCompute() {
836 >                CCF f = new LCCF(8);
837                  assertTrue(f.cancel(true));
838                  try {
839                      f.invoke();
# Line 769 | Line 849 | public class CountedCompleterTest extend
849       * join of a forked task throws exception when task cancelled
850       */
851      public void testCancelledForkJoin() {
852 <       ForkJoinTask a = new CheckedFJTask() {
853 <            public void realCompute() {
854 <                CCF f = new LCCF(null, 8);
852 >        ForkJoinTask a = new CheckedRecursiveAction() {
853 >            protected void realCompute() {
854 >                CCF f = new LCCF(8);
855                  assertTrue(f.cancel(true));
856                  assertSame(f, f.fork());
857                  try {
# Line 788 | Line 868 | public class CountedCompleterTest extend
868       * get of a forked task throws exception when task cancelled
869       */
870      public void testCancelledForkGet() {
871 <       ForkJoinTask a = new CheckedFJTask() {
872 <            public void realCompute() throws Exception {
873 <                CCF f = new LCCF(null, 8);
871 >        ForkJoinTask a = new CheckedRecursiveAction() {
872 >            protected void realCompute() throws Exception {
873 >                CCF f = new LCCF(8);
874                  assertTrue(f.cancel(true));
875                  assertSame(f, f.fork());
876                  try {
# Line 807 | Line 887 | public class CountedCompleterTest extend
887       * timed get of a forked task throws exception when task cancelled
888       */
889      public void testCancelledForkTimedGet() throws Exception {
890 <       ForkJoinTask a = new CheckedFJTask() {
891 <            public void realCompute() throws Exception {
892 <                CCF f = new LCCF(null, 8);
890 >        ForkJoinTask a = new CheckedRecursiveAction() {
891 >            protected void realCompute() throws Exception {
892 >                CCF f = new LCCF(8);
893                  assertTrue(f.cancel(true));
894                  assertSame(f, f.fork());
895                  try {
# Line 826 | Line 906 | public class CountedCompleterTest extend
906       * quietlyJoin of a forked task returns when task cancelled
907       */
908      public void testCancelledForkQuietlyJoin() {
909 <       ForkJoinTask a = new CheckedFJTask() {
910 <            public void realCompute() {
911 <                CCF f = new LCCF(null, 8);
909 >        ForkJoinTask a = new CheckedRecursiveAction() {
910 >            protected void realCompute() {
911 >                CCF f = new LCCF(8);
912                  assertTrue(f.cancel(true));
913                  assertSame(f, f.fork());
914                  f.quietlyJoin();
# Line 842 | Line 922 | public class CountedCompleterTest extend
922       */
923      public void testGetPool() {
924          final ForkJoinPool mainPool = mainPool();
925 <       ForkJoinTask a = new CheckedFJTask() {
926 <            public void realCompute() {
925 >        ForkJoinTask a = new CheckedRecursiveAction() {
926 >            protected void realCompute() {
927                  assertSame(mainPool, getPool());
928              }};
929          testInvokeOnPool(mainPool, a);
# Line 853 | Line 933 | public class CountedCompleterTest extend
933       * getPool of non-FJ task returns null
934       */
935      public void testGetPool2() {
936 <       ForkJoinTask a = new CheckedFJTask() {
937 <            public void realCompute() {
936 >        ForkJoinTask a = new CheckedRecursiveAction() {
937 >            protected void realCompute() {
938                  assertNull(getPool());
939              }};
940          assertNull(a.invoke());
# Line 864 | Line 944 | public class CountedCompleterTest extend
944       * inForkJoinPool of executing task returns true
945       */
946      public void testInForkJoinPool() {
947 <       ForkJoinTask a = new CheckedFJTask() {
948 <            public void realCompute() {
947 >        ForkJoinTask a = new CheckedRecursiveAction() {
948 >            protected void realCompute() {
949                  assertTrue(inForkJoinPool());
950              }};
951          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 955 | public class CountedCompleterTest extend
955       * inForkJoinPool of non-FJ task returns false
956       */
957      public void testInForkJoinPool2() {
958 <       ForkJoinTask a = new CheckedFJTask() {
959 <            public void realCompute() {
958 >        ForkJoinTask a = new CheckedRecursiveAction() {
959 >            protected void realCompute() {
960                  assertFalse(inForkJoinPool());
961              }};
962          assertNull(a.invoke());
# Line 886 | Line 966 | public class CountedCompleterTest extend
966       * setRawResult(null) succeeds
967       */
968      public void testSetRawResult() {
969 <       ForkJoinTask a = new CheckedFJTask() {
970 <            public void realCompute() {
969 >        ForkJoinTask a = new CheckedRecursiveAction() {
970 >            protected void realCompute() {
971                  setRawResult(null);
972                  assertNull(getRawResult());
973              }};
# Line 898 | Line 978 | public class CountedCompleterTest extend
978       * invoke task throws exception after invoking completeExceptionally
979       */
980      public void testCompleteExceptionally2() {
981 <       ForkJoinTask a = new CheckedFJTask() {
982 <            public void realCompute() {
983 <                CCF f = new LCCF(null, 8);
984 <                f.completeExceptionally(new FJException());
985 <                try {
986 <                    f.invoke();
987 <                    shouldThrow();
988 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
981 >        ForkJoinTask a = new CheckedRecursiveAction() {
982 >            protected void realCompute() {
983 >                CCF n = new LCCF(8);
984 >                CCF f = new LCCF(n, 8);
985 >                FJException ex = new FJException();
986 >                f.completeExceptionally(ex);
987 >                f.checkCompletedExceptionally(ex);
988 >                n.checkCompletedExceptionally(ex);
989              }};
990          testInvokeOnPool(mainPool(), a);
991      }
# Line 916 | Line 994 | public class CountedCompleterTest extend
994       * invokeAll(t1, t2) invokes all task arguments
995       */
996      public void testInvokeAll2() {
997 <       ForkJoinTask a = new CheckedFJTask() {
998 <            public void realCompute() {
999 <                CCF f = new LCCF(null, 8);
1000 <                CCF g = new LCCF(null, 9);
997 >        ForkJoinTask a = new CheckedRecursiveAction() {
998 >            protected void realCompute() {
999 >                CCF f = new LCCF(8);
1000 >                CCF g = new LCCF(9);
1001                  invokeAll(f, g);
1002                  assertEquals(21, f.number);
1003                  assertEquals(34, g.number);
# Line 933 | Line 1011 | public class CountedCompleterTest extend
1011       * invokeAll(tasks) with 1 argument invokes task
1012       */
1013      public void testInvokeAll1() {
1014 <       ForkJoinTask a = new CheckedFJTask() {
1015 <            public void realCompute() {
1016 <                CCF f = new LCCF(null, 8);
1014 >        ForkJoinTask a = new CheckedRecursiveAction() {
1015 >            protected void realCompute() {
1016 >                CCF f = new LCCF(8);
1017                  invokeAll(f);
1018                  checkCompletedNormally(f);
1019                  assertEquals(21, f.number);
# Line 947 | Line 1025 | public class CountedCompleterTest extend
1025       * invokeAll(tasks) with > 2 argument invokes tasks
1026       */
1027      public void testInvokeAll3() {
1028 <       ForkJoinTask a = new CheckedFJTask() {
1029 <            public void realCompute() {
1030 <                CCF f = new LCCF(null, 8);
1031 <                CCF g = new LCCF(null, 9);
1032 <                CCF h = new LCCF(null, 7);
1028 >        ForkJoinTask a = new CheckedRecursiveAction() {
1029 >            protected void realCompute() {
1030 >                CCF f = new LCCF(8);
1031 >                CCF g = new LCCF(9);
1032 >                CCF h = new LCCF(7);
1033                  invokeAll(f, g, h);
1034                  assertEquals(21, f.number);
1035                  assertEquals(34, g.number);
# Line 967 | Line 1045 | public class CountedCompleterTest extend
1045       * invokeAll(collection) invokes all tasks in the collection
1046       */
1047      public void testInvokeAllCollection() {
1048 <       ForkJoinTask a = new CheckedFJTask() {
1049 <            public void realCompute() {
1050 <                CCF f = new LCCF(null, 8);
1051 <                CCF g = new LCCF(null, 9);
1052 <                CCF h = new LCCF(null, 7);
1048 >        ForkJoinTask a = new CheckedRecursiveAction() {
1049 >            protected void realCompute() {
1050 >                CCF f = new LCCF(8);
1051 >                CCF g = new LCCF(9);
1052 >                CCF h = new LCCF(7);
1053                  HashSet set = new HashSet();
1054                  set.add(f);
1055                  set.add(g);
# Line 991 | Line 1069 | public class CountedCompleterTest extend
1069       * invokeAll(tasks) with any null task throws NPE
1070       */
1071      public void testInvokeAllNPE() {
1072 <       ForkJoinTask a = new CheckedFJTask() {
1073 <            public void realCompute() {
1074 <                CCF f = new LCCF(null, 8);
1075 <                CCF g = new LCCF(null, 9);
1072 >        ForkJoinTask a = new CheckedRecursiveAction() {
1073 >            protected void realCompute() {
1074 >                CCF f = new LCCF(8);
1075 >                CCF g = new LCCF(9);
1076                  CCF h = null;
1077                  try {
1078                      invokeAll(f, g, h);
# Line 1008 | Line 1086 | public class CountedCompleterTest extend
1086       * invokeAll(t1, t2) throw exception if any task does
1087       */
1088      public void testAbnormalInvokeAll2() {
1089 <       ForkJoinTask a = new CheckedFJTask() {
1090 <            public void realCompute() {
1091 <                CCF f = new LCCF(null, 8);
1092 <                FailingCCF g = new LFCCF(null, 9);
1089 >        ForkJoinTask a = new CheckedRecursiveAction() {
1090 >            protected void realCompute() {
1091 >                CCF f = new LCCF(8);
1092 >                FailingCCF g = new LFCCF(9);
1093                  try {
1094                      invokeAll(f, g);
1095                      shouldThrow();
# Line 1026 | Line 1104 | public class CountedCompleterTest extend
1104       * invokeAll(tasks) with 1 argument throws exception if task does
1105       */
1106      public void testAbnormalInvokeAll1() {
1107 <       ForkJoinTask a = new CheckedFJTask() {
1108 <            public void realCompute() {
1109 <                FailingCCF g = new LFCCF(null, 9);
1107 >        ForkJoinTask a = new CheckedRecursiveAction() {
1108 >            protected void realCompute() {
1109 >                FailingCCF g = new LFCCF(9);
1110                  try {
1111                      invokeAll(g);
1112                      shouldThrow();
# Line 1043 | Line 1121 | public class CountedCompleterTest extend
1121       * invokeAll(tasks) with > 2 argument throws exception if any task does
1122       */
1123      public void testAbnormalInvokeAll3() {
1124 <       ForkJoinTask a = new CheckedFJTask() {
1125 <            public void realCompute() {
1126 <                CCF f = new LCCF(null, 8);
1127 <                FailingCCF g = new LFCCF(null, 9);
1128 <                CCF h = new LCCF(null, 7);
1124 >        ForkJoinTask a = new CheckedRecursiveAction() {
1125 >            protected void realCompute() {
1126 >                CCF f = new LCCF(8);
1127 >                FailingCCF g = new LFCCF(9);
1128 >                CCF h = new LCCF(7);
1129                  try {
1130                      invokeAll(f, g, h);
1131                      shouldThrow();
# Line 1059 | Line 1137 | public class CountedCompleterTest extend
1137      }
1138  
1139      /**
1140 <     * invokeAll(collection)  throws exception if any task does
1140 >     * invokeAll(collection) throws exception if any task does
1141       */
1142      public void testAbnormalInvokeAllCollection() {
1143 <       ForkJoinTask a = new CheckedFJTask() {
1144 <            public void realCompute() {
1145 <                FailingCCF f = new LFCCF(null, 8);
1146 <                CCF g = new LCCF(null, 9);
1147 <                CCF h = new LCCF(null, 7);
1143 >        ForkJoinTask a = new CheckedRecursiveAction() {
1144 >            protected void realCompute() {
1145 >                FailingCCF f = new LFCCF(8);
1146 >                CCF g = new LCCF(9);
1147 >                CCF h = new LCCF(7);
1148                  HashSet set = new HashSet();
1149                  set.add(f);
1150                  set.add(g);
# Line 1086 | Line 1164 | public class CountedCompleterTest extend
1164       * and suppresses execution
1165       */
1166      public void testTryUnfork() {
1167 <       ForkJoinTask a = new CheckedFJTask() {
1168 <            public void realCompute() {
1169 <                CCF g = new LCCF(null, 9);
1167 >        ForkJoinTask a = new CheckedRecursiveAction() {
1168 >            protected void realCompute() {
1169 >                CCF g = new LCCF(9);
1170                  assertSame(g, g.fork());
1171 <                CCF f = new LCCF(null, 8);
1171 >                CCF f = new LCCF(8);
1172                  assertSame(f, f.fork());
1173                  assertTrue(f.tryUnfork());
1174                  helpQuiesce();
# Line 1105 | Line 1183 | public class CountedCompleterTest extend
1183       * there are more tasks than threads
1184       */
1185      public void testGetSurplusQueuedTaskCount() {
1186 <       ForkJoinTask a = new CheckedFJTask() {
1187 <            public void realCompute() {
1188 <                CCF h = new LCCF(null, 7);
1186 >        ForkJoinTask a = new CheckedRecursiveAction() {
1187 >            protected void realCompute() {
1188 >                CCF h = new LCCF(7);
1189                  assertSame(h, h.fork());
1190 <                CCF g = new LCCF(null, 9);
1190 >                CCF g = new LCCF(9);
1191                  assertSame(g, g.fork());
1192 <                CCF f = new LCCF(null, 8);
1192 >                CCF f = new LCCF(8);
1193                  assertSame(f, f.fork());
1194                  assertTrue(getSurplusQueuedTaskCount() > 0);
1195                  helpQuiesce();
# Line 1127 | Line 1205 | public class CountedCompleterTest extend
1205       * peekNextLocalTask returns most recent unexecuted task.
1206       */
1207      public void testPeekNextLocalTask() {
1208 <       ForkJoinTask a = new CheckedFJTask() {
1209 <            public void realCompute() {
1210 <                CCF g = new LCCF(null, 9);
1208 >        ForkJoinTask a = new CheckedRecursiveAction() {
1209 >            protected void realCompute() {
1210 >                CCF g = new LCCF(9);
1211                  assertSame(g, g.fork());
1212 <                CCF f = new LCCF(null, 8);
1212 >                CCF f = new LCCF(8);
1213                  assertSame(f, f.fork());
1214                  assertSame(f, peekNextLocalTask());
1215                  assertNull(f.join());
# Line 1147 | Line 1225 | public class CountedCompleterTest extend
1225       * executing it
1226       */
1227      public void testPollNextLocalTask() {
1228 <       ForkJoinTask a = new CheckedFJTask() {
1229 <            public void realCompute() {
1230 <                CCF g = new LCCF(null, 9);
1228 >        ForkJoinTask a = new CheckedRecursiveAction() {
1229 >            protected void realCompute() {
1230 >                CCF g = new LCCF(9);
1231                  assertSame(g, g.fork());
1232 <                CCF f = new LCCF(null, 8);
1232 >                CCF f = new LCCF(8);
1233                  assertSame(f, f.fork());
1234                  assertSame(f, pollNextLocalTask());
1235                  helpQuiesce();
# Line 1166 | Line 1244 | public class CountedCompleterTest extend
1244       * pollTask returns an unexecuted task without executing it
1245       */
1246      public void testPollTask() {
1247 <       ForkJoinTask a = new CheckedFJTask() {
1248 <            public void realCompute() {
1249 <                CCF g = new LCCF(null, 9);
1247 >        ForkJoinTask a = new CheckedRecursiveAction() {
1248 >            protected void realCompute() {
1249 >                CCF g = new LCCF(9);
1250                  assertSame(g, g.fork());
1251 <                CCF f = new LCCF(null, 8);
1251 >                CCF f = new LCCF(8);
1252                  assertSame(f, f.fork());
1253                  assertSame(f, pollTask());
1254                  helpQuiesce();
# Line 1184 | Line 1262 | public class CountedCompleterTest extend
1262       * peekNextLocalTask returns least recent unexecuted task in async mode
1263       */
1264      public void testPeekNextLocalTaskAsync() {
1265 <       ForkJoinTask a = new CheckedFJTask() {
1266 <            public void realCompute() {
1267 <                CCF g = new LCCF(null, 9);
1265 >        ForkJoinTask a = new CheckedRecursiveAction() {
1266 >            protected void realCompute() {
1267 >                CCF g = new LCCF(9);
1268                  assertSame(g, g.fork());
1269 <                CCF f = new LCCF(null, 8);
1269 >                CCF f = new LCCF(8);
1270                  assertSame(f, f.fork());
1271                  assertSame(g, peekNextLocalTask());
1272                  assertNull(f.join());
# Line 1205 | Line 1283 | public class CountedCompleterTest extend
1283       * executing it, in async mode
1284       */
1285      public void testPollNextLocalTaskAsync() {
1286 <       ForkJoinTask a = new CheckedFJTask() {
1287 <            public void realCompute() {
1288 <                CCF g = new LCCF(null, 9);
1286 >        ForkJoinTask a = new CheckedRecursiveAction() {
1287 >            protected void realCompute() {
1288 >                CCF g = new LCCF(9);
1289                  assertSame(g, g.fork());
1290 <                CCF f = new LCCF(null, 8);
1290 >                CCF f = new LCCF(8);
1291                  assertSame(f, f.fork());
1292                  assertSame(g, pollNextLocalTask());
1293                  helpQuiesce();
# Line 1225 | Line 1303 | public class CountedCompleterTest extend
1303       * async mode
1304       */
1305      public void testPollTaskAsync() {
1306 <       ForkJoinTask a = new CheckedFJTask() {
1307 <            public void realCompute() {
1308 <                CCF g = new LCCF(null, 9);
1306 >        ForkJoinTask a = new CheckedRecursiveAction() {
1307 >            protected void realCompute() {
1308 >                CCF g = new LCCF(9);
1309                  assertSame(g, g.fork());
1310 <                CCF f = new LCCF(null, 8);
1310 >                CCF f = new LCCF(8);
1311                  assertSame(f, f.fork());
1312                  assertSame(g, pollTask());
1313                  helpQuiesce();
# Line 1248 | Line 1326 | public class CountedCompleterTest extend
1326       * completed tasks; getRawResult returns null.
1327       */
1328      public void testInvokeSingleton() {
1329 <       ForkJoinTask a = new CheckedFJTask() {
1330 <            public void realCompute() {
1331 <                CCF f = new LCCF(null, 8);
1329 >        ForkJoinTask a = new CheckedRecursiveAction() {
1330 >            protected void realCompute() {
1331 >                CCF f = new LCCF(8);
1332                  assertNull(f.invoke());
1333                  assertEquals(21, f.number);
1334                  checkCompletedNormally(f);
# Line 1264 | Line 1342 | public class CountedCompleterTest extend
1342       * completed tasks
1343       */
1344      public void testQuietlyInvokeSingleton() {
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                  f.quietlyInvoke();
1349                  assertEquals(21, f.number);
1350                  checkCompletedNormally(f);
# Line 1278 | Line 1356 | public class CountedCompleterTest extend
1356       * join of a forked task returns when task completes
1357       */
1358      public void testForkJoinSingleton() {
1359 <       ForkJoinTask a = new CheckedFJTask() {
1360 <            public void realCompute() {
1361 <                CCF f = new LCCF(null, 8);
1359 >        ForkJoinTask a = new CheckedRecursiveAction() {
1360 >            protected void realCompute() {
1361 >                CCF f = new LCCF(8);
1362                  assertSame(f, f.fork());
1363                  assertNull(f.join());
1364                  assertEquals(21, f.number);
# Line 1293 | Line 1371 | public class CountedCompleterTest extend
1371       * get of a forked task returns when task completes
1372       */
1373      public void testForkGetSingleton() {
1374 <       ForkJoinTask a = new CheckedFJTask() {
1375 <            public void realCompute() throws Exception {
1376 <                CCF f = new LCCF(null, 8);
1374 >        ForkJoinTask a = new CheckedRecursiveAction() {
1375 >            protected void realCompute() throws Exception {
1376 >                CCF f = new LCCF(8);
1377                  assertSame(f, f.fork());
1378                  assertNull(f.get());
1379                  assertEquals(21, f.number);
# Line 1308 | Line 1386 | public class CountedCompleterTest extend
1386       * timed get of a forked task returns when task completes
1387       */
1388      public void testForkTimedGetSingleton() {
1389 <       ForkJoinTask a = new CheckedFJTask() {
1390 <            public void realCompute() throws Exception {
1391 <                CCF f = new LCCF(null, 8);
1389 >        ForkJoinTask a = new CheckedRecursiveAction() {
1390 >            protected void realCompute() throws Exception {
1391 >                CCF f = new LCCF(8);
1392                  assertSame(f, f.fork());
1393                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1394                  assertEquals(21, f.number);
# Line 1323 | Line 1401 | public class CountedCompleterTest extend
1401       * timed get with null time unit throws NPE
1402       */
1403      public void testForkTimedGetNPESingleton() {
1404 <       ForkJoinTask a = new CheckedFJTask() {
1405 <            public void realCompute() throws Exception {
1406 <                CCF f = new LCCF(null, 8);
1404 >        ForkJoinTask a = new CheckedRecursiveAction() {
1405 >            protected void realCompute() throws Exception {
1406 >                CCF f = new LCCF(8);
1407                  assertSame(f, f.fork());
1408                  try {
1409                      f.get(5L, null);
# Line 1339 | Line 1417 | public class CountedCompleterTest extend
1417       * quietlyJoin of a forked task returns when task completes
1418       */
1419      public void testForkQuietlyJoinSingleton() {
1420 <       ForkJoinTask a = new CheckedFJTask() {
1421 <            public void realCompute() {
1422 <                CCF f = new LCCF(null, 8);
1420 >        ForkJoinTask a = new CheckedRecursiveAction() {
1421 >            protected void realCompute() {
1422 >                CCF f = new LCCF(8);
1423                  assertSame(f, f.fork());
1424                  f.quietlyJoin();
1425                  assertEquals(21, f.number);
# Line 1355 | Line 1433 | public class CountedCompleterTest extend
1433       * getQueuedTaskCount returns 0 when quiescent
1434       */
1435      public void testForkHelpQuiesceSingleton() {
1436 <       ForkJoinTask a = new CheckedFJTask() {
1437 <            public void realCompute() {
1438 <                CCF f = new LCCF(null, 8);
1436 >        ForkJoinTask a = new CheckedRecursiveAction() {
1437 >            protected void realCompute() {
1438 >                CCF f = new LCCF(8);
1439                  assertSame(f, f.fork());
1440                  helpQuiesce();
1441                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1449 | public class CountedCompleterTest extend
1449       * invoke task throws exception when task completes abnormally
1450       */
1451      public void testAbnormalInvokeSingleton() {
1452 <       ForkJoinTask a = new CheckedFJTask() {
1453 <            public void realCompute() {
1454 <                FailingCCF f = new LFCCF(null, 8);
1452 >        ForkJoinTask a = new CheckedRecursiveAction() {
1453 >            protected void realCompute() {
1454 >                FailingCCF f = new LFCCF(8);
1455                  try {
1456                      f.invoke();
1457                      shouldThrow();
# Line 1388 | Line 1466 | public class CountedCompleterTest extend
1466       * quietlyInvoke task returns when task completes abnormally
1467       */
1468      public void testAbnormalQuietlyInvokeSingleton() {
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                  f.quietlyInvoke();
1473                  assertTrue(f.getException() instanceof FJException);
1474                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1480 | public class CountedCompleterTest extend
1480       * join of a forked task throws exception when task completes abnormally
1481       */
1482      public void testAbnormalForkJoinSingleton() {
1483 <       ForkJoinTask a = new CheckedFJTask() {
1484 <            public void realCompute() {
1485 <                FailingCCF f = new LFCCF(null, 8);
1483 >        ForkJoinTask a = new CheckedRecursiveAction() {
1484 >            protected void realCompute() {
1485 >                FailingCCF f = new LFCCF(8);
1486                  assertSame(f, f.fork());
1487                  try {
1488                      f.join();
# Line 1420 | Line 1498 | public class CountedCompleterTest extend
1498       * get of a forked task throws exception when task completes abnormally
1499       */
1500      public void testAbnormalForkGetSingleton() {
1501 <       ForkJoinTask a = new CheckedFJTask() {
1502 <            public void realCompute() throws Exception {
1503 <                FailingCCF f = new LFCCF(null, 8);
1501 >        ForkJoinTask a = new CheckedRecursiveAction() {
1502 >            protected void realCompute() throws Exception {
1503 >                FailingCCF f = new LFCCF(8);
1504                  assertSame(f, f.fork());
1505                  try {
1506                      f.get();
# Line 1440 | Line 1518 | public class CountedCompleterTest extend
1518       * timed get of a forked task throws exception when task completes abnormally
1519       */
1520      public void testAbnormalForkTimedGetSingleton() {
1521 <       ForkJoinTask a = new CheckedFJTask() {
1522 <            public void realCompute() throws Exception {
1523 <                FailingCCF f = new LFCCF(null, 8);
1521 >        ForkJoinTask a = new CheckedRecursiveAction() {
1522 >            protected void realCompute() throws Exception {
1523 >                FailingCCF f = new LFCCF(8);
1524                  assertSame(f, f.fork());
1525                  try {
1526                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1538 | public class CountedCompleterTest extend
1538       * quietlyJoin of a forked task returns when task completes abnormally
1539       */
1540      public void testAbnormalForkQuietlyJoinSingleton() {
1541 <       ForkJoinTask a = new CheckedFJTask() {
1542 <            public void realCompute() {
1543 <                FailingCCF f = new LFCCF(null, 8);
1541 >        ForkJoinTask a = new CheckedRecursiveAction() {
1542 >            protected void realCompute() {
1543 >                FailingCCF f = new LFCCF(8);
1544                  assertSame(f, f.fork());
1545                  f.quietlyJoin();
1546                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1553 | public class CountedCompleterTest extend
1553       * invoke task throws exception when task cancelled
1554       */
1555      public void testCancelledInvokeSingleton() {
1556 <       ForkJoinTask a = new CheckedFJTask() {
1557 <            public void realCompute() {
1558 <                CCF f = new LCCF(null, 8);
1556 >        ForkJoinTask a = new CheckedRecursiveAction() {
1557 >            protected void realCompute() {
1558 >                CCF f = new LCCF(8);
1559                  assertTrue(f.cancel(true));
1560                  try {
1561                      f.invoke();
# Line 1493 | Line 1571 | public class CountedCompleterTest extend
1571       * join of a forked task throws exception when task cancelled
1572       */
1573      public void testCancelledForkJoinSingleton() {
1574 <       ForkJoinTask a = new CheckedFJTask() {
1575 <            public void realCompute() {
1576 <                CCF f = new LCCF(null, 8);
1574 >        ForkJoinTask a = new CheckedRecursiveAction() {
1575 >            protected void realCompute() {
1576 >                CCF f = new LCCF(8);
1577                  assertTrue(f.cancel(true));
1578                  assertSame(f, f.fork());
1579                  try {
# Line 1512 | Line 1590 | public class CountedCompleterTest extend
1590       * get of a forked task throws exception when task cancelled
1591       */
1592      public void testCancelledForkGetSingleton() {
1593 <       ForkJoinTask a = new CheckedFJTask() {
1594 <            public void realCompute() throws Exception {
1595 <                CCF f = new LCCF(null, 8);
1593 >        ForkJoinTask a = new CheckedRecursiveAction() {
1594 >            protected void realCompute() throws Exception {
1595 >                CCF f = new LCCF(8);
1596                  assertTrue(f.cancel(true));
1597                  assertSame(f, f.fork());
1598                  try {
# Line 1531 | Line 1609 | public class CountedCompleterTest extend
1609       * timed get of a forked task throws exception when task cancelled
1610       */
1611      public void testCancelledForkTimedGetSingleton() throws Exception {
1612 <       ForkJoinTask a = new CheckedFJTask() {
1613 <            public void realCompute() throws Exception {
1614 <                CCF f = new LCCF(null, 8);
1612 >        ForkJoinTask a = new CheckedRecursiveAction() {
1613 >            protected void realCompute() throws Exception {
1614 >                CCF f = new LCCF(8);
1615                  assertTrue(f.cancel(true));
1616                  assertSame(f, f.fork());
1617                  try {
# Line 1550 | Line 1628 | public class CountedCompleterTest extend
1628       * quietlyJoin of a forked task returns when task cancelled
1629       */
1630      public void testCancelledForkQuietlyJoinSingleton() {
1631 <       ForkJoinTask a = new CheckedFJTask() {
1632 <            public void realCompute() {
1633 <                CCF f = new LCCF(null, 8);
1631 >        ForkJoinTask a = new CheckedRecursiveAction() {
1632 >            protected void realCompute() {
1633 >                CCF f = new LCCF(8);
1634                  assertTrue(f.cancel(true));
1635                  assertSame(f, f.fork());
1636                  f.quietlyJoin();
# Line 1565 | Line 1643 | public class CountedCompleterTest extend
1643       * invoke task throws exception after invoking completeExceptionally
1644       */
1645      public void testCompleteExceptionallySingleton() {
1646 <       ForkJoinTask a = new CheckedFJTask() {
1647 <            public void realCompute() {
1648 <                CCF f = new LCCF(null, 8);
1649 <                f.completeExceptionally(new FJException());
1650 <                try {
1651 <                    f.invoke();
1652 <                    shouldThrow();
1653 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1646 >        ForkJoinTask a = new CheckedRecursiveAction() {
1647 >            protected void realCompute() {
1648 >                CCF n = new LCCF(8);
1649 >                CCF f = new LCCF(n, 8);
1650 >                FJException ex = new FJException();
1651 >                f.completeExceptionally(ex);
1652 >                f.checkCompletedExceptionally(ex);
1653 >                n.checkCompletedExceptionally(ex);
1654              }};
1655          testInvokeOnPool(singletonPool(), a);
1656      }
# Line 1583 | Line 1659 | public class CountedCompleterTest extend
1659       * invokeAll(t1, t2) invokes all task arguments
1660       */
1661      public void testInvokeAll2Singleton() {
1662 <       ForkJoinTask a = new CheckedFJTask() {
1663 <            public void realCompute() {
1664 <                CCF f = new LCCF(null, 8);
1665 <                CCF g = new LCCF(null, 9);
1662 >        ForkJoinTask a = new CheckedRecursiveAction() {
1663 >            protected void realCompute() {
1664 >                CCF f = new LCCF(8);
1665 >                CCF g = new LCCF(9);
1666                  invokeAll(f, g);
1667                  assertEquals(21, f.number);
1668                  assertEquals(34, g.number);
# Line 1600 | Line 1676 | public class CountedCompleterTest extend
1676       * invokeAll(tasks) with 1 argument invokes task
1677       */
1678      public void testInvokeAll1Singleton() {
1679 <       ForkJoinTask a = new CheckedFJTask() {
1680 <            public void realCompute() {
1681 <                CCF f = new LCCF(null, 8);
1679 >        ForkJoinTask a = new CheckedRecursiveAction() {
1680 >            protected void realCompute() {
1681 >                CCF f = new LCCF(8);
1682                  invokeAll(f);
1683                  checkCompletedNormally(f);
1684                  assertEquals(21, f.number);
# Line 1614 | Line 1690 | public class CountedCompleterTest extend
1690       * invokeAll(tasks) with > 2 argument invokes tasks
1691       */
1692      public void testInvokeAll3Singleton() {
1693 <       ForkJoinTask a = new CheckedFJTask() {
1694 <            public void realCompute() {
1695 <                CCF f = new LCCF(null, 8);
1696 <                CCF g = new LCCF(null, 9);
1697 <                CCF h = new LCCF(null, 7);
1693 >        ForkJoinTask a = new CheckedRecursiveAction() {
1694 >            protected void realCompute() {
1695 >                CCF f = new LCCF(8);
1696 >                CCF g = new LCCF(9);
1697 >                CCF h = new LCCF(7);
1698                  invokeAll(f, g, h);
1699                  assertEquals(21, f.number);
1700                  assertEquals(34, g.number);
# Line 1634 | Line 1710 | public class CountedCompleterTest extend
1710       * invokeAll(collection) invokes all tasks in the collection
1711       */
1712      public void testInvokeAllCollectionSingleton() {
1713 <       ForkJoinTask a = new CheckedFJTask() {
1714 <            public void realCompute() {
1715 <                CCF f = new LCCF(null, 8);
1716 <                CCF g = new LCCF(null, 9);
1717 <                CCF h = new LCCF(null, 7);
1713 >        ForkJoinTask a = new CheckedRecursiveAction() {
1714 >            protected void realCompute() {
1715 >                CCF f = new LCCF(8);
1716 >                CCF g = new LCCF(9);
1717 >                CCF h = new LCCF(7);
1718                  HashSet set = new HashSet();
1719                  set.add(f);
1720                  set.add(g);
# Line 1658 | Line 1734 | public class CountedCompleterTest extend
1734       * invokeAll(tasks) with any null task throws NPE
1735       */
1736      public void testInvokeAllNPESingleton() {
1737 <       ForkJoinTask a = new CheckedFJTask() {
1738 <            public void realCompute() {
1739 <                CCF f = new LCCF(null, 8);
1740 <                CCF g = new LCCF(null, 9);
1737 >        ForkJoinTask a = new CheckedRecursiveAction() {
1738 >            protected void realCompute() {
1739 >                CCF f = new LCCF(8);
1740 >                CCF g = new LCCF(9);
1741                  CCF h = null;
1742                  try {
1743                      invokeAll(f, g, h);
# Line 1675 | Line 1751 | public class CountedCompleterTest extend
1751       * invokeAll(t1, t2) throw exception if any task does
1752       */
1753      public void testAbnormalInvokeAll2Singleton() {
1754 <       ForkJoinTask a = new CheckedFJTask() {
1755 <            public void realCompute() {
1756 <                CCF f = new LCCF(null, 8);
1757 <                FailingCCF g = new LFCCF(null, 9);
1754 >        ForkJoinTask a = new CheckedRecursiveAction() {
1755 >            protected void realCompute() {
1756 >                CCF f = new LCCF(8);
1757 >                FailingCCF g = new LFCCF(9);
1758                  try {
1759                      invokeAll(f, g);
1760                      shouldThrow();
# Line 1693 | Line 1769 | public class CountedCompleterTest extend
1769       * invokeAll(tasks) with 1 argument throws exception if task does
1770       */
1771      public void testAbnormalInvokeAll1Singleton() {
1772 <       ForkJoinTask a = new CheckedFJTask() {
1773 <            public void realCompute() {
1774 <                FailingCCF g = new LFCCF(null, 9);
1772 >        ForkJoinTask a = new CheckedRecursiveAction() {
1773 >            protected void realCompute() {
1774 >                FailingCCF g = new LFCCF(9);
1775                  try {
1776                      invokeAll(g);
1777                      shouldThrow();
# Line 1710 | Line 1786 | public class CountedCompleterTest extend
1786       * invokeAll(tasks) with > 2 argument throws exception if any task does
1787       */
1788      public void testAbnormalInvokeAll3Singleton() {
1789 <       ForkJoinTask a = new CheckedFJTask() {
1790 <            public void realCompute() {
1791 <                CCF f = new LCCF(null, 8);
1792 <                FailingCCF g = new LFCCF(null, 9);
1793 <                CCF h = new LCCF(null, 7);
1789 >        ForkJoinTask a = new CheckedRecursiveAction() {
1790 >            protected void realCompute() {
1791 >                CCF f = new LCCF(8);
1792 >                FailingCCF g = new LFCCF(9);
1793 >                CCF h = new LCCF(7);
1794                  try {
1795                      invokeAll(f, g, h);
1796                      shouldThrow();
# Line 1726 | Line 1802 | public class CountedCompleterTest extend
1802      }
1803  
1804      /**
1805 <     * invokeAll(collection)  throws exception if any task does
1805 >     * invokeAll(collection) throws exception if any task does
1806       */
1807      public void testAbnormalInvokeAllCollectionSingleton() {
1808 <       ForkJoinTask a = new CheckedFJTask() {
1809 <            public void realCompute() {
1810 <                FailingCCF f = new LFCCF(null, 8);
1811 <                CCF g = new LCCF(null, 9);
1812 <                CCF h = new LCCF(null, 7);
1808 >        ForkJoinTask a = new CheckedRecursiveAction() {
1809 >            protected void realCompute() {
1810 >                FailingCCF f = new LFCCF(8);
1811 >                CCF g = new LCCF(9);
1812 >                CCF h = new LCCF(7);
1813                  HashSet set = new HashSet();
1814                  set.add(f);
1815                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines