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.22 by jsr166, Sun Oct 18 18:54:49 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 62 | Line 49 | public class CountedCompleterTest extend
49      }
50  
51      private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) {
52 <        try {
52 >        try (PoolCleaner cleaner = cleaner(pool)) {
53              assertFalse(a.isDone());
54              assertFalse(a.isCompletedNormally());
55              assertFalse(a.isCompletedAbnormally());
# Line 78 | Line 65 | public class CountedCompleterTest extend
65              assertFalse(a.isCancelled());
66              assertNull(a.getException());
67              assertNull(a.getRawResult());
81        } finally {
82            joinPool(pool);
68          }
69      }
70  
# Line 98 | Line 83 | public class CountedCompleterTest extend
83          } catch (Throwable fail) { threadUnexpectedException(fail); }
84      }
85  
86 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
102 <        checkCompletedNormally(a, null);
103 <    }
104 <
105 <    <T> void checkCompletedNormally(CountedCompleter<T> a, T expected) {
86 >    void checkCompletedNormally(CountedCompleter<?> a) {
87          assertTrue(a.isDone());
88          assertFalse(a.isCancelled());
89          assertTrue(a.isCompletedNormally());
90          assertFalse(a.isCompletedAbnormally());
91          assertNull(a.getException());
92 <        assertSame(expected, a.getRawResult());
92 >        assertNull(a.getRawResult());
93  
94          {
95              Thread.currentThread().interrupt();
96 <            long t0 = System.nanoTime();
97 <            assertSame(expected, a.join());
98 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
96 >            long startTime = System.nanoTime();
97 >            assertNull(a.join());
98 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
99              Thread.interrupted();
100          }
101  
102          {
103              Thread.currentThread().interrupt();
104 <            long t0 = System.nanoTime();
104 >            long startTime = System.nanoTime();
105              a.quietlyJoin();        // should be no-op
106 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
106 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
107              Thread.interrupted();
108          }
109  
110          assertFalse(a.cancel(false));
111          assertFalse(a.cancel(true));
112          try {
113 <            assertSame(expected, a.get());
113 >            assertNull(a.get());
114          } catch (Throwable fail) { threadUnexpectedException(fail); }
115          try {
116 <            assertSame(expected, a.get(5L, SECONDS));
116 >            assertNull(a.get(5L, SECONDS));
117          } catch (Throwable fail) { threadUnexpectedException(fail); }
118      }
119  
# Line 155 | Line 136 | public class CountedCompleterTest extend
136          Thread.interrupted();
137  
138          {
139 <            long t0 = System.nanoTime();
139 >            long startTime = System.nanoTime();
140              a.quietlyJoin();        // should be no-op
141 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
141 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
142          }
143  
144          try {
# Line 193 | Line 174 | public class CountedCompleterTest extend
174          Thread.interrupted();
175  
176          {
177 <            long t0 = System.nanoTime();
177 >            long startTime = System.nanoTime();
178              a.quietlyJoin();        // should be no-op
179 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
179 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
180          }
181  
182          try {
# Line 211 | Line 192 | public class CountedCompleterTest extend
192          } catch (ExecutionException success) {
193              assertSame(t.getClass(), success.getCause().getClass());
194          } catch (Throwable fail) { threadUnexpectedException(fail); }
195 +
196 +        try {
197 +            a.invoke();
198 +            shouldThrow();
199 +        } catch (Throwable success) {
200 +            assertSame(t, success);
201 +        }
202      }
203  
204      public static final class FJException extends RuntimeException {
205          FJException() { super(); }
206      }
207  
208 <    static final class NoopCountedCompleter extends CountedCompleter {
209 <        boolean post; // set true if onCompletion called
210 <        NoopCountedCompleter() { super(); }
211 <        NoopCountedCompleter(CountedCompleter p) { super(p); }
212 <        public void compute() {}
213 <        public final void onCompletion(CountedCompleter caller) {
214 <            post = true;
208 >    abstract class CheckedCC extends CountedCompleter<Object> {
209 >        final AtomicInteger computeN = new AtomicInteger(0);
210 >        final AtomicInteger onCompletionN = new AtomicInteger(0);
211 >        final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
212 >        final AtomicInteger setRawResultN = new AtomicInteger(0);
213 >        final AtomicReference<Object> rawResult = new AtomicReference<Object>(null);
214 >        int computeN() { return computeN.get(); }
215 >        int onCompletionN() { return onCompletionN.get(); }
216 >        int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }
217 >        int setRawResultN() { return setRawResultN.get(); }
218 >
219 >        CheckedCC() { super(); }
220 >        CheckedCC(CountedCompleter p) { super(p); }
221 >        CheckedCC(CountedCompleter p, int n) { super(p, n); }
222 >        abstract void realCompute();
223 >        public final void compute() {
224 >            computeN.incrementAndGet();
225 >            realCompute();
226 >        }
227 >        public void onCompletion(CountedCompleter caller) {
228 >            onCompletionN.incrementAndGet();
229 >            super.onCompletion(caller);
230 >        }
231 >        public boolean onExceptionalCompletion(Throwable ex,
232 >                                               CountedCompleter caller) {
233 >            onExceptionalCompletionN.incrementAndGet();
234 >            assertNotNull(ex);
235 >            assertTrue(isCompletedAbnormally());
236 >            assertTrue(super.onExceptionalCompletion(ex, caller));
237 >            return true;
238 >        }
239 >        protected void setRawResult(Object t) {
240 >            setRawResultN.incrementAndGet();
241 >            rawResult.set(t);
242 >            super.setRawResult(t);
243 >        }
244 >        void checkIncomplete() {
245 >            assertEquals(0, computeN());
246 >            assertEquals(0, onCompletionN());
247 >            assertEquals(0, onExceptionalCompletionN());
248 >            assertEquals(0, setRawResultN());
249 >            checkNotDone(this);
250 >        }
251 >        void checkCompletes(Object rawResult) {
252 >            checkIncomplete();
253 >            int pendingCount = getPendingCount();
254 >            complete(rawResult);
255 >            assertEquals(pendingCount, getPendingCount());
256 >            assertEquals(0, computeN());
257 >            assertEquals(1, onCompletionN());
258 >            assertEquals(0, onExceptionalCompletionN());
259 >            assertEquals(1, setRawResultN());
260 >            assertSame(rawResult, this.rawResult.get());
261 >            checkCompletedNormally(this);
262 >        }
263 >        void checkCompletesExceptionally(Throwable ex) {
264 >            checkIncomplete();
265 >            completeExceptionally(ex);
266 >            checkCompletedExceptionally(ex);
267          }
268 +        void checkCompletedExceptionally(Throwable ex) {
269 +            assertEquals(0, computeN());
270 +            assertEquals(0, onCompletionN());
271 +            assertEquals(1, onExceptionalCompletionN());
272 +            assertEquals(0, setRawResultN());
273 +            assertNull(this.rawResult.get());
274 +            checkCompletedAbnormally(this, ex);
275 +        }
276 +    }
277 +
278 +    final class NoopCC extends CheckedCC {
279 +        NoopCC() { super(); }
280 +        NoopCC(CountedCompleter p) { super(p); }
281 +        NoopCC(CountedCompleter p, int initialPendingCount) {
282 +            super(p, initialPendingCount);
283 +        }
284 +        protected void realCompute() {}
285      }
286  
287      /**
288       * A newly constructed CountedCompleter is not completed;
289 <     * complete() causes completion.
289 >     * complete() causes completion. pendingCount is ignored.
290       */
291      public void testComplete() {
292 <        NoopCountedCompleter a = new NoopCountedCompleter();
293 <        assertFalse(a.isDone());
294 <        assertFalse(a.isCompletedNormally());
295 <        assertFalse(a.isCompletedAbnormally());
296 <        assertFalse(a.isCancelled());
297 <        assertNull(a.getException());
298 <        assertNull(a.getRawResult());
299 <        assertFalse(a.post);
300 <        a.complete(null);
301 <        assertTrue(a.post);
302 <        assertTrue(a.isDone());
246 <        assertTrue(a.isCompletedNormally());
247 <        assertFalse(a.isCompletedAbnormally());
248 <        assertFalse(a.isCancelled());
249 <        assertNull(a.getException());
250 <        assertNull(a.getRawResult());
292 >        for (Object x : new Object[] { Boolean.TRUE, null }) {
293 >            for (int pendingCount : new int[] { 0, 42 }) {
294 >                testComplete(new NoopCC(), x, pendingCount);
295 >                testComplete(new NoopCC(new NoopCC()), x, pendingCount);
296 >            }
297 >        }
298 >    }
299 >    void testComplete(NoopCC cc, Object x, int pendingCount) {
300 >        cc.setPendingCount(pendingCount);
301 >        cc.checkCompletes(x);
302 >        assertEquals(pendingCount, cc.getPendingCount());
303      }
304  
305      /**
306       * completeExceptionally completes exceptionally
307       */
308      public void testCompleteExceptionally() {
309 <        NoopCountedCompleter a = new NoopCountedCompleter();
310 <        assertFalse(a.isDone());
311 <        assertFalse(a.isCompletedNormally());
312 <        assertFalse(a.isCompletedAbnormally());
313 <        assertFalse(a.isCancelled());
314 <        assertNull(a.getException());
315 <        assertNull(a.getRawResult());
316 <        assertFalse(a.post);
317 <        a.completeExceptionally(new FJException());
318 <        assertFalse(a.post);
319 <        assertTrue(a.isDone());
320 <        assertFalse(a.isCompletedNormally());
321 <        assertTrue(a.isCompletedAbnormally());
322 <        assertFalse(a.isCancelled());
323 <        assertTrue(a.getException() instanceof FJException);
324 <        assertNull(a.getRawResult());
309 >        new NoopCC()
310 >            .checkCompletesExceptionally(new FJException());
311 >        new NoopCC(new NoopCC())
312 >            .checkCompletesExceptionally(new FJException());
313 >    }
314 >
315 >    /**
316 >     * completeExceptionally(null) surprisingly has the same effect as
317 >     * completeExceptionally(new RuntimeException())
318 >     */
319 >    public void testCompleteExceptionally_null() {
320 >        NoopCC a = new NoopCC();
321 >        a.completeExceptionally(null);
322 >        try {
323 >            a.invoke();
324 >            shouldThrow();
325 >        } catch (RuntimeException success) {
326 >            assertSame(success.getClass(), RuntimeException.class);
327 >            assertNull(success.getCause());
328 >            a.checkCompletedExceptionally(success);
329 >        }
330      }
331  
332      /**
333       * setPendingCount sets the reported pending count
334       */
335      public void testSetPendingCount() {
336 <        NoopCountedCompleter a = new NoopCountedCompleter();
336 >        NoopCC a = new NoopCC();
337          assertEquals(0, a.getPendingCount());
338          a.setPendingCount(1);
339          assertEquals(1, a.getPendingCount());
# Line 288 | Line 345 | public class CountedCompleterTest extend
345       * addToPendingCount adds to the reported pending count
346       */
347      public void testAddToPendingCount() {
348 <        NoopCountedCompleter a = new NoopCountedCompleter();
348 >        NoopCC a = new NoopCC();
349          assertEquals(0, a.getPendingCount());
350          a.addToPendingCount(1);
351          assertEquals(1, a.getPendingCount());
# Line 300 | Line 357 | public class CountedCompleterTest extend
357       * decrementPendingCountUnlessZero decrements reported pending
358       * count unless zero
359       */
360 <    public void testDecrementPendingCount() {
361 <        NoopCountedCompleter a = new NoopCountedCompleter();
362 <        assertEquals(0, a.getPendingCount());
363 <        a.addToPendingCount(1);
360 >    public void testDecrementPendingCountUnlessZero() {
361 >        NoopCC a = new NoopCC(null, 2);
362 >        assertEquals(2, a.getPendingCount());
363 >        assertEquals(2, a.decrementPendingCountUnlessZero());
364          assertEquals(1, a.getPendingCount());
365 <        a.decrementPendingCountUnlessZero();
365 >        assertEquals(1, a.decrementPendingCountUnlessZero());
366 >        assertEquals(0, a.getPendingCount());
367 >        assertEquals(0, a.decrementPendingCountUnlessZero());
368          assertEquals(0, a.getPendingCount());
369 <        a.decrementPendingCountUnlessZero();
369 >    }
370 >
371 >    /**
372 >     * compareAndSetPendingCount compares and sets the reported
373 >     * pending count
374 >     */
375 >    public void testCompareAndSetPendingCount() {
376 >        NoopCC a = new NoopCC();
377          assertEquals(0, a.getPendingCount());
378 +        assertTrue(a.compareAndSetPendingCount(0, 1));
379 +        assertEquals(1, a.getPendingCount());
380 +        assertTrue(a.compareAndSetPendingCount(1, 2));
381 +        assertEquals(2, a.getPendingCount());
382 +        assertFalse(a.compareAndSetPendingCount(1, 3));
383 +        assertEquals(2, a.getPendingCount());
384      }
385  
386      /**
387       * getCompleter returns parent or null if at root
388       */
389      public void testGetCompleter() {
390 <        NoopCountedCompleter a = new NoopCountedCompleter();
390 >        NoopCC a = new NoopCC();
391          assertNull(a.getCompleter());
392 <        CountedCompleter b = new NoopCountedCompleter(a);
393 <        assertEquals(a, b.getCompleter());
392 >        CountedCompleter b = new NoopCC(a);
393 >        assertSame(a, b.getCompleter());
394 >        CountedCompleter c = new NoopCC(b);
395 >        assertSame(b, c.getCompleter());
396      }
397  
398      /**
399       * getRoot returns self if no parent, else parent's root
400       */
401      public void testGetRoot() {
402 <        NoopCountedCompleter a = new NoopCountedCompleter();
403 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
404 <        assertEquals(a, a.getRoot());
405 <        assertEquals(a, b.getRoot());
402 >        NoopCC a = new NoopCC();
403 >        NoopCC b = new NoopCC(a);
404 >        NoopCC c = new NoopCC(b);
405 >        assertSame(a, a.getRoot());
406 >        assertSame(a, b.getRoot());
407 >        assertSame(a, c.getRoot());
408      }
409  
410      /**
411 <     * tryComplete causes completion if pending count is zero
411 >     * tryComplete decrements pending count unless zero, in which case
412 >     * causes completion
413       */
414 <    public void testTryComplete1() {
415 <        NoopCountedCompleter a = new NoopCountedCompleter();
414 >    public void testTryComplete() {
415 >        NoopCC a = new NoopCC();
416          assertEquals(0, a.getPendingCount());
417 +        int n = 3;
418 +        a.setPendingCount(n);
419 +        for (; n > 0; n--) {
420 +            assertEquals(n, a.getPendingCount());
421 +            a.tryComplete();
422 +            a.checkIncomplete();
423 +            assertEquals(n - 1, a.getPendingCount());
424 +        }
425          a.tryComplete();
426 <        assertTrue(a.post);
427 <        assertTrue(a.isDone());
426 >        assertEquals(0, a.computeN());
427 >        assertEquals(1, a.onCompletionN());
428 >        assertEquals(0, a.onExceptionalCompletionN());
429 >        assertEquals(0, a.setRawResultN());
430 >        checkCompletedNormally(a);
431      }
432  
433      /**
434 <     * propagateCompletion causes completion without invoking
435 <     * onCompletion if pending count is zero
434 >     * propagateCompletion decrements pending count unless zero, in
435 >     * which case causes completion, without invoking onCompletion
436       */
437      public void testPropagateCompletion() {
438 <        NoopCountedCompleter a = new NoopCountedCompleter();
438 >        NoopCC a = new NoopCC();
439          assertEquals(0, a.getPendingCount());
440 +        int n = 3;
441 +        a.setPendingCount(n);
442 +        for (; n > 0; n--) {
443 +            assertEquals(n, a.getPendingCount());
444 +            a.propagateCompletion();
445 +            a.checkIncomplete();
446 +            assertEquals(n - 1, a.getPendingCount());
447 +        }
448          a.propagateCompletion();
449 <        assertFalse(a.post);
450 <        assertTrue(a.isDone());
451 <    }
452 <
453 <    /**
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());
449 >        assertEquals(0, a.computeN());
450 >        assertEquals(0, a.onCompletionN());
451 >        assertEquals(0, a.onExceptionalCompletionN());
452 >        assertEquals(0, a.setRawResultN());
453 >        checkCompletedNormally(a);
454      }
455  
456      /**
457       * firstComplete returns this if pending count is zero else null
458       */
459      public void testFirstComplete() {
460 <        NoopCountedCompleter a = new NoopCountedCompleter();
460 >        NoopCC a = new NoopCC();
461          a.setPendingCount(1);
462          assertNull(a.firstComplete());
463 <        assertEquals(a, a.firstComplete());
463 >        a.checkIncomplete();
464 >        assertSame(a, a.firstComplete());
465 >        a.checkIncomplete();
466      }
467  
468      /**
# Line 385 | Line 470 | public class CountedCompleterTest extend
470       * zero else null
471       */
472      public void testNextComplete() {
473 <        NoopCountedCompleter a = new NoopCountedCompleter();
474 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
473 >        NoopCC a = new NoopCC();
474 >        NoopCC b = new NoopCC(a);
475          a.setPendingCount(1);
476          b.setPendingCount(1);
477          assertNull(b.firstComplete());
478 <        CountedCompleter c = b.firstComplete();
479 <        assertEquals(b, c);
480 <        CountedCompleter d = c.nextComplete();
481 <        assertNull(d);
482 <        CountedCompleter e = c.nextComplete();
483 <        assertEquals(a, e);
478 >        assertSame(b, b.firstComplete());
479 >        assertNull(b.nextComplete());
480 >        a.checkIncomplete();
481 >        b.checkIncomplete();
482 >        assertSame(a, b.nextComplete());
483 >        assertSame(a, b.nextComplete());
484 >        a.checkIncomplete();
485 >        b.checkIncomplete();
486 >        assertNull(a.nextComplete());
487 >        b.checkIncomplete();
488 >        checkCompletedNormally(a);
489      }
490  
491      /**
492       * quietlyCompleteRoot completes root task
493       */
494      public void testQuietlyCompleteRoot() {
495 <        NoopCountedCompleter a = new NoopCountedCompleter();
496 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
495 >        NoopCC a = new NoopCC();
496 >        NoopCC b = new NoopCC(a);
497 >        NoopCC c = new NoopCC(b);
498          a.setPendingCount(1);
499          b.setPendingCount(1);
500 <        b.quietlyCompleteRoot();
500 >        c.setPendingCount(1);
501 >        c.quietlyCompleteRoot();
502          assertTrue(a.isDone());
503          assertFalse(b.isDone());
504 +        assertFalse(c.isDone());
505      }
506  
507      // Invocation tests use some interdependent task classes
508      // to better test propagation etc
509  
510 <
511 <    // Version of Fibonacci with different classes for left vs right forks
512 <    abstract static class CCF extends CountedCompleter {
510 >    /**
511 >     * Version of Fibonacci with different classes for left vs right forks
512 >     */
513 >    abstract class CCF extends CheckedCC {
514          int number;
515          int rnumber;
516  
# Line 425 | Line 519 | public class CountedCompleterTest extend
519              this.number = n;
520          }
521  
522 <        public final void compute() {
429 <            CountedCompleter p;
522 >        protected final void realCompute() {
523              CCF f = this;
524              int n = number;
525              while (n >= 2) {
526                  new RCCF(f, n - 2).fork();
527                  f = new LCCF(f, --n);
528              }
529 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
529 >            f.complete(null);
530          }
531      }
532  
533 <    static final class LCCF extends CCF {
533 >    final class LCCF extends CCF {
534 >        public LCCF(int n) { this(null, n); }
535          public LCCF(CountedCompleter parent, int n) {
536              super(parent, n);
537          }
538          public final void onCompletion(CountedCompleter caller) {
539 +            super.onCompletion(caller);
540              CCF p = (CCF)getCompleter();
541              int n = number + rnumber;
542              if (p != null)
# Line 455 | Line 545 | public class CountedCompleterTest extend
545                  number = n;
546          }
547      }
548 <    static final class RCCF extends CCF {
548 >    final class RCCF extends CCF {
549          public RCCF(CountedCompleter parent, int n) {
550              super(parent, n);
551          }
552          public final void onCompletion(CountedCompleter caller) {
553 +            super.onCompletion(caller);
554              CCF p = (CCF)getCompleter();
555              int n = number + rnumber;
556              if (p != null)
# Line 470 | Line 561 | public class CountedCompleterTest extend
561      }
562  
563      // Version of CCF with forced failure in left completions
564 <    abstract static class FailingCCF extends CountedCompleter {
564 >    abstract class FailingCCF extends CheckedCC {
565          int number;
566          int rnumber;
567  
# Line 479 | Line 570 | public class CountedCompleterTest extend
570              this.number = n;
571          }
572  
573 <        public final void compute() {
483 <            CountedCompleter p;
573 >        protected final void realCompute() {
574              FailingCCF f = this;
575              int n = number;
576              while (n >= 2) {
577                  new RFCCF(f, n - 2).fork();
578                  f = new LFCCF(f, --n);
579              }
580 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
580 >            f.complete(null);
581          }
582      }
583  
584 <    static final class LFCCF extends FailingCCF {
584 >    final class LFCCF extends FailingCCF {
585 >        public LFCCF(int n) { this(null, n); }
586          public LFCCF(CountedCompleter parent, int n) {
587              super(parent, n);
588          }
589          public final void onCompletion(CountedCompleter caller) {
590 +            super.onCompletion(caller);
591              FailingCCF p = (FailingCCF)getCompleter();
592              int n = number + rnumber;
593              if (p != null)
# Line 509 | Line 596 | public class CountedCompleterTest extend
596                  number = n;
597          }
598      }
599 <    static final class RFCCF extends FailingCCF {
599 >    final class RFCCF extends FailingCCF {
600          public RFCCF(CountedCompleter parent, int n) {
601              super(parent, n);
602          }
603          public final void onCompletion(CountedCompleter caller) {
604 +            super.onCompletion(caller);
605              completeExceptionally(new FJException());
606          }
607      }
# Line 524 | Line 612 | public class CountedCompleterTest extend
612       * completed tasks; getRawResult returns null.
613       */
614      public void testInvoke() {
615 <       ForkJoinTask a = new CheckedFJTask() {
616 <            public void realCompute() {
617 <                CCF f = new LCCF(null, 8);
615 >        ForkJoinTask a = new CheckedRecursiveAction() {
616 >            protected void realCompute() {
617 >                CCF f = new LCCF(8);
618                  assertNull(f.invoke());
619                  assertEquals(21, f.number);
620                  checkCompletedNormally(f);
# Line 540 | Line 628 | public class CountedCompleterTest extend
628       * completed tasks
629       */
630      public void testQuietlyInvoke() {
631 <       ForkJoinTask a = new CheckedFJTask() {
632 <            public void realCompute() {
633 <                CCF f = new LCCF(null, 8);
631 >        ForkJoinTask a = new CheckedRecursiveAction() {
632 >            protected void realCompute() {
633 >                CCF f = new LCCF(8);
634                  f.quietlyInvoke();
635                  assertEquals(21, f.number);
636                  checkCompletedNormally(f);
# Line 554 | Line 642 | public class CountedCompleterTest extend
642       * join of a forked task returns when task completes
643       */
644      public void testForkJoin() {
645 <       ForkJoinTask a = new CheckedFJTask() {
646 <            public void realCompute() {
647 <                CCF f = new LCCF(null, 8);
645 >        ForkJoinTask a = new CheckedRecursiveAction() {
646 >            protected void realCompute() {
647 >                CCF f = new LCCF(8);
648                  assertSame(f, f.fork());
649                  assertNull(f.join());
650                  assertEquals(21, f.number);
# Line 569 | Line 657 | public class CountedCompleterTest extend
657       * get of a forked task returns when task completes
658       */
659      public void testForkGet() {
660 <       ForkJoinTask a = new CheckedFJTask() {
661 <            public void realCompute() throws Exception {
662 <                CCF f = new LCCF(null, 8);
660 >        ForkJoinTask a = new CheckedRecursiveAction() {
661 >            protected void realCompute() throws Exception {
662 >                CCF f = new LCCF(8);
663                  assertSame(f, f.fork());
664                  assertNull(f.get());
665                  assertEquals(21, f.number);
# Line 584 | Line 672 | public class CountedCompleterTest extend
672       * timed get of a forked task returns when task completes
673       */
674      public void testForkTimedGet() {
675 <       ForkJoinTask a = new CheckedFJTask() {
676 <            public void realCompute() throws Exception {
677 <                CCF f = new LCCF(null, 8);
675 >        ForkJoinTask a = new CheckedRecursiveAction() {
676 >            protected void realCompute() throws Exception {
677 >                CCF f = new LCCF(8);
678                  assertSame(f, f.fork());
679                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
680                  assertEquals(21, f.number);
# Line 599 | Line 687 | public class CountedCompleterTest extend
687       * timed get with null time unit throws NPE
688       */
689      public void testForkTimedGetNPE() {
690 <       ForkJoinTask a = new CheckedFJTask() {
691 <            public void realCompute() throws Exception {
692 <                CCF f = new LCCF(null, 8);
690 >        ForkJoinTask a = new CheckedRecursiveAction() {
691 >            protected void realCompute() throws Exception {
692 >                CCF f = new LCCF(8);
693                  assertSame(f, f.fork());
694                  try {
695                      f.get(5L, null);
# Line 615 | Line 703 | public class CountedCompleterTest extend
703       * quietlyJoin of a forked task returns when task completes
704       */
705      public void testForkQuietlyJoin() {
706 <       ForkJoinTask a = new CheckedFJTask() {
707 <            public void realCompute() {
708 <                CCF f = new LCCF(null, 8);
706 >        ForkJoinTask a = new CheckedRecursiveAction() {
707 >            protected void realCompute() {
708 >                CCF f = new LCCF(8);
709                  assertSame(f, f.fork());
710                  f.quietlyJoin();
711                  assertEquals(21, f.number);
# Line 631 | Line 719 | public class CountedCompleterTest extend
719       * getQueuedTaskCount returns 0 when quiescent
720       */
721      public void testForkHelpQuiesce() {
722 <       ForkJoinTask a = new CheckedFJTask() {
723 <            public void realCompute() {
724 <                CCF f = new LCCF(null, 8);
722 >        ForkJoinTask a = new CheckedRecursiveAction() {
723 >            protected void realCompute() {
724 >                CCF f = new LCCF(8);
725                  assertSame(f, f.fork());
726                  helpQuiesce();
727                  assertEquals(21, f.number);
# Line 647 | Line 735 | public class CountedCompleterTest extend
735       * invoke task throws exception when task completes abnormally
736       */
737      public void testAbnormalInvoke() {
738 <       ForkJoinTask a = new CheckedFJTask() {
739 <            public void realCompute() {
740 <                FailingCCF f = new LFCCF(null, 8);
738 >        ForkJoinTask a = new CheckedRecursiveAction() {
739 >            protected void realCompute() {
740 >                FailingCCF f = new LFCCF(8);
741                  try {
742                      f.invoke();
743                      shouldThrow();
# Line 664 | Line 752 | public class CountedCompleterTest extend
752       * quietlyInvoke task returns when task completes abnormally
753       */
754      public void testAbnormalQuietlyInvoke() {
755 <       ForkJoinTask a = new CheckedFJTask() {
756 <            public void realCompute() {
757 <                FailingCCF f = new LFCCF(null, 8);
755 >        ForkJoinTask a = new CheckedRecursiveAction() {
756 >            protected void realCompute() {
757 >                FailingCCF f = new LFCCF(8);
758                  f.quietlyInvoke();
759                  assertTrue(f.getException() instanceof FJException);
760                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 766 | public class CountedCompleterTest extend
766       * join of a forked task throws exception when task completes abnormally
767       */
768      public void testAbnormalForkJoin() {
769 <       ForkJoinTask a = new CheckedFJTask() {
770 <            public void realCompute() {
771 <                FailingCCF f = new LFCCF(null, 8);
769 >        ForkJoinTask a = new CheckedRecursiveAction() {
770 >            protected void realCompute() {
771 >                FailingCCF f = new LFCCF(8);
772                  assertSame(f, f.fork());
773                  try {
774                      f.join();
# Line 696 | Line 784 | public class CountedCompleterTest extend
784       * get of a forked task throws exception when task completes abnormally
785       */
786      public void testAbnormalForkGet() {
787 <       ForkJoinTask a = new CheckedFJTask() {
788 <            public void realCompute() throws Exception {
789 <                FailingCCF f = new LFCCF(null, 8);
787 >        ForkJoinTask a = new CheckedRecursiveAction() {
788 >            protected void realCompute() throws Exception {
789 >                FailingCCF f = new LFCCF(8);
790                  assertSame(f, f.fork());
791                  try {
792                      f.get();
# Line 716 | Line 804 | public class CountedCompleterTest extend
804       * timed get of a forked task throws exception when task completes abnormally
805       */
806      public void testAbnormalForkTimedGet() {
807 <       ForkJoinTask a = new CheckedFJTask() {
808 <            public void realCompute() throws Exception {
809 <                FailingCCF f = new LFCCF(null, 8);
807 >        ForkJoinTask a = new CheckedRecursiveAction() {
808 >            protected void realCompute() throws Exception {
809 >                FailingCCF f = new LFCCF(8);
810                  assertSame(f, f.fork());
811                  try {
812                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 824 | public class CountedCompleterTest extend
824       * quietlyJoin of a forked task returns when task completes abnormally
825       */
826      public void testAbnormalForkQuietlyJoin() {
827 <       ForkJoinTask a = new CheckedFJTask() {
828 <            public void realCompute() {
829 <                FailingCCF f = new LFCCF(null, 8);
827 >        ForkJoinTask a = new CheckedRecursiveAction() {
828 >            protected void realCompute() {
829 >                FailingCCF f = new LFCCF(8);
830                  assertSame(f, f.fork());
831                  f.quietlyJoin();
832                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 839 | public class CountedCompleterTest extend
839       * invoke task throws exception when task cancelled
840       */
841      public void testCancelledInvoke() {
842 <       ForkJoinTask a = new CheckedFJTask() {
843 <            public void realCompute() {
844 <                CCF f = new LCCF(null, 8);
842 >        ForkJoinTask a = new CheckedRecursiveAction() {
843 >            protected void realCompute() {
844 >                CCF f = new LCCF(8);
845                  assertTrue(f.cancel(true));
846                  try {
847                      f.invoke();
# Line 769 | Line 857 | public class CountedCompleterTest extend
857       * join of a forked task throws exception when task cancelled
858       */
859      public void testCancelledForkJoin() {
860 <       ForkJoinTask a = new CheckedFJTask() {
861 <            public void realCompute() {
862 <                CCF f = new LCCF(null, 8);
860 >        ForkJoinTask a = new CheckedRecursiveAction() {
861 >            protected void realCompute() {
862 >                CCF f = new LCCF(8);
863                  assertTrue(f.cancel(true));
864                  assertSame(f, f.fork());
865                  try {
# Line 788 | Line 876 | public class CountedCompleterTest extend
876       * get of a forked task throws exception when task cancelled
877       */
878      public void testCancelledForkGet() {
879 <       ForkJoinTask a = new CheckedFJTask() {
880 <            public void realCompute() throws Exception {
881 <                CCF f = new LCCF(null, 8);
879 >        ForkJoinTask a = new CheckedRecursiveAction() {
880 >            protected void realCompute() throws Exception {
881 >                CCF f = new LCCF(8);
882                  assertTrue(f.cancel(true));
883                  assertSame(f, f.fork());
884                  try {
# Line 807 | Line 895 | public class CountedCompleterTest extend
895       * timed get of a forked task throws exception when task cancelled
896       */
897      public void testCancelledForkTimedGet() throws Exception {
898 <       ForkJoinTask a = new CheckedFJTask() {
899 <            public void realCompute() throws Exception {
900 <                CCF f = new LCCF(null, 8);
898 >        ForkJoinTask a = new CheckedRecursiveAction() {
899 >            protected void realCompute() throws Exception {
900 >                CCF f = new LCCF(8);
901                  assertTrue(f.cancel(true));
902                  assertSame(f, f.fork());
903                  try {
# Line 826 | Line 914 | public class CountedCompleterTest extend
914       * quietlyJoin of a forked task returns when task cancelled
915       */
916      public void testCancelledForkQuietlyJoin() {
917 <       ForkJoinTask a = new CheckedFJTask() {
918 <            public void realCompute() {
919 <                CCF f = new LCCF(null, 8);
917 >        ForkJoinTask a = new CheckedRecursiveAction() {
918 >            protected void realCompute() {
919 >                CCF f = new LCCF(8);
920                  assertTrue(f.cancel(true));
921                  assertSame(f, f.fork());
922                  f.quietlyJoin();
# Line 842 | Line 930 | public class CountedCompleterTest extend
930       */
931      public void testGetPool() {
932          final ForkJoinPool mainPool = mainPool();
933 <       ForkJoinTask a = new CheckedFJTask() {
934 <            public void realCompute() {
933 >        ForkJoinTask a = new CheckedRecursiveAction() {
934 >            protected void realCompute() {
935                  assertSame(mainPool, getPool());
936              }};
937          testInvokeOnPool(mainPool, a);
# Line 853 | Line 941 | public class CountedCompleterTest extend
941       * getPool of non-FJ task returns null
942       */
943      public void testGetPool2() {
944 <       ForkJoinTask a = new CheckedFJTask() {
945 <            public void realCompute() {
944 >        ForkJoinTask a = new CheckedRecursiveAction() {
945 >            protected void realCompute() {
946                  assertNull(getPool());
947              }};
948          assertNull(a.invoke());
# Line 864 | Line 952 | public class CountedCompleterTest extend
952       * inForkJoinPool of executing task returns true
953       */
954      public void testInForkJoinPool() {
955 <       ForkJoinTask a = new CheckedFJTask() {
956 <            public void realCompute() {
955 >        ForkJoinTask a = new CheckedRecursiveAction() {
956 >            protected void realCompute() {
957                  assertTrue(inForkJoinPool());
958              }};
959          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 963 | public class CountedCompleterTest extend
963       * inForkJoinPool of non-FJ task returns false
964       */
965      public void testInForkJoinPool2() {
966 <       ForkJoinTask a = new CheckedFJTask() {
967 <            public void realCompute() {
966 >        ForkJoinTask a = new CheckedRecursiveAction() {
967 >            protected void realCompute() {
968                  assertFalse(inForkJoinPool());
969              }};
970          assertNull(a.invoke());
# Line 886 | Line 974 | public class CountedCompleterTest extend
974       * setRawResult(null) succeeds
975       */
976      public void testSetRawResult() {
977 <       ForkJoinTask a = new CheckedFJTask() {
978 <            public void realCompute() {
977 >        ForkJoinTask a = new CheckedRecursiveAction() {
978 >            protected void realCompute() {
979                  setRawResult(null);
980                  assertNull(getRawResult());
981              }};
# Line 898 | Line 986 | public class CountedCompleterTest extend
986       * invoke task throws exception after invoking completeExceptionally
987       */
988      public void testCompleteExceptionally2() {
989 <       ForkJoinTask a = new CheckedFJTask() {
990 <            public void realCompute() {
991 <                CCF f = new LCCF(null, 8);
992 <                f.completeExceptionally(new FJException());
993 <                try {
994 <                    f.invoke();
995 <                    shouldThrow();
996 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
989 >        ForkJoinTask a = new CheckedRecursiveAction() {
990 >            protected void realCompute() {
991 >                CCF n = new LCCF(8);
992 >                CCF f = new LCCF(n, 8);
993 >                FJException ex = new FJException();
994 >                f.completeExceptionally(ex);
995 >                f.checkCompletedExceptionally(ex);
996 >                n.checkCompletedExceptionally(ex);
997              }};
998          testInvokeOnPool(mainPool(), a);
999      }
# Line 916 | Line 1002 | public class CountedCompleterTest extend
1002       * invokeAll(t1, t2) invokes all task arguments
1003       */
1004      public void testInvokeAll2() {
1005 <       ForkJoinTask a = new CheckedFJTask() {
1006 <            public void realCompute() {
1007 <                CCF f = new LCCF(null, 8);
1008 <                CCF g = new LCCF(null, 9);
1005 >        ForkJoinTask a = new CheckedRecursiveAction() {
1006 >            protected void realCompute() {
1007 >                CCF f = new LCCF(8);
1008 >                CCF g = new LCCF(9);
1009                  invokeAll(f, g);
1010                  assertEquals(21, f.number);
1011                  assertEquals(34, g.number);
# Line 933 | Line 1019 | public class CountedCompleterTest extend
1019       * invokeAll(tasks) with 1 argument invokes task
1020       */
1021      public void testInvokeAll1() {
1022 <       ForkJoinTask a = new CheckedFJTask() {
1023 <            public void realCompute() {
1024 <                CCF f = new LCCF(null, 8);
1022 >        ForkJoinTask a = new CheckedRecursiveAction() {
1023 >            protected void realCompute() {
1024 >                CCF f = new LCCF(8);
1025                  invokeAll(f);
1026                  checkCompletedNormally(f);
1027                  assertEquals(21, f.number);
# Line 947 | Line 1033 | public class CountedCompleterTest extend
1033       * invokeAll(tasks) with > 2 argument invokes tasks
1034       */
1035      public void testInvokeAll3() {
1036 <       ForkJoinTask a = new CheckedFJTask() {
1037 <            public void realCompute() {
1038 <                CCF f = new LCCF(null, 8);
1039 <                CCF g = new LCCF(null, 9);
1040 <                CCF h = new LCCF(null, 7);
1036 >        ForkJoinTask a = new CheckedRecursiveAction() {
1037 >            protected void realCompute() {
1038 >                CCF f = new LCCF(8);
1039 >                CCF g = new LCCF(9);
1040 >                CCF h = new LCCF(7);
1041                  invokeAll(f, g, h);
1042                  assertEquals(21, f.number);
1043                  assertEquals(34, g.number);
# Line 967 | Line 1053 | public class CountedCompleterTest extend
1053       * invokeAll(collection) invokes all tasks in the collection
1054       */
1055      public void testInvokeAllCollection() {
1056 <       ForkJoinTask a = new CheckedFJTask() {
1057 <            public void realCompute() {
1058 <                CCF f = new LCCF(null, 8);
1059 <                CCF g = new LCCF(null, 9);
1060 <                CCF h = new LCCF(null, 7);
1056 >        ForkJoinTask a = new CheckedRecursiveAction() {
1057 >            protected void realCompute() {
1058 >                CCF f = new LCCF(8);
1059 >                CCF g = new LCCF(9);
1060 >                CCF h = new LCCF(7);
1061                  HashSet set = new HashSet();
1062                  set.add(f);
1063                  set.add(g);
# Line 991 | Line 1077 | public class CountedCompleterTest extend
1077       * invokeAll(tasks) with any null task throws NPE
1078       */
1079      public void testInvokeAllNPE() {
1080 <       ForkJoinTask a = new CheckedFJTask() {
1081 <            public void realCompute() {
1082 <                CCF f = new LCCF(null, 8);
1083 <                CCF g = new LCCF(null, 9);
1080 >        ForkJoinTask a = new CheckedRecursiveAction() {
1081 >            protected void realCompute() {
1082 >                CCF f = new LCCF(8);
1083 >                CCF g = new LCCF(9);
1084                  CCF h = null;
1085                  try {
1086                      invokeAll(f, g, h);
# Line 1008 | Line 1094 | public class CountedCompleterTest extend
1094       * invokeAll(t1, t2) throw exception if any task does
1095       */
1096      public void testAbnormalInvokeAll2() {
1097 <       ForkJoinTask a = new CheckedFJTask() {
1098 <            public void realCompute() {
1099 <                CCF f = new LCCF(null, 8);
1100 <                FailingCCF g = new LFCCF(null, 9);
1097 >        ForkJoinTask a = new CheckedRecursiveAction() {
1098 >            protected void realCompute() {
1099 >                CCF f = new LCCF(8);
1100 >                FailingCCF g = new LFCCF(9);
1101                  try {
1102                      invokeAll(f, g);
1103                      shouldThrow();
# Line 1026 | Line 1112 | public class CountedCompleterTest extend
1112       * invokeAll(tasks) with 1 argument throws exception if task does
1113       */
1114      public void testAbnormalInvokeAll1() {
1115 <       ForkJoinTask a = new CheckedFJTask() {
1116 <            public void realCompute() {
1117 <                FailingCCF g = new LFCCF(null, 9);
1115 >        ForkJoinTask a = new CheckedRecursiveAction() {
1116 >            protected void realCompute() {
1117 >                FailingCCF g = new LFCCF(9);
1118                  try {
1119                      invokeAll(g);
1120                      shouldThrow();
# Line 1043 | Line 1129 | public class CountedCompleterTest extend
1129       * invokeAll(tasks) with > 2 argument throws exception if any task does
1130       */
1131      public void testAbnormalInvokeAll3() {
1132 <       ForkJoinTask a = new CheckedFJTask() {
1133 <            public void realCompute() {
1134 <                CCF f = new LCCF(null, 8);
1135 <                FailingCCF g = new LFCCF(null, 9);
1136 <                CCF h = new LCCF(null, 7);
1132 >        ForkJoinTask a = new CheckedRecursiveAction() {
1133 >            protected void realCompute() {
1134 >                CCF f = new LCCF(8);
1135 >                FailingCCF g = new LFCCF(9);
1136 >                CCF h = new LCCF(7);
1137                  try {
1138                      invokeAll(f, g, h);
1139                      shouldThrow();
# Line 1059 | Line 1145 | public class CountedCompleterTest extend
1145      }
1146  
1147      /**
1148 <     * invokeAll(collection)  throws exception if any task does
1148 >     * invokeAll(collection) throws exception if any task does
1149       */
1150      public void testAbnormalInvokeAllCollection() {
1151 <       ForkJoinTask a = new CheckedFJTask() {
1152 <            public void realCompute() {
1153 <                FailingCCF f = new LFCCF(null, 8);
1154 <                CCF g = new LCCF(null, 9);
1155 <                CCF h = new LCCF(null, 7);
1151 >        ForkJoinTask a = new CheckedRecursiveAction() {
1152 >            protected void realCompute() {
1153 >                FailingCCF f = new LFCCF(8);
1154 >                CCF g = new LCCF(9);
1155 >                CCF h = new LCCF(7);
1156                  HashSet set = new HashSet();
1157                  set.add(f);
1158                  set.add(g);
# Line 1086 | Line 1172 | public class CountedCompleterTest extend
1172       * and suppresses execution
1173       */
1174      public void testTryUnfork() {
1175 <       ForkJoinTask a = new CheckedFJTask() {
1176 <            public void realCompute() {
1177 <                CCF g = new LCCF(null, 9);
1175 >        ForkJoinTask a = new CheckedRecursiveAction() {
1176 >            protected void realCompute() {
1177 >                CCF g = new LCCF(9);
1178                  assertSame(g, g.fork());
1179 <                CCF f = new LCCF(null, 8);
1179 >                CCF f = new LCCF(8);
1180                  assertSame(f, f.fork());
1181                  assertTrue(f.tryUnfork());
1182                  helpQuiesce();
# Line 1105 | Line 1191 | public class CountedCompleterTest extend
1191       * there are more tasks than threads
1192       */
1193      public void testGetSurplusQueuedTaskCount() {
1194 <       ForkJoinTask a = new CheckedFJTask() {
1195 <            public void realCompute() {
1196 <                CCF h = new LCCF(null, 7);
1194 >        ForkJoinTask a = new CheckedRecursiveAction() {
1195 >            protected void realCompute() {
1196 >                CCF h = new LCCF(7);
1197                  assertSame(h, h.fork());
1198 <                CCF g = new LCCF(null, 9);
1198 >                CCF g = new LCCF(9);
1199                  assertSame(g, g.fork());
1200 <                CCF f = new LCCF(null, 8);
1200 >                CCF f = new LCCF(8);
1201                  assertSame(f, f.fork());
1202                  assertTrue(getSurplusQueuedTaskCount() > 0);
1203                  helpQuiesce();
# Line 1127 | Line 1213 | public class CountedCompleterTest extend
1213       * peekNextLocalTask returns most recent unexecuted task.
1214       */
1215      public void testPeekNextLocalTask() {
1216 <       ForkJoinTask a = new CheckedFJTask() {
1217 <            public void realCompute() {
1218 <                CCF g = new LCCF(null, 9);
1216 >        ForkJoinTask a = new CheckedRecursiveAction() {
1217 >            protected void realCompute() {
1218 >                CCF g = new LCCF(9);
1219                  assertSame(g, g.fork());
1220 <                CCF f = new LCCF(null, 8);
1220 >                CCF f = new LCCF(8);
1221                  assertSame(f, f.fork());
1222                  assertSame(f, peekNextLocalTask());
1223                  assertNull(f.join());
# Line 1147 | Line 1233 | public class CountedCompleterTest extend
1233       * executing it
1234       */
1235      public void testPollNextLocalTask() {
1236 <       ForkJoinTask a = new CheckedFJTask() {
1237 <            public void realCompute() {
1238 <                CCF g = new LCCF(null, 9);
1236 >        ForkJoinTask a = new CheckedRecursiveAction() {
1237 >            protected void realCompute() {
1238 >                CCF g = new LCCF(9);
1239                  assertSame(g, g.fork());
1240 <                CCF f = new LCCF(null, 8);
1240 >                CCF f = new LCCF(8);
1241                  assertSame(f, f.fork());
1242                  assertSame(f, pollNextLocalTask());
1243                  helpQuiesce();
# Line 1166 | Line 1252 | public class CountedCompleterTest extend
1252       * pollTask returns an unexecuted task without executing it
1253       */
1254      public void testPollTask() {
1255 <       ForkJoinTask a = new CheckedFJTask() {
1256 <            public void realCompute() {
1257 <                CCF g = new LCCF(null, 9);
1255 >        ForkJoinTask a = new CheckedRecursiveAction() {
1256 >            protected void realCompute() {
1257 >                CCF g = new LCCF(9);
1258                  assertSame(g, g.fork());
1259 <                CCF f = new LCCF(null, 8);
1259 >                CCF f = new LCCF(8);
1260                  assertSame(f, f.fork());
1261                  assertSame(f, pollTask());
1262                  helpQuiesce();
# Line 1184 | Line 1270 | public class CountedCompleterTest extend
1270       * peekNextLocalTask returns least recent unexecuted task in async mode
1271       */
1272      public void testPeekNextLocalTaskAsync() {
1273 <       ForkJoinTask a = new CheckedFJTask() {
1274 <            public void realCompute() {
1275 <                CCF g = new LCCF(null, 9);
1273 >        ForkJoinTask a = new CheckedRecursiveAction() {
1274 >            protected void realCompute() {
1275 >                CCF g = new LCCF(9);
1276                  assertSame(g, g.fork());
1277 <                CCF f = new LCCF(null, 8);
1277 >                CCF f = new LCCF(8);
1278                  assertSame(f, f.fork());
1279                  assertSame(g, peekNextLocalTask());
1280                  assertNull(f.join());
# Line 1205 | Line 1291 | public class CountedCompleterTest extend
1291       * executing it, in async mode
1292       */
1293      public void testPollNextLocalTaskAsync() {
1294 <       ForkJoinTask a = new CheckedFJTask() {
1295 <            public void realCompute() {
1296 <                CCF g = new LCCF(null, 9);
1294 >        ForkJoinTask a = new CheckedRecursiveAction() {
1295 >            protected void realCompute() {
1296 >                CCF g = new LCCF(9);
1297                  assertSame(g, g.fork());
1298 <                CCF f = new LCCF(null, 8);
1298 >                CCF f = new LCCF(8);
1299                  assertSame(f, f.fork());
1300                  assertSame(g, pollNextLocalTask());
1301                  helpQuiesce();
# Line 1225 | Line 1311 | public class CountedCompleterTest extend
1311       * async mode
1312       */
1313      public void testPollTaskAsync() {
1314 <       ForkJoinTask a = new CheckedFJTask() {
1315 <            public void realCompute() {
1316 <                CCF g = new LCCF(null, 9);
1314 >        ForkJoinTask a = new CheckedRecursiveAction() {
1315 >            protected void realCompute() {
1316 >                CCF g = new LCCF(9);
1317                  assertSame(g, g.fork());
1318 <                CCF f = new LCCF(null, 8);
1318 >                CCF f = new LCCF(8);
1319                  assertSame(f, f.fork());
1320                  assertSame(g, pollTask());
1321                  helpQuiesce();
# Line 1248 | Line 1334 | public class CountedCompleterTest extend
1334       * completed tasks; getRawResult returns null.
1335       */
1336      public void testInvokeSingleton() {
1337 <       ForkJoinTask a = new CheckedFJTask() {
1338 <            public void realCompute() {
1339 <                CCF f = new LCCF(null, 8);
1337 >        ForkJoinTask a = new CheckedRecursiveAction() {
1338 >            protected void realCompute() {
1339 >                CCF f = new LCCF(8);
1340                  assertNull(f.invoke());
1341                  assertEquals(21, f.number);
1342                  checkCompletedNormally(f);
# Line 1264 | Line 1350 | public class CountedCompleterTest extend
1350       * completed tasks
1351       */
1352      public void testQuietlyInvokeSingleton() {
1353 <       ForkJoinTask a = new CheckedFJTask() {
1354 <            public void realCompute() {
1355 <                CCF f = new LCCF(null, 8);
1353 >        ForkJoinTask a = new CheckedRecursiveAction() {
1354 >            protected void realCompute() {
1355 >                CCF f = new LCCF(8);
1356                  f.quietlyInvoke();
1357                  assertEquals(21, f.number);
1358                  checkCompletedNormally(f);
# Line 1278 | Line 1364 | public class CountedCompleterTest extend
1364       * join of a forked task returns when task completes
1365       */
1366      public void testForkJoinSingleton() {
1367 <       ForkJoinTask a = new CheckedFJTask() {
1368 <            public void realCompute() {
1369 <                CCF f = new LCCF(null, 8);
1367 >        ForkJoinTask a = new CheckedRecursiveAction() {
1368 >            protected void realCompute() {
1369 >                CCF f = new LCCF(8);
1370                  assertSame(f, f.fork());
1371                  assertNull(f.join());
1372                  assertEquals(21, f.number);
# Line 1293 | Line 1379 | public class CountedCompleterTest extend
1379       * get of a forked task returns when task completes
1380       */
1381      public void testForkGetSingleton() {
1382 <       ForkJoinTask a = new CheckedFJTask() {
1383 <            public void realCompute() throws Exception {
1384 <                CCF f = new LCCF(null, 8);
1382 >        ForkJoinTask a = new CheckedRecursiveAction() {
1383 >            protected void realCompute() throws Exception {
1384 >                CCF f = new LCCF(8);
1385                  assertSame(f, f.fork());
1386                  assertNull(f.get());
1387                  assertEquals(21, f.number);
# Line 1308 | Line 1394 | public class CountedCompleterTest extend
1394       * timed get of a forked task returns when task completes
1395       */
1396      public void testForkTimedGetSingleton() {
1397 <       ForkJoinTask a = new CheckedFJTask() {
1398 <            public void realCompute() throws Exception {
1399 <                CCF f = new LCCF(null, 8);
1397 >        ForkJoinTask a = new CheckedRecursiveAction() {
1398 >            protected void realCompute() throws Exception {
1399 >                CCF f = new LCCF(8);
1400                  assertSame(f, f.fork());
1401                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1402                  assertEquals(21, f.number);
# Line 1323 | Line 1409 | public class CountedCompleterTest extend
1409       * timed get with null time unit throws NPE
1410       */
1411      public void testForkTimedGetNPESingleton() {
1412 <       ForkJoinTask a = new CheckedFJTask() {
1413 <            public void realCompute() throws Exception {
1414 <                CCF f = new LCCF(null, 8);
1412 >        ForkJoinTask a = new CheckedRecursiveAction() {
1413 >            protected void realCompute() throws Exception {
1414 >                CCF f = new LCCF(8);
1415                  assertSame(f, f.fork());
1416                  try {
1417                      f.get(5L, null);
# Line 1339 | Line 1425 | public class CountedCompleterTest extend
1425       * quietlyJoin of a forked task returns when task completes
1426       */
1427      public void testForkQuietlyJoinSingleton() {
1428 <       ForkJoinTask a = new CheckedFJTask() {
1429 <            public void realCompute() {
1430 <                CCF f = new LCCF(null, 8);
1428 >        ForkJoinTask a = new CheckedRecursiveAction() {
1429 >            protected void realCompute() {
1430 >                CCF f = new LCCF(8);
1431                  assertSame(f, f.fork());
1432                  f.quietlyJoin();
1433                  assertEquals(21, f.number);
# Line 1355 | Line 1441 | public class CountedCompleterTest extend
1441       * getQueuedTaskCount returns 0 when quiescent
1442       */
1443      public void testForkHelpQuiesceSingleton() {
1444 <       ForkJoinTask a = new CheckedFJTask() {
1445 <            public void realCompute() {
1446 <                CCF f = new LCCF(null, 8);
1444 >        ForkJoinTask a = new CheckedRecursiveAction() {
1445 >            protected void realCompute() {
1446 >                CCF f = new LCCF(8);
1447                  assertSame(f, f.fork());
1448                  helpQuiesce();
1449                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1457 | public class CountedCompleterTest extend
1457       * invoke task throws exception when task completes abnormally
1458       */
1459      public void testAbnormalInvokeSingleton() {
1460 <       ForkJoinTask a = new CheckedFJTask() {
1461 <            public void realCompute() {
1462 <                FailingCCF f = new LFCCF(null, 8);
1460 >        ForkJoinTask a = new CheckedRecursiveAction() {
1461 >            protected void realCompute() {
1462 >                FailingCCF f = new LFCCF(8);
1463                  try {
1464                      f.invoke();
1465                      shouldThrow();
# Line 1388 | Line 1474 | public class CountedCompleterTest extend
1474       * quietlyInvoke task returns when task completes abnormally
1475       */
1476      public void testAbnormalQuietlyInvokeSingleton() {
1477 <       ForkJoinTask a = new CheckedFJTask() {
1478 <            public void realCompute() {
1479 <                FailingCCF f = new LFCCF(null, 8);
1477 >        ForkJoinTask a = new CheckedRecursiveAction() {
1478 >            protected void realCompute() {
1479 >                FailingCCF f = new LFCCF(8);
1480                  f.quietlyInvoke();
1481                  assertTrue(f.getException() instanceof FJException);
1482                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1488 | public class CountedCompleterTest extend
1488       * join of a forked task throws exception when task completes abnormally
1489       */
1490      public void testAbnormalForkJoinSingleton() {
1491 <       ForkJoinTask a = new CheckedFJTask() {
1492 <            public void realCompute() {
1493 <                FailingCCF f = new LFCCF(null, 8);
1491 >        ForkJoinTask a = new CheckedRecursiveAction() {
1492 >            protected void realCompute() {
1493 >                FailingCCF f = new LFCCF(8);
1494                  assertSame(f, f.fork());
1495                  try {
1496                      f.join();
# Line 1420 | Line 1506 | public class CountedCompleterTest extend
1506       * get of a forked task throws exception when task completes abnormally
1507       */
1508      public void testAbnormalForkGetSingleton() {
1509 <       ForkJoinTask a = new CheckedFJTask() {
1510 <            public void realCompute() throws Exception {
1511 <                FailingCCF f = new LFCCF(null, 8);
1509 >        ForkJoinTask a = new CheckedRecursiveAction() {
1510 >            protected void realCompute() throws Exception {
1511 >                FailingCCF f = new LFCCF(8);
1512                  assertSame(f, f.fork());
1513                  try {
1514                      f.get();
# Line 1440 | Line 1526 | public class CountedCompleterTest extend
1526       * timed get of a forked task throws exception when task completes abnormally
1527       */
1528      public void testAbnormalForkTimedGetSingleton() {
1529 <       ForkJoinTask a = new CheckedFJTask() {
1530 <            public void realCompute() throws Exception {
1531 <                FailingCCF f = new LFCCF(null, 8);
1529 >        ForkJoinTask a = new CheckedRecursiveAction() {
1530 >            protected void realCompute() throws Exception {
1531 >                FailingCCF f = new LFCCF(8);
1532                  assertSame(f, f.fork());
1533                  try {
1534                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1546 | public class CountedCompleterTest extend
1546       * quietlyJoin of a forked task returns when task completes abnormally
1547       */
1548      public void testAbnormalForkQuietlyJoinSingleton() {
1549 <       ForkJoinTask a = new CheckedFJTask() {
1550 <            public void realCompute() {
1551 <                FailingCCF f = new LFCCF(null, 8);
1549 >        ForkJoinTask a = new CheckedRecursiveAction() {
1550 >            protected void realCompute() {
1551 >                FailingCCF f = new LFCCF(8);
1552                  assertSame(f, f.fork());
1553                  f.quietlyJoin();
1554                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1561 | public class CountedCompleterTest extend
1561       * invoke task throws exception when task cancelled
1562       */
1563      public void testCancelledInvokeSingleton() {
1564 <       ForkJoinTask a = new CheckedFJTask() {
1565 <            public void realCompute() {
1566 <                CCF f = new LCCF(null, 8);
1564 >        ForkJoinTask a = new CheckedRecursiveAction() {
1565 >            protected void realCompute() {
1566 >                CCF f = new LCCF(8);
1567                  assertTrue(f.cancel(true));
1568                  try {
1569                      f.invoke();
# Line 1493 | Line 1579 | public class CountedCompleterTest extend
1579       * join of a forked task throws exception when task cancelled
1580       */
1581      public void testCancelledForkJoinSingleton() {
1582 <       ForkJoinTask a = new CheckedFJTask() {
1583 <            public void realCompute() {
1584 <                CCF f = new LCCF(null, 8);
1582 >        ForkJoinTask a = new CheckedRecursiveAction() {
1583 >            protected void realCompute() {
1584 >                CCF f = new LCCF(8);
1585                  assertTrue(f.cancel(true));
1586                  assertSame(f, f.fork());
1587                  try {
# Line 1512 | Line 1598 | public class CountedCompleterTest extend
1598       * get of a forked task throws exception when task cancelled
1599       */
1600      public void testCancelledForkGetSingleton() {
1601 <       ForkJoinTask a = new CheckedFJTask() {
1602 <            public void realCompute() throws Exception {
1603 <                CCF f = new LCCF(null, 8);
1601 >        ForkJoinTask a = new CheckedRecursiveAction() {
1602 >            protected void realCompute() throws Exception {
1603 >                CCF f = new LCCF(8);
1604                  assertTrue(f.cancel(true));
1605                  assertSame(f, f.fork());
1606                  try {
# Line 1531 | Line 1617 | public class CountedCompleterTest extend
1617       * timed get of a forked task throws exception when task cancelled
1618       */
1619      public void testCancelledForkTimedGetSingleton() throws Exception {
1620 <       ForkJoinTask a = new CheckedFJTask() {
1621 <            public void realCompute() throws Exception {
1622 <                CCF f = new LCCF(null, 8);
1620 >        ForkJoinTask a = new CheckedRecursiveAction() {
1621 >            protected void realCompute() throws Exception {
1622 >                CCF f = new LCCF(8);
1623                  assertTrue(f.cancel(true));
1624                  assertSame(f, f.fork());
1625                  try {
# Line 1550 | Line 1636 | public class CountedCompleterTest extend
1636       * quietlyJoin of a forked task returns when task cancelled
1637       */
1638      public void testCancelledForkQuietlyJoinSingleton() {
1639 <       ForkJoinTask a = new CheckedFJTask() {
1640 <            public void realCompute() {
1641 <                CCF f = new LCCF(null, 8);
1639 >        ForkJoinTask a = new CheckedRecursiveAction() {
1640 >            protected void realCompute() {
1641 >                CCF f = new LCCF(8);
1642                  assertTrue(f.cancel(true));
1643                  assertSame(f, f.fork());
1644                  f.quietlyJoin();
# Line 1565 | Line 1651 | public class CountedCompleterTest extend
1651       * invoke task throws exception after invoking completeExceptionally
1652       */
1653      public void testCompleteExceptionallySingleton() {
1654 <       ForkJoinTask a = new CheckedFJTask() {
1655 <            public void realCompute() {
1656 <                CCF f = new LCCF(null, 8);
1657 <                f.completeExceptionally(new FJException());
1658 <                try {
1659 <                    f.invoke();
1660 <                    shouldThrow();
1661 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1654 >        ForkJoinTask a = new CheckedRecursiveAction() {
1655 >            protected void realCompute() {
1656 >                CCF n = new LCCF(8);
1657 >                CCF f = new LCCF(n, 8);
1658 >                FJException ex = new FJException();
1659 >                f.completeExceptionally(ex);
1660 >                f.checkCompletedExceptionally(ex);
1661 >                n.checkCompletedExceptionally(ex);
1662              }};
1663          testInvokeOnPool(singletonPool(), a);
1664      }
# Line 1583 | Line 1667 | public class CountedCompleterTest extend
1667       * invokeAll(t1, t2) invokes all task arguments
1668       */
1669      public void testInvokeAll2Singleton() {
1670 <       ForkJoinTask a = new CheckedFJTask() {
1671 <            public void realCompute() {
1672 <                CCF f = new LCCF(null, 8);
1673 <                CCF g = new LCCF(null, 9);
1670 >        ForkJoinTask a = new CheckedRecursiveAction() {
1671 >            protected void realCompute() {
1672 >                CCF f = new LCCF(8);
1673 >                CCF g = new LCCF(9);
1674                  invokeAll(f, g);
1675                  assertEquals(21, f.number);
1676                  assertEquals(34, g.number);
# Line 1600 | Line 1684 | public class CountedCompleterTest extend
1684       * invokeAll(tasks) with 1 argument invokes task
1685       */
1686      public void testInvokeAll1Singleton() {
1687 <       ForkJoinTask a = new CheckedFJTask() {
1688 <            public void realCompute() {
1689 <                CCF f = new LCCF(null, 8);
1687 >        ForkJoinTask a = new CheckedRecursiveAction() {
1688 >            protected void realCompute() {
1689 >                CCF f = new LCCF(8);
1690                  invokeAll(f);
1691                  checkCompletedNormally(f);
1692                  assertEquals(21, f.number);
# Line 1614 | Line 1698 | public class CountedCompleterTest extend
1698       * invokeAll(tasks) with > 2 argument invokes tasks
1699       */
1700      public void testInvokeAll3Singleton() {
1701 <       ForkJoinTask a = new CheckedFJTask() {
1702 <            public void realCompute() {
1703 <                CCF f = new LCCF(null, 8);
1704 <                CCF g = new LCCF(null, 9);
1705 <                CCF h = new LCCF(null, 7);
1701 >        ForkJoinTask a = new CheckedRecursiveAction() {
1702 >            protected void realCompute() {
1703 >                CCF f = new LCCF(8);
1704 >                CCF g = new LCCF(9);
1705 >                CCF h = new LCCF(7);
1706                  invokeAll(f, g, h);
1707                  assertEquals(21, f.number);
1708                  assertEquals(34, g.number);
# Line 1634 | Line 1718 | public class CountedCompleterTest extend
1718       * invokeAll(collection) invokes all tasks in the collection
1719       */
1720      public void testInvokeAllCollectionSingleton() {
1721 <       ForkJoinTask a = new CheckedFJTask() {
1722 <            public void realCompute() {
1723 <                CCF f = new LCCF(null, 8);
1724 <                CCF g = new LCCF(null, 9);
1725 <                CCF h = new LCCF(null, 7);
1721 >        ForkJoinTask a = new CheckedRecursiveAction() {
1722 >            protected void realCompute() {
1723 >                CCF f = new LCCF(8);
1724 >                CCF g = new LCCF(9);
1725 >                CCF h = new LCCF(7);
1726                  HashSet set = new HashSet();
1727                  set.add(f);
1728                  set.add(g);
# Line 1658 | Line 1742 | public class CountedCompleterTest extend
1742       * invokeAll(tasks) with any null task throws NPE
1743       */
1744      public void testInvokeAllNPESingleton() {
1745 <       ForkJoinTask a = new CheckedFJTask() {
1746 <            public void realCompute() {
1747 <                CCF f = new LCCF(null, 8);
1748 <                CCF g = new LCCF(null, 9);
1745 >        ForkJoinTask a = new CheckedRecursiveAction() {
1746 >            protected void realCompute() {
1747 >                CCF f = new LCCF(8);
1748 >                CCF g = new LCCF(9);
1749                  CCF h = null;
1750                  try {
1751                      invokeAll(f, g, h);
# Line 1675 | Line 1759 | public class CountedCompleterTest extend
1759       * invokeAll(t1, t2) throw exception if any task does
1760       */
1761      public void testAbnormalInvokeAll2Singleton() {
1762 <       ForkJoinTask a = new CheckedFJTask() {
1763 <            public void realCompute() {
1764 <                CCF f = new LCCF(null, 8);
1765 <                FailingCCF g = new LFCCF(null, 9);
1762 >        ForkJoinTask a = new CheckedRecursiveAction() {
1763 >            protected void realCompute() {
1764 >                CCF f = new LCCF(8);
1765 >                FailingCCF g = new LFCCF(9);
1766                  try {
1767                      invokeAll(f, g);
1768                      shouldThrow();
# Line 1693 | Line 1777 | public class CountedCompleterTest extend
1777       * invokeAll(tasks) with 1 argument throws exception if task does
1778       */
1779      public void testAbnormalInvokeAll1Singleton() {
1780 <       ForkJoinTask a = new CheckedFJTask() {
1781 <            public void realCompute() {
1782 <                FailingCCF g = new LFCCF(null, 9);
1780 >        ForkJoinTask a = new CheckedRecursiveAction() {
1781 >            protected void realCompute() {
1782 >                FailingCCF g = new LFCCF(9);
1783                  try {
1784                      invokeAll(g);
1785                      shouldThrow();
# Line 1710 | Line 1794 | public class CountedCompleterTest extend
1794       * invokeAll(tasks) with > 2 argument throws exception if any task does
1795       */
1796      public void testAbnormalInvokeAll3Singleton() {
1797 <       ForkJoinTask a = new CheckedFJTask() {
1798 <            public void realCompute() {
1799 <                CCF f = new LCCF(null, 8);
1800 <                FailingCCF g = new LFCCF(null, 9);
1801 <                CCF h = new LCCF(null, 7);
1797 >        ForkJoinTask a = new CheckedRecursiveAction() {
1798 >            protected void realCompute() {
1799 >                CCF f = new LCCF(8);
1800 >                FailingCCF g = new LFCCF(9);
1801 >                CCF h = new LCCF(7);
1802                  try {
1803                      invokeAll(f, g, h);
1804                      shouldThrow();
# Line 1726 | Line 1810 | public class CountedCompleterTest extend
1810      }
1811  
1812      /**
1813 <     * invokeAll(collection)  throws exception if any task does
1813 >     * invokeAll(collection) throws exception if any task does
1814       */
1815      public void testAbnormalInvokeAllCollectionSingleton() {
1816 <       ForkJoinTask a = new CheckedFJTask() {
1817 <            public void realCompute() {
1818 <                FailingCCF f = new LFCCF(null, 8);
1819 <                CCF g = new LCCF(null, 9);
1820 <                CCF h = new LCCF(null, 7);
1816 >        ForkJoinTask a = new CheckedRecursiveAction() {
1817 >            protected void realCompute() {
1818 >                FailingCCF f = new LFCCF(8);
1819 >                CCF g = new LCCF(9);
1820 >                CCF h = new LCCF(7);
1821                  HashSet set = new HashSet();
1822                  set.add(f);
1823                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines