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

Comparing jsr166/src/test/tck/CountedCompleterTest.java (file contents):
Revision 1.2 by dl, Thu Mar 21 16:26:43 2013 UTC vs.
Revision 1.24 by jsr166, Sun Oct 18 19:20:05 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.
288 >     * A newly constructed CountedCompleter is not completed;
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());
340 <        a.setPendingCount(27);
341 <        assertEquals(27, a.getPendingCount());
338 >        for (int val : new int[] { -1, 0, 1, Integer.MIN_VALUE, Integer.MAX_VALUE }) {
339 >            a.setPendingCount(val);
340 >            assertEquals(val, a.getPendingCount());
341 >        }
342      }
343  
344      /**
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 <        a.decrementPendingCountUnlessZero();
367 >        assertEquals(0, a.decrementPendingCountUnlessZero());
368          assertEquals(0, a.getPendingCount());
369 +        a.setPendingCount(-1);
370 +        assertEquals(-1, a.decrementPendingCountUnlessZero());
371 +        assertEquals(-2, a.getPendingCount());
372 +    }
373 +
374 +    /**
375 +     * compareAndSetPendingCount compares and sets the reported
376 +     * pending count
377 +     */
378 +    public void testCompareAndSetPendingCount() {
379 +        NoopCC a = new NoopCC();
380 +        assertEquals(0, a.getPendingCount());
381 +        assertTrue(a.compareAndSetPendingCount(0, 1));
382 +        assertEquals(1, a.getPendingCount());
383 +        assertTrue(a.compareAndSetPendingCount(1, 2));
384 +        assertEquals(2, a.getPendingCount());
385 +        assertFalse(a.compareAndSetPendingCount(1, 3));
386 +        assertEquals(2, a.getPendingCount());
387      }
388  
389      /**
390       * getCompleter returns parent or null if at root
391       */
392      public void testGetCompleter() {
393 <        NoopCountedCompleter a = new NoopCountedCompleter();
393 >        NoopCC a = new NoopCC();
394          assertNull(a.getCompleter());
395 <        CountedCompleter b = new NoopCountedCompleter(a);
396 <        assertEquals(a, b.getCompleter());
395 >        CountedCompleter b = new NoopCC(a);
396 >        assertSame(a, b.getCompleter());
397 >        CountedCompleter c = new NoopCC(b);
398 >        assertSame(b, c.getCompleter());
399      }
400 <    
400 >
401      /**
402       * getRoot returns self if no parent, else parent's root
403       */
404      public void testGetRoot() {
405 <        NoopCountedCompleter a = new NoopCountedCompleter();
406 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
407 <        assertEquals(a, a.getRoot());
408 <        assertEquals(a, b.getRoot());
405 >        NoopCC a = new NoopCC();
406 >        NoopCC b = new NoopCC(a);
407 >        NoopCC c = new NoopCC(b);
408 >        assertSame(a, a.getRoot());
409 >        assertSame(a, b.getRoot());
410 >        assertSame(a, c.getRoot());
411      }
412 <              
412 >
413      /**
414 <     * tryComplete causes completion if pending count is zero
414 >     * tryComplete decrements pending count unless zero, in which case
415 >     * causes completion
416       */
417 <    public void testTryComplete1() {
418 <        NoopCountedCompleter a = new NoopCountedCompleter();
417 >    public void testTryComplete() {
418 >        NoopCC a = new NoopCC();
419          assertEquals(0, a.getPendingCount());
420 +        int n = 3;
421 +        a.setPendingCount(n);
422 +        for (; n > 0; n--) {
423 +            assertEquals(n, a.getPendingCount());
424 +            a.tryComplete();
425 +            a.checkIncomplete();
426 +            assertEquals(n - 1, a.getPendingCount());
427 +        }
428          a.tryComplete();
429 <        assertTrue(a.post);
430 <        assertTrue(a.isDone());
429 >        assertEquals(0, a.computeN());
430 >        assertEquals(1, a.onCompletionN());
431 >        assertEquals(0, a.onExceptionalCompletionN());
432 >        assertEquals(0, a.setRawResultN());
433 >        checkCompletedNormally(a);
434      }
435  
436      /**
437 <     * propagateCompletion causes completion without invokein
438 <     * onCompletion if pending count is zero
437 >     * propagateCompletion decrements pending count unless zero, in
438 >     * which case causes completion, without invoking onCompletion
439       */
440      public void testPropagateCompletion() {
441 <        NoopCountedCompleter a = new NoopCountedCompleter();
441 >        NoopCC a = new NoopCC();
442          assertEquals(0, a.getPendingCount());
443 +        int n = 3;
444 +        a.setPendingCount(n);
445 +        for (; n > 0; n--) {
446 +            assertEquals(n, a.getPendingCount());
447 +            a.propagateCompletion();
448 +            a.checkIncomplete();
449 +            assertEquals(n - 1, a.getPendingCount());
450 +        }
451          a.propagateCompletion();
452 <        assertFalse(a.post);
453 <        assertTrue(a.isDone());
454 <    }
455 <
456 <    /**
358 <     * tryComplete decrments pending count unless zero
359 <     */
360 <    public void testTryComplete2() {
361 <        NoopCountedCompleter a = new NoopCountedCompleter();
362 <        assertEquals(0, a.getPendingCount());
363 <        a.setPendingCount(1);
364 <        a.tryComplete();
365 <        assertFalse(a.post);
366 <        assertFalse(a.isDone());
367 <        assertEquals(0, a.getPendingCount());
368 <        a.tryComplete();
369 <        assertTrue(a.post);
370 <        assertTrue(a.isDone());
452 >        assertEquals(0, a.computeN());
453 >        assertEquals(0, a.onCompletionN());
454 >        assertEquals(0, a.onExceptionalCompletionN());
455 >        assertEquals(0, a.setRawResultN());
456 >        checkCompletedNormally(a);
457      }
458  
459      /**
460       * firstComplete returns this if pending count is zero else null
461       */
462      public void testFirstComplete() {
463 <        NoopCountedCompleter a = new NoopCountedCompleter();
463 >        NoopCC a = new NoopCC();
464          a.setPendingCount(1);
465          assertNull(a.firstComplete());
466 <        assertEquals(a, a.firstComplete());
466 >        a.checkIncomplete();
467 >        assertSame(a, a.firstComplete());
468 >        a.checkIncomplete();
469      }
470  
471      /**
# Line 385 | Line 473 | public class CountedCompleterTest extend
473       * zero else null
474       */
475      public void testNextComplete() {
476 <        NoopCountedCompleter a = new NoopCountedCompleter();
477 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
476 >        NoopCC a = new NoopCC();
477 >        NoopCC b = new NoopCC(a);
478          a.setPendingCount(1);
479          b.setPendingCount(1);
480          assertNull(b.firstComplete());
481 <        CountedCompleter c = b.firstComplete();
482 <        assertEquals(b, c);
483 <        CountedCompleter d = c.nextComplete();
484 <        assertNull(d);
485 <        CountedCompleter e = c.nextComplete();
486 <        assertEquals(a, e);
481 >        assertSame(b, b.firstComplete());
482 >        assertNull(b.nextComplete());
483 >        a.checkIncomplete();
484 >        b.checkIncomplete();
485 >        assertSame(a, b.nextComplete());
486 >        assertSame(a, b.nextComplete());
487 >        a.checkIncomplete();
488 >        b.checkIncomplete();
489 >        assertNull(a.nextComplete());
490 >        b.checkIncomplete();
491 >        checkCompletedNormally(a);
492      }
493  
494      /**
495       * quietlyCompleteRoot completes root task
496       */
497      public void testQuietlyCompleteRoot() {
498 <        NoopCountedCompleter a = new NoopCountedCompleter();
499 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
498 >        NoopCC a = new NoopCC();
499 >        NoopCC b = new NoopCC(a);
500 >        NoopCC c = new NoopCC(b);
501          a.setPendingCount(1);
502          b.setPendingCount(1);
503 <        b.quietlyCompleteRoot();
503 >        c.setPendingCount(1);
504 >        c.quietlyCompleteRoot();
505          assertTrue(a.isDone());
506          assertFalse(b.isDone());
507 +        assertFalse(c.isDone());
508      }
509  
510      // Invocation tests use some interdependent task classes
511      // to better test propagation etc
512  
513 <    
514 <    // Version of Fibonacci with different classes for left vs right forks
515 <    static abstract class CCF extends CountedCompleter {
513 >    /**
514 >     * Version of Fibonacci with different classes for left vs right forks
515 >     */
516 >    abstract class CCF extends CheckedCC {
517          int number;
518          int rnumber;
519  
# Line 425 | Line 522 | public class CountedCompleterTest extend
522              this.number = n;
523          }
524  
525 <        public final void compute() {
429 <            CountedCompleter p;
525 >        protected final void realCompute() {
526              CCF f = this;
527              int n = number;
528              while (n >= 2) {
529                  new RCCF(f, n - 2).fork();
530                  f = new LCCF(f, --n);
531              }
532 <            f.number = n;
437 <            f.onCompletion(f);
438 <            if ((p = f.getCompleter()) != null)
439 <                p.tryComplete();
440 <            else
441 <                f.quietlyComplete();
532 >            f.complete(null);
533          }
534      }
535  
536 <    static final class LCCF extends CCF {
536 >    final class LCCF extends CCF {
537 >        public LCCF(int n) { this(null, n); }
538          public LCCF(CountedCompleter parent, int n) {
539              super(parent, n);
540          }
541          public final void onCompletion(CountedCompleter caller) {
542 +            super.onCompletion(caller);
543              CCF p = (CCF)getCompleter();
544              int n = number + rnumber;
545              if (p != null)
# Line 455 | Line 548 | public class CountedCompleterTest extend
548                  number = n;
549          }
550      }
551 <    static final class RCCF extends CCF {
551 >    final class RCCF extends CCF {
552          public RCCF(CountedCompleter parent, int n) {
553              super(parent, n);
554          }
555          public final void onCompletion(CountedCompleter caller) {
556 +            super.onCompletion(caller);
557              CCF p = (CCF)getCompleter();
558              int n = number + rnumber;
559              if (p != null)
# Line 470 | Line 564 | public class CountedCompleterTest extend
564      }
565  
566      // Version of CCF with forced failure in left completions
567 <    static abstract class FailingCCF extends CountedCompleter {
567 >    abstract class FailingCCF extends CheckedCC {
568          int number;
569          int rnumber;
570  
# Line 479 | Line 573 | public class CountedCompleterTest extend
573              this.number = n;
574          }
575  
576 <        public final void compute() {
483 <            CountedCompleter p;
576 >        protected final void realCompute() {
577              FailingCCF f = this;
578              int n = number;
579              while (n >= 2) {
580                  new RFCCF(f, n - 2).fork();
581                  f = new LFCCF(f, --n);
582              }
583 <            f.number = n;
491 <            f.onCompletion(f);
492 <            if ((p = f.getCompleter()) != null)
493 <                p.tryComplete();
494 <            else
495 <                f.quietlyComplete();
583 >            f.complete(null);
584          }
585      }
586  
587 <    static final class LFCCF extends FailingCCF {
587 >    final class LFCCF extends FailingCCF {
588 >        public LFCCF(int n) { this(null, n); }
589          public LFCCF(CountedCompleter parent, int n) {
590              super(parent, n);
591          }
592          public final void onCompletion(CountedCompleter caller) {
593 +            super.onCompletion(caller);
594              FailingCCF p = (FailingCCF)getCompleter();
595              int n = number + rnumber;
596              if (p != null)
# Line 509 | Line 599 | public class CountedCompleterTest extend
599                  number = n;
600          }
601      }
602 <    static final class RFCCF extends FailingCCF {
602 >    final class RFCCF extends FailingCCF {
603          public RFCCF(CountedCompleter parent, int n) {
604              super(parent, n);
605          }
606          public final void onCompletion(CountedCompleter caller) {
607 +            super.onCompletion(caller);
608              completeExceptionally(new FJException());
609          }
610      }
611 <    
611 >
612      /**
613       * invoke returns when task completes normally.
614       * isCompletedAbnormally and isCancelled return false for normally
615       * completed tasks; getRawResult returns null.
616       */
617      public void testInvoke() {
618 <       ForkJoinTask a =  new CheckedFJTask() {
619 <            public void realCompute() {
620 <                CCF f = new LCCF(null, 8);
618 >        ForkJoinTask a = new CheckedRecursiveAction() {
619 >            protected void realCompute() {
620 >                CCF f = new LCCF(8);
621                  assertNull(f.invoke());
622                  assertEquals(21, f.number);
623                  checkCompletedNormally(f);
# Line 540 | Line 631 | public class CountedCompleterTest extend
631       * completed tasks
632       */
633      public void testQuietlyInvoke() {
634 <       ForkJoinTask a =  new CheckedFJTask() {
635 <            public void realCompute() {
636 <                CCF f = new LCCF(null, 8);
634 >        ForkJoinTask a = new CheckedRecursiveAction() {
635 >            protected void realCompute() {
636 >                CCF f = new LCCF(8);
637                  f.quietlyInvoke();
638                  assertEquals(21, f.number);
639                  checkCompletedNormally(f);
# Line 554 | Line 645 | public class CountedCompleterTest extend
645       * join of a forked task returns when task completes
646       */
647      public void testForkJoin() {
648 <       ForkJoinTask a =  new CheckedFJTask() {
649 <            public void realCompute() {
650 <                CCF f = new LCCF(null, 8);
648 >        ForkJoinTask a = new CheckedRecursiveAction() {
649 >            protected void realCompute() {
650 >                CCF f = new LCCF(8);
651                  assertSame(f, f.fork());
652                  assertNull(f.join());
653                  assertEquals(21, f.number);
# Line 569 | Line 660 | public class CountedCompleterTest extend
660       * get of a forked task returns when task completes
661       */
662      public void testForkGet() {
663 <       ForkJoinTask a =  new CheckedFJTask() {
664 <            public void realCompute() throws Exception {
665 <                CCF f = new LCCF(null, 8);
663 >        ForkJoinTask a = new CheckedRecursiveAction() {
664 >            protected void realCompute() throws Exception {
665 >                CCF f = new LCCF(8);
666                  assertSame(f, f.fork());
667                  assertNull(f.get());
668                  assertEquals(21, f.number);
# Line 584 | Line 675 | public class CountedCompleterTest extend
675       * timed get of a forked task returns when task completes
676       */
677      public void testForkTimedGet() {
678 <       ForkJoinTask a =  new CheckedFJTask() {
679 <            public void realCompute() throws Exception {
680 <                CCF f = new LCCF(null, 8);
678 >        ForkJoinTask a = new CheckedRecursiveAction() {
679 >            protected void realCompute() throws Exception {
680 >                CCF f = new LCCF(8);
681                  assertSame(f, f.fork());
682                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
683                  assertEquals(21, f.number);
# Line 599 | Line 690 | public class CountedCompleterTest extend
690       * timed get with null time unit throws NPE
691       */
692      public void testForkTimedGetNPE() {
693 <       ForkJoinTask a =  new CheckedFJTask() {
694 <            public void realCompute() throws Exception {
695 <                CCF f = new LCCF(null, 8);
693 >        ForkJoinTask a = new CheckedRecursiveAction() {
694 >            protected void realCompute() throws Exception {
695 >                CCF f = new LCCF(8);
696                  assertSame(f, f.fork());
697                  try {
698                      f.get(5L, null);
# Line 615 | Line 706 | public class CountedCompleterTest extend
706       * quietlyJoin of a forked task returns when task completes
707       */
708      public void testForkQuietlyJoin() {
709 <       ForkJoinTask a =  new CheckedFJTask() {
710 <            public void realCompute() {
711 <                CCF f = new LCCF(null, 8);
709 >        ForkJoinTask a = new CheckedRecursiveAction() {
710 >            protected void realCompute() {
711 >                CCF f = new LCCF(8);
712                  assertSame(f, f.fork());
713                  f.quietlyJoin();
714                  assertEquals(21, f.number);
# Line 631 | Line 722 | public class CountedCompleterTest extend
722       * getQueuedTaskCount returns 0 when quiescent
723       */
724      public void testForkHelpQuiesce() {
725 <       ForkJoinTask a =  new CheckedFJTask() {
726 <            public void realCompute() {
727 <                CCF f = new LCCF(null, 8);
725 >        ForkJoinTask a = new CheckedRecursiveAction() {
726 >            protected void realCompute() {
727 >                CCF f = new LCCF(8);
728                  assertSame(f, f.fork());
729                  helpQuiesce();
730                  assertEquals(21, f.number);
# Line 647 | Line 738 | public class CountedCompleterTest extend
738       * invoke task throws exception when task completes abnormally
739       */
740      public void testAbnormalInvoke() {
741 <       ForkJoinTask a =  new CheckedFJTask() {
742 <            public void realCompute() {
743 <                FailingCCF f = new LFCCF(null, 8);
741 >        ForkJoinTask a = new CheckedRecursiveAction() {
742 >            protected void realCompute() {
743 >                FailingCCF f = new LFCCF(8);
744                  try {
745                      f.invoke();
746                      shouldThrow();
# Line 664 | Line 755 | public class CountedCompleterTest extend
755       * quietlyInvoke task returns when task completes abnormally
756       */
757      public void testAbnormalQuietlyInvoke() {
758 <       ForkJoinTask a =  new CheckedFJTask() {
759 <            public void realCompute() {
760 <                FailingCCF f = new LFCCF(null, 8);
758 >        ForkJoinTask a = new CheckedRecursiveAction() {
759 >            protected void realCompute() {
760 >                FailingCCF f = new LFCCF(8);
761                  f.quietlyInvoke();
762                  assertTrue(f.getException() instanceof FJException);
763                  checkCompletedAbnormally(f, f.getException());
# Line 678 | Line 769 | public class CountedCompleterTest extend
769       * join of a forked task throws exception when task completes abnormally
770       */
771      public void testAbnormalForkJoin() {
772 <       ForkJoinTask a =  new CheckedFJTask() {
773 <            public void realCompute() {
774 <                FailingCCF f = new LFCCF(null, 8);
772 >        ForkJoinTask a = new CheckedRecursiveAction() {
773 >            protected void realCompute() {
774 >                FailingCCF f = new LFCCF(8);
775                  assertSame(f, f.fork());
776                  try {
777                      f.join();
# Line 696 | Line 787 | public class CountedCompleterTest extend
787       * get of a forked task throws exception when task completes abnormally
788       */
789      public void testAbnormalForkGet() {
790 <       ForkJoinTask a =  new CheckedFJTask() {
791 <            public void realCompute() throws Exception {
792 <                FailingCCF f = new LFCCF(null, 8);
790 >        ForkJoinTask a = new CheckedRecursiveAction() {
791 >            protected void realCompute() throws Exception {
792 >                FailingCCF f = new LFCCF(8);
793                  assertSame(f, f.fork());
794                  try {
795                      f.get();
# Line 716 | Line 807 | public class CountedCompleterTest extend
807       * timed get of a forked task throws exception when task completes abnormally
808       */
809      public void testAbnormalForkTimedGet() {
810 <       ForkJoinTask a =  new CheckedFJTask() {
811 <            public void realCompute() throws Exception {
812 <                FailingCCF f = new LFCCF(null, 8);
810 >        ForkJoinTask a = new CheckedRecursiveAction() {
811 >            protected void realCompute() throws Exception {
812 >                FailingCCF f = new LFCCF(8);
813                  assertSame(f, f.fork());
814                  try {
815                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 736 | Line 827 | public class CountedCompleterTest extend
827       * quietlyJoin of a forked task returns when task completes abnormally
828       */
829      public void testAbnormalForkQuietlyJoin() {
830 <       ForkJoinTask a =  new CheckedFJTask() {
831 <            public void realCompute() {
832 <                FailingCCF f = new LFCCF(null, 8);
830 >        ForkJoinTask a = new CheckedRecursiveAction() {
831 >            protected void realCompute() {
832 >                FailingCCF f = new LFCCF(8);
833                  assertSame(f, f.fork());
834                  f.quietlyJoin();
835                  assertTrue(f.getException() instanceof FJException);
# Line 751 | Line 842 | public class CountedCompleterTest extend
842       * invoke task throws exception when task cancelled
843       */
844      public void testCancelledInvoke() {
845 <       ForkJoinTask a =  new CheckedFJTask() {
846 <            public void realCompute() {
847 <                CCF f = new LCCF(null, 8);
845 >        ForkJoinTask a = new CheckedRecursiveAction() {
846 >            protected void realCompute() {
847 >                CCF f = new LCCF(8);
848                  assertTrue(f.cancel(true));
849                  try {
850                      f.invoke();
# Line 769 | Line 860 | public class CountedCompleterTest extend
860       * join of a forked task throws exception when task cancelled
861       */
862      public void testCancelledForkJoin() {
863 <       ForkJoinTask a =  new CheckedFJTask() {
864 <            public void realCompute() {
865 <                CCF f = new LCCF(null, 8);
863 >        ForkJoinTask a = new CheckedRecursiveAction() {
864 >            protected void realCompute() {
865 >                CCF f = new LCCF(8);
866                  assertTrue(f.cancel(true));
867                  assertSame(f, f.fork());
868                  try {
# Line 788 | Line 879 | public class CountedCompleterTest extend
879       * get of a forked task throws exception when task cancelled
880       */
881      public void testCancelledForkGet() {
882 <       ForkJoinTask a =  new CheckedFJTask() {
883 <            public void realCompute() throws Exception {
884 <                CCF f = new LCCF(null, 8);
882 >        ForkJoinTask a = new CheckedRecursiveAction() {
883 >            protected void realCompute() throws Exception {
884 >                CCF f = new LCCF(8);
885                  assertTrue(f.cancel(true));
886                  assertSame(f, f.fork());
887                  try {
# Line 807 | Line 898 | public class CountedCompleterTest extend
898       * timed get of a forked task throws exception when task cancelled
899       */
900      public void testCancelledForkTimedGet() throws Exception {
901 <       ForkJoinTask a =  new CheckedFJTask() {
902 <            public void realCompute() throws Exception {
903 <                CCF f = new LCCF(null, 8);
901 >        ForkJoinTask a = new CheckedRecursiveAction() {
902 >            protected void realCompute() throws Exception {
903 >                CCF f = new LCCF(8);
904                  assertTrue(f.cancel(true));
905                  assertSame(f, f.fork());
906                  try {
# Line 826 | Line 917 | public class CountedCompleterTest extend
917       * quietlyJoin of a forked task returns when task cancelled
918       */
919      public void testCancelledForkQuietlyJoin() {
920 <       ForkJoinTask a =  new CheckedFJTask() {
921 <            public void realCompute() {
922 <                CCF f = new LCCF(null, 8);
920 >        ForkJoinTask a = new CheckedRecursiveAction() {
921 >            protected void realCompute() {
922 >                CCF f = new LCCF(8);
923                  assertTrue(f.cancel(true));
924                  assertSame(f, f.fork());
925                  f.quietlyJoin();
# Line 842 | Line 933 | public class CountedCompleterTest extend
933       */
934      public void testGetPool() {
935          final ForkJoinPool mainPool = mainPool();
936 <       ForkJoinTask a =  new CheckedFJTask() {
937 <            public void realCompute() {
936 >        ForkJoinTask a = new CheckedRecursiveAction() {
937 >            protected void realCompute() {
938                  assertSame(mainPool, getPool());
939              }};
940          testInvokeOnPool(mainPool, a);
# Line 853 | Line 944 | public class CountedCompleterTest extend
944       * getPool of non-FJ task returns null
945       */
946      public void testGetPool2() {
947 <       ForkJoinTask a =  new CheckedFJTask() {
948 <            public void realCompute() {
947 >        ForkJoinTask a = new CheckedRecursiveAction() {
948 >            protected void realCompute() {
949                  assertNull(getPool());
950              }};
951          assertNull(a.invoke());
# Line 864 | Line 955 | public class CountedCompleterTest extend
955       * inForkJoinPool of executing task returns true
956       */
957      public void testInForkJoinPool() {
958 <       ForkJoinTask a =  new CheckedFJTask() {
959 <            public void realCompute() {
958 >        ForkJoinTask a = new CheckedRecursiveAction() {
959 >            protected void realCompute() {
960                  assertTrue(inForkJoinPool());
961              }};
962          testInvokeOnPool(mainPool(), a);
# Line 875 | Line 966 | public class CountedCompleterTest extend
966       * inForkJoinPool of non-FJ task returns false
967       */
968      public void testInForkJoinPool2() {
969 <       ForkJoinTask a =  new CheckedFJTask() {
970 <            public void realCompute() {
969 >        ForkJoinTask a = new CheckedRecursiveAction() {
970 >            protected void realCompute() {
971                  assertFalse(inForkJoinPool());
972              }};
973          assertNull(a.invoke());
# Line 886 | Line 977 | public class CountedCompleterTest extend
977       * setRawResult(null) succeeds
978       */
979      public void testSetRawResult() {
980 <       ForkJoinTask a =  new CheckedFJTask() {
981 <            public void realCompute() {
980 >        ForkJoinTask a = new CheckedRecursiveAction() {
981 >            protected void realCompute() {
982                  setRawResult(null);
983                  assertNull(getRawResult());
984              }};
# Line 898 | Line 989 | public class CountedCompleterTest extend
989       * invoke task throws exception after invoking completeExceptionally
990       */
991      public void testCompleteExceptionally2() {
992 <       ForkJoinTask a =  new CheckedFJTask() {
993 <            public void realCompute() {
994 <                CCF f = new LCCF(null, 8);
995 <                f.completeExceptionally(new FJException());
996 <                try {
997 <                    f.invoke();
998 <                    shouldThrow();
999 <                } catch (FJException success) {
909 <                    checkCompletedAbnormally(f, success);
910 <                }
992 >        ForkJoinTask a = new CheckedRecursiveAction() {
993 >            protected void realCompute() {
994 >                CCF n = new LCCF(8);
995 >                CCF f = new LCCF(n, 8);
996 >                FJException ex = new FJException();
997 >                f.completeExceptionally(ex);
998 >                f.checkCompletedExceptionally(ex);
999 >                n.checkCompletedExceptionally(ex);
1000              }};
1001          testInvokeOnPool(mainPool(), a);
1002      }
# Line 916 | Line 1005 | public class CountedCompleterTest extend
1005       * invokeAll(t1, t2) invokes all task arguments
1006       */
1007      public void testInvokeAll2() {
1008 <       ForkJoinTask a =  new CheckedFJTask() {
1009 <            public void realCompute() {
1010 <                CCF f = new LCCF(null, 8);
1011 <                CCF g = new LCCF(null, 9);
1008 >        ForkJoinTask a = new CheckedRecursiveAction() {
1009 >            protected void realCompute() {
1010 >                CCF f = new LCCF(8);
1011 >                CCF g = new LCCF(9);
1012                  invokeAll(f, g);
1013                  assertEquals(21, f.number);
1014                  assertEquals(34, g.number);
# Line 933 | Line 1022 | public class CountedCompleterTest extend
1022       * invokeAll(tasks) with 1 argument invokes task
1023       */
1024      public void testInvokeAll1() {
1025 <       ForkJoinTask a =  new CheckedFJTask() {
1026 <            public void realCompute() {
1027 <                CCF f = new LCCF(null, 8);
1025 >        ForkJoinTask a = new CheckedRecursiveAction() {
1026 >            protected void realCompute() {
1027 >                CCF f = new LCCF(8);
1028                  invokeAll(f);
1029                  checkCompletedNormally(f);
1030                  assertEquals(21, f.number);
# Line 947 | Line 1036 | public class CountedCompleterTest extend
1036       * invokeAll(tasks) with > 2 argument invokes tasks
1037       */
1038      public void testInvokeAll3() {
1039 <       ForkJoinTask a =  new CheckedFJTask() {
1040 <            public void realCompute() {
1041 <                CCF f = new LCCF(null, 8);
1042 <                CCF g = new LCCF(null, 9);
1043 <                CCF h = new LCCF(null, 7);
1039 >        ForkJoinTask a = new CheckedRecursiveAction() {
1040 >            protected void realCompute() {
1041 >                CCF f = new LCCF(8);
1042 >                CCF g = new LCCF(9);
1043 >                CCF h = new LCCF(7);
1044                  invokeAll(f, g, h);
1045                  assertEquals(21, f.number);
1046                  assertEquals(34, g.number);
# Line 967 | Line 1056 | public class CountedCompleterTest extend
1056       * invokeAll(collection) invokes all tasks in the collection
1057       */
1058      public void testInvokeAllCollection() {
1059 <       ForkJoinTask a =  new CheckedFJTask() {
1060 <            public void realCompute() {
1061 <                CCF f = new LCCF(null, 8);
1062 <                CCF g = new LCCF(null, 9);
1063 <                CCF h = new LCCF(null, 7);
1059 >        ForkJoinTask a = new CheckedRecursiveAction() {
1060 >            protected void realCompute() {
1061 >                CCF f = new LCCF(8);
1062 >                CCF g = new LCCF(9);
1063 >                CCF h = new LCCF(7);
1064                  HashSet set = new HashSet();
1065                  set.add(f);
1066                  set.add(g);
# Line 991 | Line 1080 | public class CountedCompleterTest extend
1080       * invokeAll(tasks) with any null task throws NPE
1081       */
1082      public void testInvokeAllNPE() {
1083 <       ForkJoinTask a =  new CheckedFJTask() {
1084 <            public void realCompute() {
1085 <                CCF f = new LCCF(null, 8);
1086 <                CCF g = new LCCF(null, 9);
1083 >        ForkJoinTask a = new CheckedRecursiveAction() {
1084 >            protected void realCompute() {
1085 >                CCF f = new LCCF(8);
1086 >                CCF g = new LCCF(9);
1087                  CCF h = null;
1088                  try {
1089                      invokeAll(f, g, h);
# Line 1008 | Line 1097 | public class CountedCompleterTest extend
1097       * invokeAll(t1, t2) throw exception if any task does
1098       */
1099      public void testAbnormalInvokeAll2() {
1100 <       ForkJoinTask a =  new CheckedFJTask() {
1101 <            public void realCompute() {
1102 <                CCF f = new LCCF(null, 8);
1103 <                FailingCCF g = new LFCCF(null, 9);
1100 >        ForkJoinTask a = new CheckedRecursiveAction() {
1101 >            protected void realCompute() {
1102 >                CCF f = new LCCF(8);
1103 >                FailingCCF g = new LFCCF(9);
1104                  try {
1105                      invokeAll(f, g);
1106                      shouldThrow();
# Line 1026 | Line 1115 | public class CountedCompleterTest extend
1115       * invokeAll(tasks) with 1 argument throws exception if task does
1116       */
1117      public void testAbnormalInvokeAll1() {
1118 <       ForkJoinTask a =  new CheckedFJTask() {
1119 <            public void realCompute() {
1120 <                FailingCCF g = new LFCCF(null, 9);
1118 >        ForkJoinTask a = new CheckedRecursiveAction() {
1119 >            protected void realCompute() {
1120 >                FailingCCF g = new LFCCF(9);
1121                  try {
1122                      invokeAll(g);
1123                      shouldThrow();
# Line 1043 | Line 1132 | public class CountedCompleterTest extend
1132       * invokeAll(tasks) with > 2 argument throws exception if any task does
1133       */
1134      public void testAbnormalInvokeAll3() {
1135 <       ForkJoinTask a =  new CheckedFJTask() {
1136 <            public void realCompute() {
1137 <                CCF f = new LCCF(null, 8);
1138 <                FailingCCF g = new LFCCF(null, 9);
1139 <                CCF h = new LCCF(null, 7);
1135 >        ForkJoinTask a = new CheckedRecursiveAction() {
1136 >            protected void realCompute() {
1137 >                CCF f = new LCCF(8);
1138 >                FailingCCF g = new LFCCF(9);
1139 >                CCF h = new LCCF(7);
1140                  try {
1141                      invokeAll(f, g, h);
1142                      shouldThrow();
# Line 1059 | Line 1148 | public class CountedCompleterTest extend
1148      }
1149  
1150      /**
1151 <     * invokeAll(collection)  throws exception if any task does
1151 >     * invokeAll(collection) throws exception if any task does
1152       */
1153      public void testAbnormalInvokeAllCollection() {
1154 <       ForkJoinTask a =  new CheckedFJTask() {
1155 <            public void realCompute() {
1156 <                FailingCCF f = new LFCCF(null, 8);
1157 <                CCF g = new LCCF(null, 9);
1158 <                CCF h = new LCCF(null, 7);
1154 >        ForkJoinTask a = new CheckedRecursiveAction() {
1155 >            protected void realCompute() {
1156 >                FailingCCF f = new LFCCF(8);
1157 >                CCF g = new LCCF(9);
1158 >                CCF h = new LCCF(7);
1159                  HashSet set = new HashSet();
1160                  set.add(f);
1161                  set.add(g);
# Line 1086 | Line 1175 | public class CountedCompleterTest extend
1175       * and suppresses execution
1176       */
1177      public void testTryUnfork() {
1178 <       ForkJoinTask a =  new CheckedFJTask() {
1179 <            public void realCompute() {
1180 <                CCF g = new LCCF(null, 9);
1178 >        ForkJoinTask a = new CheckedRecursiveAction() {
1179 >            protected void realCompute() {
1180 >                CCF g = new LCCF(9);
1181                  assertSame(g, g.fork());
1182 <                CCF f = new LCCF(null, 8);
1182 >                CCF f = new LCCF(8);
1183                  assertSame(f, f.fork());
1184                  assertTrue(f.tryUnfork());
1185                  helpQuiesce();
# Line 1105 | Line 1194 | public class CountedCompleterTest extend
1194       * there are more tasks than threads
1195       */
1196      public void testGetSurplusQueuedTaskCount() {
1197 <       ForkJoinTask a =  new CheckedFJTask() {
1198 <            public void realCompute() {
1199 <                CCF h = new LCCF(null, 7);
1197 >        ForkJoinTask a = new CheckedRecursiveAction() {
1198 >            protected void realCompute() {
1199 >                CCF h = new LCCF(7);
1200                  assertSame(h, h.fork());
1201 <                CCF g = new LCCF(null, 9);
1201 >                CCF g = new LCCF(9);
1202                  assertSame(g, g.fork());
1203 <                CCF f = new LCCF(null, 8);
1203 >                CCF f = new LCCF(8);
1204                  assertSame(f, f.fork());
1205                  assertTrue(getSurplusQueuedTaskCount() > 0);
1206                  helpQuiesce();
# Line 1127 | Line 1216 | public class CountedCompleterTest extend
1216       * peekNextLocalTask returns most recent unexecuted task.
1217       */
1218      public void testPeekNextLocalTask() {
1219 <       ForkJoinTask a =  new CheckedFJTask() {
1220 <            public void realCompute() {
1221 <                CCF g = new LCCF(null, 9);
1219 >        ForkJoinTask a = new CheckedRecursiveAction() {
1220 >            protected void realCompute() {
1221 >                CCF g = new LCCF(9);
1222                  assertSame(g, g.fork());
1223 <                CCF f = new LCCF(null, 8);
1223 >                CCF f = new LCCF(8);
1224                  assertSame(f, f.fork());
1225                  assertSame(f, peekNextLocalTask());
1226                  assertNull(f.join());
# Line 1147 | Line 1236 | public class CountedCompleterTest extend
1236       * executing it
1237       */
1238      public void testPollNextLocalTask() {
1239 <       ForkJoinTask a =  new CheckedFJTask() {
1240 <            public void realCompute() {
1241 <                CCF g = new LCCF(null, 9);
1239 >        ForkJoinTask a = new CheckedRecursiveAction() {
1240 >            protected void realCompute() {
1241 >                CCF g = new LCCF(9);
1242                  assertSame(g, g.fork());
1243 <                CCF f = new LCCF(null, 8);
1243 >                CCF f = new LCCF(8);
1244                  assertSame(f, f.fork());
1245                  assertSame(f, pollNextLocalTask());
1246                  helpQuiesce();
# Line 1166 | Line 1255 | public class CountedCompleterTest extend
1255       * pollTask returns an unexecuted task without executing it
1256       */
1257      public void testPollTask() {
1258 <       ForkJoinTask a =  new CheckedFJTask() {
1259 <            public void realCompute() {
1260 <                CCF g = new LCCF(null, 9);
1258 >        ForkJoinTask a = new CheckedRecursiveAction() {
1259 >            protected void realCompute() {
1260 >                CCF g = new LCCF(9);
1261                  assertSame(g, g.fork());
1262 <                CCF f = new LCCF(null, 8);
1262 >                CCF f = new LCCF(8);
1263                  assertSame(f, f.fork());
1264                  assertSame(f, pollTask());
1265                  helpQuiesce();
# Line 1184 | Line 1273 | public class CountedCompleterTest extend
1273       * peekNextLocalTask returns least recent unexecuted task in async mode
1274       */
1275      public void testPeekNextLocalTaskAsync() {
1276 <       ForkJoinTask a =  new CheckedFJTask() {
1277 <            public void realCompute() {
1278 <                CCF g = new LCCF(null, 9);
1276 >        ForkJoinTask a = new CheckedRecursiveAction() {
1277 >            protected void realCompute() {
1278 >                CCF g = new LCCF(9);
1279                  assertSame(g, g.fork());
1280 <                CCF f = new LCCF(null, 8);
1280 >                CCF f = new LCCF(8);
1281                  assertSame(f, f.fork());
1282                  assertSame(g, peekNextLocalTask());
1283                  assertNull(f.join());
# Line 1205 | Line 1294 | public class CountedCompleterTest extend
1294       * executing it, in async mode
1295       */
1296      public void testPollNextLocalTaskAsync() {
1297 <       ForkJoinTask a =  new CheckedFJTask() {
1298 <            public void realCompute() {
1299 <                CCF g = new LCCF(null, 9);
1297 >        ForkJoinTask a = new CheckedRecursiveAction() {
1298 >            protected void realCompute() {
1299 >                CCF g = new LCCF(9);
1300                  assertSame(g, g.fork());
1301 <                CCF f = new LCCF(null, 8);
1301 >                CCF f = new LCCF(8);
1302                  assertSame(f, f.fork());
1303                  assertSame(g, pollNextLocalTask());
1304                  helpQuiesce();
# Line 1225 | Line 1314 | public class CountedCompleterTest extend
1314       * async mode
1315       */
1316      public void testPollTaskAsync() {
1317 <       ForkJoinTask a =  new CheckedFJTask() {
1318 <            public void realCompute() {
1319 <                CCF g = new LCCF(null, 9);
1317 >        ForkJoinTask a = new CheckedRecursiveAction() {
1318 >            protected void realCompute() {
1319 >                CCF g = new LCCF(9);
1320                  assertSame(g, g.fork());
1321 <                CCF f = new LCCF(null, 8);
1321 >                CCF f = new LCCF(8);
1322                  assertSame(f, f.fork());
1323                  assertSame(g, pollTask());
1324                  helpQuiesce();
# Line 1248 | Line 1337 | public class CountedCompleterTest extend
1337       * completed tasks; getRawResult returns null.
1338       */
1339      public void testInvokeSingleton() {
1340 <       ForkJoinTask a =  new CheckedFJTask() {
1341 <            public void realCompute() {
1342 <                CCF f = new LCCF(null, 8);
1340 >        ForkJoinTask a = new CheckedRecursiveAction() {
1341 >            protected void realCompute() {
1342 >                CCF f = new LCCF(8);
1343                  assertNull(f.invoke());
1344                  assertEquals(21, f.number);
1345                  checkCompletedNormally(f);
# Line 1264 | Line 1353 | public class CountedCompleterTest extend
1353       * completed tasks
1354       */
1355      public void testQuietlyInvokeSingleton() {
1356 <       ForkJoinTask a =  new CheckedFJTask() {
1357 <            public void realCompute() {
1358 <                CCF f = new LCCF(null, 8);
1356 >        ForkJoinTask a = new CheckedRecursiveAction() {
1357 >            protected void realCompute() {
1358 >                CCF f = new LCCF(8);
1359                  f.quietlyInvoke();
1360                  assertEquals(21, f.number);
1361                  checkCompletedNormally(f);
# Line 1278 | Line 1367 | public class CountedCompleterTest extend
1367       * join of a forked task returns when task completes
1368       */
1369      public void testForkJoinSingleton() {
1370 <       ForkJoinTask a =  new CheckedFJTask() {
1371 <            public void realCompute() {
1372 <                CCF f = new LCCF(null, 8);
1370 >        ForkJoinTask a = new CheckedRecursiveAction() {
1371 >            protected void realCompute() {
1372 >                CCF f = new LCCF(8);
1373                  assertSame(f, f.fork());
1374                  assertNull(f.join());
1375                  assertEquals(21, f.number);
# Line 1293 | Line 1382 | public class CountedCompleterTest extend
1382       * get of a forked task returns when task completes
1383       */
1384      public void testForkGetSingleton() {
1385 <       ForkJoinTask a =  new CheckedFJTask() {
1386 <            public void realCompute() throws Exception {
1387 <                CCF f = new LCCF(null, 8);
1385 >        ForkJoinTask a = new CheckedRecursiveAction() {
1386 >            protected void realCompute() throws Exception {
1387 >                CCF f = new LCCF(8);
1388                  assertSame(f, f.fork());
1389                  assertNull(f.get());
1390                  assertEquals(21, f.number);
# Line 1308 | Line 1397 | public class CountedCompleterTest extend
1397       * timed get of a forked task returns when task completes
1398       */
1399      public void testForkTimedGetSingleton() {
1400 <       ForkJoinTask a =  new CheckedFJTask() {
1401 <            public void realCompute() throws Exception {
1402 <                CCF f = new LCCF(null, 8);
1400 >        ForkJoinTask a = new CheckedRecursiveAction() {
1401 >            protected void realCompute() throws Exception {
1402 >                CCF f = new LCCF(8);
1403                  assertSame(f, f.fork());
1404                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1405                  assertEquals(21, f.number);
# Line 1323 | Line 1412 | public class CountedCompleterTest extend
1412       * timed get with null time unit throws NPE
1413       */
1414      public void testForkTimedGetNPESingleton() {
1415 <       ForkJoinTask a =  new CheckedFJTask() {
1416 <            public void realCompute() throws Exception {
1417 <                CCF f = new LCCF(null, 8);
1415 >        ForkJoinTask a = new CheckedRecursiveAction() {
1416 >            protected void realCompute() throws Exception {
1417 >                CCF f = new LCCF(8);
1418                  assertSame(f, f.fork());
1419                  try {
1420                      f.get(5L, null);
# Line 1339 | Line 1428 | public class CountedCompleterTest extend
1428       * quietlyJoin of a forked task returns when task completes
1429       */
1430      public void testForkQuietlyJoinSingleton() {
1431 <       ForkJoinTask a =  new CheckedFJTask() {
1432 <            public void realCompute() {
1433 <                CCF f = new LCCF(null, 8);
1431 >        ForkJoinTask a = new CheckedRecursiveAction() {
1432 >            protected void realCompute() {
1433 >                CCF f = new LCCF(8);
1434                  assertSame(f, f.fork());
1435                  f.quietlyJoin();
1436                  assertEquals(21, f.number);
# Line 1355 | Line 1444 | public class CountedCompleterTest extend
1444       * getQueuedTaskCount returns 0 when quiescent
1445       */
1446      public void testForkHelpQuiesceSingleton() {
1447 <       ForkJoinTask a =  new CheckedFJTask() {
1448 <            public void realCompute() {
1449 <                CCF f = new LCCF(null, 8);
1447 >        ForkJoinTask a = new CheckedRecursiveAction() {
1448 >            protected void realCompute() {
1449 >                CCF f = new LCCF(8);
1450                  assertSame(f, f.fork());
1451                  helpQuiesce();
1452                  assertEquals(0, getQueuedTaskCount());
# Line 1371 | Line 1460 | public class CountedCompleterTest extend
1460       * invoke task throws exception when task completes abnormally
1461       */
1462      public void testAbnormalInvokeSingleton() {
1463 <       ForkJoinTask a =  new CheckedFJTask() {
1464 <            public void realCompute() {
1465 <                FailingCCF f = new LFCCF(null, 8);
1463 >        ForkJoinTask a = new CheckedRecursiveAction() {
1464 >            protected void realCompute() {
1465 >                FailingCCF f = new LFCCF(8);
1466                  try {
1467                      f.invoke();
1468                      shouldThrow();
# Line 1388 | Line 1477 | public class CountedCompleterTest extend
1477       * quietlyInvoke task returns when task completes abnormally
1478       */
1479      public void testAbnormalQuietlyInvokeSingleton() {
1480 <       ForkJoinTask a =  new CheckedFJTask() {
1481 <            public void realCompute() {
1482 <                FailingCCF f = new LFCCF(null, 8);
1480 >        ForkJoinTask a = new CheckedRecursiveAction() {
1481 >            protected void realCompute() {
1482 >                FailingCCF f = new LFCCF(8);
1483                  f.quietlyInvoke();
1484                  assertTrue(f.getException() instanceof FJException);
1485                  checkCompletedAbnormally(f, f.getException());
# Line 1402 | Line 1491 | public class CountedCompleterTest extend
1491       * join of a forked task throws exception when task completes abnormally
1492       */
1493      public void testAbnormalForkJoinSingleton() {
1494 <       ForkJoinTask a =  new CheckedFJTask() {
1495 <            public void realCompute() {
1496 <                FailingCCF f = new LFCCF(null, 8);
1494 >        ForkJoinTask a = new CheckedRecursiveAction() {
1495 >            protected void realCompute() {
1496 >                FailingCCF f = new LFCCF(8);
1497                  assertSame(f, f.fork());
1498                  try {
1499                      f.join();
# Line 1420 | Line 1509 | public class CountedCompleterTest extend
1509       * get of a forked task throws exception when task completes abnormally
1510       */
1511      public void testAbnormalForkGetSingleton() {
1512 <       ForkJoinTask a =  new CheckedFJTask() {
1513 <            public void realCompute() throws Exception {
1514 <                FailingCCF f = new LFCCF(null, 8);
1512 >        ForkJoinTask a = new CheckedRecursiveAction() {
1513 >            protected void realCompute() throws Exception {
1514 >                FailingCCF f = new LFCCF(8);
1515                  assertSame(f, f.fork());
1516                  try {
1517                      f.get();
# Line 1440 | Line 1529 | public class CountedCompleterTest extend
1529       * timed get of a forked task throws exception when task completes abnormally
1530       */
1531      public void testAbnormalForkTimedGetSingleton() {
1532 <       ForkJoinTask a =  new CheckedFJTask() {
1533 <            public void realCompute() throws Exception {
1534 <                FailingCCF f = new LFCCF(null, 8);
1532 >        ForkJoinTask a = new CheckedRecursiveAction() {
1533 >            protected void realCompute() throws Exception {
1534 >                FailingCCF f = new LFCCF(8);
1535                  assertSame(f, f.fork());
1536                  try {
1537                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1460 | Line 1549 | public class CountedCompleterTest extend
1549       * quietlyJoin of a forked task returns when task completes abnormally
1550       */
1551      public void testAbnormalForkQuietlyJoinSingleton() {
1552 <       ForkJoinTask a =  new CheckedFJTask() {
1553 <            public void realCompute() {
1554 <                FailingCCF f = new LFCCF(null, 8);
1552 >        ForkJoinTask a = new CheckedRecursiveAction() {
1553 >            protected void realCompute() {
1554 >                FailingCCF f = new LFCCF(8);
1555                  assertSame(f, f.fork());
1556                  f.quietlyJoin();
1557                  assertTrue(f.getException() instanceof FJException);
# Line 1475 | Line 1564 | public class CountedCompleterTest extend
1564       * invoke task throws exception when task cancelled
1565       */
1566      public void testCancelledInvokeSingleton() {
1567 <       ForkJoinTask a =  new CheckedFJTask() {
1568 <            public void realCompute() {
1569 <                CCF f = new LCCF(null, 8);
1567 >        ForkJoinTask a = new CheckedRecursiveAction() {
1568 >            protected void realCompute() {
1569 >                CCF f = new LCCF(8);
1570                  assertTrue(f.cancel(true));
1571                  try {
1572                      f.invoke();
# Line 1493 | Line 1582 | public class CountedCompleterTest extend
1582       * join of a forked task throws exception when task cancelled
1583       */
1584      public void testCancelledForkJoinSingleton() {
1585 <       ForkJoinTask a =  new CheckedFJTask() {
1586 <            public void realCompute() {
1587 <                CCF f = new LCCF(null, 8);
1585 >        ForkJoinTask a = new CheckedRecursiveAction() {
1586 >            protected void realCompute() {
1587 >                CCF f = new LCCF(8);
1588                  assertTrue(f.cancel(true));
1589                  assertSame(f, f.fork());
1590                  try {
# Line 1512 | Line 1601 | public class CountedCompleterTest extend
1601       * get of a forked task throws exception when task cancelled
1602       */
1603      public void testCancelledForkGetSingleton() {
1604 <       ForkJoinTask a =  new CheckedFJTask() {
1605 <            public void realCompute() throws Exception {
1606 <                CCF f = new LCCF(null, 8);
1604 >        ForkJoinTask a = new CheckedRecursiveAction() {
1605 >            protected void realCompute() throws Exception {
1606 >                CCF f = new LCCF(8);
1607                  assertTrue(f.cancel(true));
1608                  assertSame(f, f.fork());
1609                  try {
# Line 1531 | Line 1620 | public class CountedCompleterTest extend
1620       * timed get of a forked task throws exception when task cancelled
1621       */
1622      public void testCancelledForkTimedGetSingleton() throws Exception {
1623 <       ForkJoinTask a =  new CheckedFJTask() {
1624 <            public void realCompute() throws Exception {
1625 <                CCF f = new LCCF(null, 8);
1623 >        ForkJoinTask a = new CheckedRecursiveAction() {
1624 >            protected void realCompute() throws Exception {
1625 >                CCF f = new LCCF(8);
1626                  assertTrue(f.cancel(true));
1627                  assertSame(f, f.fork());
1628                  try {
# Line 1550 | Line 1639 | public class CountedCompleterTest extend
1639       * quietlyJoin of a forked task returns when task cancelled
1640       */
1641      public void testCancelledForkQuietlyJoinSingleton() {
1642 <       ForkJoinTask a =  new CheckedFJTask() {
1643 <            public void realCompute() {
1644 <                CCF f = new LCCF(null, 8);
1642 >        ForkJoinTask a = new CheckedRecursiveAction() {
1643 >            protected void realCompute() {
1644 >                CCF f = new LCCF(8);
1645                  assertTrue(f.cancel(true));
1646                  assertSame(f, f.fork());
1647                  f.quietlyJoin();
# Line 1565 | Line 1654 | public class CountedCompleterTest extend
1654       * invoke task throws exception after invoking completeExceptionally
1655       */
1656      public void testCompleteExceptionallySingleton() {
1657 <       ForkJoinTask a =  new CheckedFJTask() {
1658 <            public void realCompute() {
1659 <                CCF f = new LCCF(null, 8);
1660 <                f.completeExceptionally(new FJException());
1661 <                try {
1662 <                    f.invoke();
1663 <                    shouldThrow();
1664 <                } catch (FJException success) {
1576 <                    checkCompletedAbnormally(f, success);
1577 <                }
1657 >        ForkJoinTask a = new CheckedRecursiveAction() {
1658 >            protected void realCompute() {
1659 >                CCF n = new LCCF(8);
1660 >                CCF f = new LCCF(n, 8);
1661 >                FJException ex = new FJException();
1662 >                f.completeExceptionally(ex);
1663 >                f.checkCompletedExceptionally(ex);
1664 >                n.checkCompletedExceptionally(ex);
1665              }};
1666          testInvokeOnPool(singletonPool(), a);
1667      }
# Line 1583 | Line 1670 | public class CountedCompleterTest extend
1670       * invokeAll(t1, t2) invokes all task arguments
1671       */
1672      public void testInvokeAll2Singleton() {
1673 <       ForkJoinTask a =  new CheckedFJTask() {
1674 <            public void realCompute() {
1675 <                CCF f = new LCCF(null, 8);
1676 <                CCF g = new LCCF(null, 9);
1673 >        ForkJoinTask a = new CheckedRecursiveAction() {
1674 >            protected void realCompute() {
1675 >                CCF f = new LCCF(8);
1676 >                CCF g = new LCCF(9);
1677                  invokeAll(f, g);
1678                  assertEquals(21, f.number);
1679                  assertEquals(34, g.number);
# Line 1600 | Line 1687 | public class CountedCompleterTest extend
1687       * invokeAll(tasks) with 1 argument invokes task
1688       */
1689      public void testInvokeAll1Singleton() {
1690 <       ForkJoinTask a =  new CheckedFJTask() {
1691 <            public void realCompute() {
1692 <                CCF f = new LCCF(null, 8);
1690 >        ForkJoinTask a = new CheckedRecursiveAction() {
1691 >            protected void realCompute() {
1692 >                CCF f = new LCCF(8);
1693                  invokeAll(f);
1694                  checkCompletedNormally(f);
1695                  assertEquals(21, f.number);
# Line 1614 | Line 1701 | public class CountedCompleterTest extend
1701       * invokeAll(tasks) with > 2 argument invokes tasks
1702       */
1703      public void testInvokeAll3Singleton() {
1704 <       ForkJoinTask a =  new CheckedFJTask() {
1705 <            public void realCompute() {
1706 <                CCF f = new LCCF(null, 8);
1707 <                CCF g = new LCCF(null, 9);
1708 <                CCF h = new LCCF(null, 7);
1704 >        ForkJoinTask a = new CheckedRecursiveAction() {
1705 >            protected void realCompute() {
1706 >                CCF f = new LCCF(8);
1707 >                CCF g = new LCCF(9);
1708 >                CCF h = new LCCF(7);
1709                  invokeAll(f, g, h);
1710                  assertEquals(21, f.number);
1711                  assertEquals(34, g.number);
# Line 1634 | Line 1721 | public class CountedCompleterTest extend
1721       * invokeAll(collection) invokes all tasks in the collection
1722       */
1723      public void testInvokeAllCollectionSingleton() {
1724 <       ForkJoinTask a =  new CheckedFJTask() {
1725 <            public void realCompute() {
1726 <                CCF f = new LCCF(null, 8);
1727 <                CCF g = new LCCF(null, 9);
1728 <                CCF h = new LCCF(null, 7);
1724 >        ForkJoinTask a = new CheckedRecursiveAction() {
1725 >            protected void realCompute() {
1726 >                CCF f = new LCCF(8);
1727 >                CCF g = new LCCF(9);
1728 >                CCF h = new LCCF(7);
1729                  HashSet set = new HashSet();
1730                  set.add(f);
1731                  set.add(g);
# Line 1658 | Line 1745 | public class CountedCompleterTest extend
1745       * invokeAll(tasks) with any null task throws NPE
1746       */
1747      public void testInvokeAllNPESingleton() {
1748 <       ForkJoinTask a =  new CheckedFJTask() {
1749 <            public void realCompute() {
1750 <                CCF f = new LCCF(null, 8);
1751 <                CCF g = new LCCF(null, 9);
1748 >        ForkJoinTask a = new CheckedRecursiveAction() {
1749 >            protected void realCompute() {
1750 >                CCF f = new LCCF(8);
1751 >                CCF g = new LCCF(9);
1752                  CCF h = null;
1753                  try {
1754                      invokeAll(f, g, h);
# Line 1675 | Line 1762 | public class CountedCompleterTest extend
1762       * invokeAll(t1, t2) throw exception if any task does
1763       */
1764      public void testAbnormalInvokeAll2Singleton() {
1765 <       ForkJoinTask a =  new CheckedFJTask() {
1766 <            public void realCompute() {
1767 <                CCF f = new LCCF(null, 8);
1768 <                FailingCCF g = new LFCCF(null, 9);
1765 >        ForkJoinTask a = new CheckedRecursiveAction() {
1766 >            protected void realCompute() {
1767 >                CCF f = new LCCF(8);
1768 >                FailingCCF g = new LFCCF(9);
1769                  try {
1770                      invokeAll(f, g);
1771                      shouldThrow();
# Line 1693 | Line 1780 | public class CountedCompleterTest extend
1780       * invokeAll(tasks) with 1 argument throws exception if task does
1781       */
1782      public void testAbnormalInvokeAll1Singleton() {
1783 <       ForkJoinTask a =  new CheckedFJTask() {
1784 <            public void realCompute() {
1785 <                FailingCCF g = new LFCCF(null, 9);
1783 >        ForkJoinTask a = new CheckedRecursiveAction() {
1784 >            protected void realCompute() {
1785 >                FailingCCF g = new LFCCF(9);
1786                  try {
1787                      invokeAll(g);
1788                      shouldThrow();
# Line 1710 | Line 1797 | public class CountedCompleterTest extend
1797       * invokeAll(tasks) with > 2 argument throws exception if any task does
1798       */
1799      public void testAbnormalInvokeAll3Singleton() {
1800 <       ForkJoinTask a =  new CheckedFJTask() {
1801 <            public void realCompute() {
1802 <                CCF f = new LCCF(null, 8);
1803 <                FailingCCF g = new LFCCF(null, 9);
1804 <                CCF h = new LCCF(null, 7);
1800 >        ForkJoinTask a = new CheckedRecursiveAction() {
1801 >            protected void realCompute() {
1802 >                CCF f = new LCCF(8);
1803 >                FailingCCF g = new LFCCF(9);
1804 >                CCF h = new LCCF(7);
1805                  try {
1806                      invokeAll(f, g, h);
1807                      shouldThrow();
# Line 1726 | Line 1813 | public class CountedCompleterTest extend
1813      }
1814  
1815      /**
1816 <     * invokeAll(collection)  throws exception if any task does
1816 >     * invokeAll(collection) throws exception if any task does
1817       */
1818      public void testAbnormalInvokeAllCollectionSingleton() {
1819 <       ForkJoinTask a =  new CheckedFJTask() {
1820 <            public void realCompute() {
1821 <                FailingCCF f = new LFCCF(null, 8);
1822 <                CCF g = new LCCF(null, 9);
1823 <                CCF h = new LCCF(null, 7);
1819 >        ForkJoinTask a = new CheckedRecursiveAction() {
1820 >            protected void realCompute() {
1821 >                FailingCCF f = new LFCCF(8);
1822 >                CCF g = new LCCF(9);
1823 >                CCF h = new LCCF(7);
1824                  HashSet set = new HashSet();
1825                  set.add(f);
1826                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines