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.7 by jsr166, Mon Jun 3 18:20:05 2013 UTC vs.
Revision 1.27 by jsr166, Sun Oct 18 19:33:21 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 47 | 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 63 | Line 65 | public class CountedCompleterTest extend
65              assertFalse(a.isCancelled());
66              assertNull(a.getException());
67              assertNull(a.getRawResult());
66        } finally {
67            joinPool(pool);
68          }
69      }
70  
# Line 83 | Line 83 | public class CountedCompleterTest extend
83          } catch (Throwable fail) { threadUnexpectedException(fail); }
84      }
85  
86 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
87 <        checkCompletedNormally(a, null);
88 <    }
89 <
90 <    <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 140 | 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 178 | 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 196 | 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());
231 <        assertTrue(a.isCompletedNormally());
232 <        assertFalse(a.isCompletedAbnormally());
233 <        assertFalse(a.isCancelled());
234 <        assertNull(a.getException());
235 <        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 >        int[] vals = {
339 >             -1, 0, 1,
340 >             Integer.MIN_VALUE,
341 >             Integer.MAX_VALUE,
342 >        };
343 >        for (int val : vals) {
344 >            a.setPendingCount(val);
345 >            assertEquals(val, a.getPendingCount());
346 >        }
347      }
348  
349      /**
350       * addToPendingCount adds to the reported pending count
351       */
352      public void testAddToPendingCount() {
353 <        NoopCountedCompleter a = new NoopCountedCompleter();
353 >        NoopCC a = new NoopCC();
354          assertEquals(0, a.getPendingCount());
355          a.addToPendingCount(1);
356          assertEquals(1, a.getPendingCount());
357          a.addToPendingCount(27);
358          assertEquals(28, a.getPendingCount());
359 +        a.addToPendingCount(-28);
360 +        assertEquals(0, a.getPendingCount());
361      }
362  
363      /**
364       * decrementPendingCountUnlessZero decrements reported pending
365       * count unless zero
366       */
367 <    public void testDecrementPendingCount() {
368 <        NoopCountedCompleter a = new NoopCountedCompleter();
369 <        assertEquals(0, a.getPendingCount());
370 <        a.addToPendingCount(1);
367 >    public void testDecrementPendingCountUnlessZero() {
368 >        NoopCC a = new NoopCC(null, 2);
369 >        assertEquals(2, a.getPendingCount());
370 >        assertEquals(2, a.decrementPendingCountUnlessZero());
371          assertEquals(1, a.getPendingCount());
372 <        a.decrementPendingCountUnlessZero();
372 >        assertEquals(1, a.decrementPendingCountUnlessZero());
373          assertEquals(0, a.getPendingCount());
374 <        a.decrementPendingCountUnlessZero();
374 >        assertEquals(0, a.decrementPendingCountUnlessZero());
375 >        assertEquals(0, a.getPendingCount());
376 >        a.setPendingCount(-1);
377 >        assertEquals(-1, a.decrementPendingCountUnlessZero());
378 >        assertEquals(-2, a.getPendingCount());
379 >    }
380 >
381 >    /**
382 >     * compareAndSetPendingCount compares and sets the reported
383 >     * pending count
384 >     */
385 >    public void testCompareAndSetPendingCount() {
386 >        NoopCC a = new NoopCC();
387          assertEquals(0, a.getPendingCount());
388 +        assertTrue(a.compareAndSetPendingCount(0, 1));
389 +        assertEquals(1, a.getPendingCount());
390 +        assertTrue(a.compareAndSetPendingCount(1, 2));
391 +        assertEquals(2, a.getPendingCount());
392 +        assertFalse(a.compareAndSetPendingCount(1, 3));
393 +        assertEquals(2, a.getPendingCount());
394      }
395  
396      /**
397       * getCompleter returns parent or null if at root
398       */
399      public void testGetCompleter() {
400 <        NoopCountedCompleter a = new NoopCountedCompleter();
400 >        NoopCC a = new NoopCC();
401          assertNull(a.getCompleter());
402 <        CountedCompleter b = new NoopCountedCompleter(a);
403 <        assertEquals(a, b.getCompleter());
402 >        CountedCompleter b = new NoopCC(a);
403 >        assertSame(a, b.getCompleter());
404 >        CountedCompleter c = new NoopCC(b);
405 >        assertSame(b, c.getCompleter());
406      }
407  
408      /**
409       * getRoot returns self if no parent, else parent's root
410       */
411      public void testGetRoot() {
412 <        NoopCountedCompleter a = new NoopCountedCompleter();
413 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
414 <        assertEquals(a, a.getRoot());
415 <        assertEquals(a, b.getRoot());
412 >        NoopCC a = new NoopCC();
413 >        NoopCC b = new NoopCC(a);
414 >        NoopCC c = new NoopCC(b);
415 >        assertSame(a, a.getRoot());
416 >        assertSame(a, b.getRoot());
417 >        assertSame(a, c.getRoot());
418      }
419  
420      /**
421 <     * tryComplete causes completion if pending count is zero
421 >     * tryComplete decrements pending count unless zero, in which case
422 >     * causes completion
423       */
424 <    public void testTryComplete1() {
425 <        NoopCountedCompleter a = new NoopCountedCompleter();
424 >    public void testTryComplete() {
425 >        NoopCC a = new NoopCC();
426          assertEquals(0, a.getPendingCount());
427 +        int n = 3;
428 +        a.setPendingCount(n);
429 +        for (; n > 0; n--) {
430 +            assertEquals(n, a.getPendingCount());
431 +            a.tryComplete();
432 +            a.checkIncomplete();
433 +            assertEquals(n - 1, a.getPendingCount());
434 +        }
435          a.tryComplete();
436 <        assertTrue(a.post);
437 <        assertTrue(a.isDone());
436 >        assertEquals(0, a.computeN());
437 >        assertEquals(1, a.onCompletionN());
438 >        assertEquals(0, a.onExceptionalCompletionN());
439 >        assertEquals(0, a.setRawResultN());
440 >        checkCompletedNormally(a);
441      }
442  
443      /**
444 <     * propagateCompletion causes completion without invoking
445 <     * onCompletion if pending count is zero
444 >     * propagateCompletion decrements pending count unless zero, in
445 >     * which case causes completion, without invoking onCompletion
446       */
447      public void testPropagateCompletion() {
448 <        NoopCountedCompleter a = new NoopCountedCompleter();
448 >        NoopCC a = new NoopCC();
449          assertEquals(0, a.getPendingCount());
450 +        int n = 3;
451 +        a.setPendingCount(n);
452 +        for (; n > 0; n--) {
453 +            assertEquals(n, a.getPendingCount());
454 +            a.propagateCompletion();
455 +            a.checkIncomplete();
456 +            assertEquals(n - 1, a.getPendingCount());
457 +        }
458          a.propagateCompletion();
459 <        assertFalse(a.post);
460 <        assertTrue(a.isDone());
461 <    }
462 <
463 <    /**
343 <     * tryComplete decrements pending count unless zero
344 <     */
345 <    public void testTryComplete2() {
346 <        NoopCountedCompleter a = new NoopCountedCompleter();
347 <        assertEquals(0, a.getPendingCount());
348 <        a.setPendingCount(1);
349 <        a.tryComplete();
350 <        assertFalse(a.post);
351 <        assertFalse(a.isDone());
352 <        assertEquals(0, a.getPendingCount());
353 <        a.tryComplete();
354 <        assertTrue(a.post);
355 <        assertTrue(a.isDone());
459 >        assertEquals(0, a.computeN());
460 >        assertEquals(0, a.onCompletionN());
461 >        assertEquals(0, a.onExceptionalCompletionN());
462 >        assertEquals(0, a.setRawResultN());
463 >        checkCompletedNormally(a);
464      }
465  
466      /**
467       * firstComplete returns this if pending count is zero else null
468       */
469      public void testFirstComplete() {
470 <        NoopCountedCompleter a = new NoopCountedCompleter();
470 >        NoopCC a = new NoopCC();
471          a.setPendingCount(1);
472          assertNull(a.firstComplete());
473 <        assertEquals(a, a.firstComplete());
473 >        a.checkIncomplete();
474 >        assertSame(a, a.firstComplete());
475 >        a.checkIncomplete();
476      }
477  
478      /**
# Line 370 | Line 480 | public class CountedCompleterTest extend
480       * zero else null
481       */
482      public void testNextComplete() {
483 <        NoopCountedCompleter a = new NoopCountedCompleter();
484 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
483 >        NoopCC a = new NoopCC();
484 >        NoopCC b = new NoopCC(a);
485          a.setPendingCount(1);
486          b.setPendingCount(1);
487          assertNull(b.firstComplete());
488 <        CountedCompleter c = b.firstComplete();
489 <        assertEquals(b, c);
490 <        CountedCompleter d = c.nextComplete();
491 <        assertNull(d);
492 <        CountedCompleter e = c.nextComplete();
493 <        assertEquals(a, e);
488 >        assertSame(b, b.firstComplete());
489 >        assertNull(b.nextComplete());
490 >        a.checkIncomplete();
491 >        b.checkIncomplete();
492 >        assertSame(a, b.nextComplete());
493 >        assertSame(a, b.nextComplete());
494 >        a.checkIncomplete();
495 >        b.checkIncomplete();
496 >        assertNull(a.nextComplete());
497 >        b.checkIncomplete();
498 >        checkCompletedNormally(a);
499      }
500  
501      /**
502 <     * quietlyCompleteRoot completes root task
502 >     * quietlyCompleteRoot completes root task and only root task
503       */
504      public void testQuietlyCompleteRoot() {
505 <        NoopCountedCompleter a = new NoopCountedCompleter();
506 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
505 >        NoopCC a = new NoopCC();
506 >        NoopCC b = new NoopCC(a);
507 >        NoopCC c = new NoopCC(b);
508          a.setPendingCount(1);
509          b.setPendingCount(1);
510 <        b.quietlyCompleteRoot();
510 >        c.setPendingCount(1);
511 >        c.quietlyCompleteRoot();
512          assertTrue(a.isDone());
513          assertFalse(b.isDone());
514 +        assertFalse(c.isDone());
515      }
516  
517      // Invocation tests use some interdependent task classes
518      // to better test propagation etc
519  
520 <
521 <    // Version of Fibonacci with different classes for left vs right forks
522 <    abstract static class CCF extends CountedCompleter {
520 >    /**
521 >     * Version of Fibonacci with different classes for left vs right forks
522 >     */
523 >    abstract class CCF extends CheckedCC {
524          int number;
525          int rnumber;
526  
# Line 410 | Line 529 | public class CountedCompleterTest extend
529              this.number = n;
530          }
531  
532 <        public final void compute() {
414 <            CountedCompleter p;
532 >        protected final void realCompute() {
533              CCF f = this;
534              int n = number;
535              while (n >= 2) {
536                  new RCCF(f, n - 2).fork();
537                  f = new LCCF(f, --n);
538              }
539 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
539 >            f.complete(null);
540          }
541      }
542  
543 <    static final class LCCF extends CCF {
543 >    final class LCCF extends CCF {
544 >        public LCCF(int n) { this(null, n); }
545          public LCCF(CountedCompleter parent, int n) {
546              super(parent, n);
547          }
548          public final void onCompletion(CountedCompleter caller) {
549 +            super.onCompletion(caller);
550              CCF p = (CCF)getCompleter();
551              int n = number + rnumber;
552              if (p != null)
# Line 440 | Line 555 | public class CountedCompleterTest extend
555                  number = n;
556          }
557      }
558 <    static final class RCCF extends CCF {
558 >    final class RCCF extends CCF {
559          public RCCF(CountedCompleter parent, int n) {
560              super(parent, n);
561          }
562          public final void onCompletion(CountedCompleter caller) {
563 +            super.onCompletion(caller);
564              CCF p = (CCF)getCompleter();
565              int n = number + rnumber;
566              if (p != null)
# Line 455 | Line 571 | public class CountedCompleterTest extend
571      }
572  
573      // Version of CCF with forced failure in left completions
574 <    abstract static class FailingCCF extends CountedCompleter {
574 >    abstract class FailingCCF extends CheckedCC {
575          int number;
576          int rnumber;
577  
# Line 464 | Line 580 | public class CountedCompleterTest extend
580              this.number = n;
581          }
582  
583 <        public final void compute() {
468 <            CountedCompleter p;
583 >        protected final void realCompute() {
584              FailingCCF f = this;
585              int n = number;
586              while (n >= 2) {
587                  new RFCCF(f, n - 2).fork();
588                  f = new LFCCF(f, --n);
589              }
590 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
590 >            f.complete(null);
591          }
592      }
593  
594 <    static final class LFCCF extends FailingCCF {
594 >    final class LFCCF extends FailingCCF {
595 >        public LFCCF(int n) { this(null, n); }
596          public LFCCF(CountedCompleter parent, int n) {
597              super(parent, n);
598          }
599          public final void onCompletion(CountedCompleter caller) {
600 +            super.onCompletion(caller);
601              FailingCCF p = (FailingCCF)getCompleter();
602              int n = number + rnumber;
603              if (p != null)
# Line 494 | Line 606 | public class CountedCompleterTest extend
606                  number = n;
607          }
608      }
609 <    static final class RFCCF extends FailingCCF {
609 >    final class RFCCF extends FailingCCF {
610          public RFCCF(CountedCompleter parent, int n) {
611              super(parent, n);
612          }
613          public final void onCompletion(CountedCompleter caller) {
614 +            super.onCompletion(caller);
615              completeExceptionally(new FJException());
616          }
617      }
# Line 511 | Line 624 | public class CountedCompleterTest extend
624      public void testInvoke() {
625          ForkJoinTask a = new CheckedRecursiveAction() {
626              protected void realCompute() {
627 <                CCF f = new LCCF(null, 8);
627 >                CCF f = new LCCF(8);
628                  assertNull(f.invoke());
629                  assertEquals(21, f.number);
630                  checkCompletedNormally(f);
# Line 527 | Line 640 | public class CountedCompleterTest extend
640      public void testQuietlyInvoke() {
641          ForkJoinTask a = new CheckedRecursiveAction() {
642              protected void realCompute() {
643 <                CCF f = new LCCF(null, 8);
643 >                CCF f = new LCCF(8);
644                  f.quietlyInvoke();
645                  assertEquals(21, f.number);
646                  checkCompletedNormally(f);
# Line 541 | Line 654 | public class CountedCompleterTest extend
654      public void testForkJoin() {
655          ForkJoinTask a = new CheckedRecursiveAction() {
656              protected void realCompute() {
657 <                CCF f = new LCCF(null, 8);
657 >                CCF f = new LCCF(8);
658                  assertSame(f, f.fork());
659                  assertNull(f.join());
660                  assertEquals(21, f.number);
# Line 556 | Line 669 | public class CountedCompleterTest extend
669      public void testForkGet() {
670          ForkJoinTask a = new CheckedRecursiveAction() {
671              protected void realCompute() throws Exception {
672 <                CCF f = new LCCF(null, 8);
672 >                CCF f = new LCCF(8);
673                  assertSame(f, f.fork());
674                  assertNull(f.get());
675                  assertEquals(21, f.number);
# Line 571 | Line 684 | public class CountedCompleterTest extend
684      public void testForkTimedGet() {
685          ForkJoinTask a = new CheckedRecursiveAction() {
686              protected void realCompute() throws Exception {
687 <                CCF f = new LCCF(null, 8);
687 >                CCF f = new LCCF(8);
688                  assertSame(f, f.fork());
689                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
690                  assertEquals(21, f.number);
# Line 586 | Line 699 | public class CountedCompleterTest extend
699      public void testForkTimedGetNPE() {
700          ForkJoinTask a = new CheckedRecursiveAction() {
701              protected void realCompute() throws Exception {
702 <                CCF f = new LCCF(null, 8);
702 >                CCF f = new LCCF(8);
703                  assertSame(f, f.fork());
704                  try {
705                      f.get(5L, null);
# Line 602 | Line 715 | public class CountedCompleterTest extend
715      public void testForkQuietlyJoin() {
716          ForkJoinTask a = new CheckedRecursiveAction() {
717              protected void realCompute() {
718 <                CCF f = new LCCF(null, 8);
718 >                CCF f = new LCCF(8);
719                  assertSame(f, f.fork());
720                  f.quietlyJoin();
721                  assertEquals(21, f.number);
# Line 618 | Line 731 | public class CountedCompleterTest extend
731      public void testForkHelpQuiesce() {
732          ForkJoinTask a = new CheckedRecursiveAction() {
733              protected void realCompute() {
734 <                CCF f = new LCCF(null, 8);
734 >                CCF f = new LCCF(8);
735                  assertSame(f, f.fork());
736                  helpQuiesce();
737                  assertEquals(21, f.number);
# Line 634 | Line 747 | public class CountedCompleterTest extend
747      public void testAbnormalInvoke() {
748          ForkJoinTask a = new CheckedRecursiveAction() {
749              protected void realCompute() {
750 <                FailingCCF f = new LFCCF(null, 8);
750 >                FailingCCF f = new LFCCF(8);
751                  try {
752                      f.invoke();
753                      shouldThrow();
# Line 651 | Line 764 | public class CountedCompleterTest extend
764      public void testAbnormalQuietlyInvoke() {
765          ForkJoinTask a = new CheckedRecursiveAction() {
766              protected void realCompute() {
767 <                FailingCCF f = new LFCCF(null, 8);
767 >                FailingCCF f = new LFCCF(8);
768                  f.quietlyInvoke();
769                  assertTrue(f.getException() instanceof FJException);
770                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 778 | public class CountedCompleterTest extend
778      public void testAbnormalForkJoin() {
779          ForkJoinTask a = new CheckedRecursiveAction() {
780              protected void realCompute() {
781 <                FailingCCF f = new LFCCF(null, 8);
781 >                FailingCCF f = new LFCCF(8);
782                  assertSame(f, f.fork());
783                  try {
784                      f.join();
# Line 683 | Line 796 | public class CountedCompleterTest extend
796      public void testAbnormalForkGet() {
797          ForkJoinTask a = new CheckedRecursiveAction() {
798              protected void realCompute() throws Exception {
799 <                FailingCCF f = new LFCCF(null, 8);
799 >                FailingCCF f = new LFCCF(8);
800                  assertSame(f, f.fork());
801                  try {
802                      f.get();
# Line 703 | Line 816 | public class CountedCompleterTest extend
816      public void testAbnormalForkTimedGet() {
817          ForkJoinTask a = new CheckedRecursiveAction() {
818              protected void realCompute() throws Exception {
819 <                FailingCCF f = new LFCCF(null, 8);
819 >                FailingCCF f = new LFCCF(8);
820                  assertSame(f, f.fork());
821                  try {
822                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 836 | public class CountedCompleterTest extend
836      public void testAbnormalForkQuietlyJoin() {
837          ForkJoinTask a = new CheckedRecursiveAction() {
838              protected void realCompute() {
839 <                FailingCCF f = new LFCCF(null, 8);
839 >                FailingCCF f = new LFCCF(8);
840                  assertSame(f, f.fork());
841                  f.quietlyJoin();
842                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 851 | public class CountedCompleterTest extend
851      public void testCancelledInvoke() {
852          ForkJoinTask a = new CheckedRecursiveAction() {
853              protected void realCompute() {
854 <                CCF f = new LCCF(null, 8);
854 >                CCF f = new LCCF(8);
855                  assertTrue(f.cancel(true));
856                  try {
857                      f.invoke();
# Line 756 | Line 869 | public class CountedCompleterTest extend
869      public void testCancelledForkJoin() {
870          ForkJoinTask a = new CheckedRecursiveAction() {
871              protected void realCompute() {
872 <                CCF f = new LCCF(null, 8);
872 >                CCF f = new LCCF(8);
873                  assertTrue(f.cancel(true));
874                  assertSame(f, f.fork());
875                  try {
# Line 775 | Line 888 | public class CountedCompleterTest extend
888      public void testCancelledForkGet() {
889          ForkJoinTask a = new CheckedRecursiveAction() {
890              protected void realCompute() throws Exception {
891 <                CCF f = new LCCF(null, 8);
891 >                CCF f = new LCCF(8);
892                  assertTrue(f.cancel(true));
893                  assertSame(f, f.fork());
894                  try {
# Line 794 | Line 907 | public class CountedCompleterTest extend
907      public void testCancelledForkTimedGet() throws Exception {
908          ForkJoinTask a = new CheckedRecursiveAction() {
909              protected void realCompute() throws Exception {
910 <                CCF f = new LCCF(null, 8);
910 >                CCF f = new LCCF(8);
911                  assertTrue(f.cancel(true));
912                  assertSame(f, f.fork());
913                  try {
# Line 813 | Line 926 | public class CountedCompleterTest extend
926      public void testCancelledForkQuietlyJoin() {
927          ForkJoinTask a = new CheckedRecursiveAction() {
928              protected void realCompute() {
929 <                CCF f = new LCCF(null, 8);
929 >                CCF f = new LCCF(8);
930                  assertTrue(f.cancel(true));
931                  assertSame(f, f.fork());
932                  f.quietlyJoin();
# Line 885 | Line 998 | public class CountedCompleterTest extend
998      public void testCompleteExceptionally2() {
999          ForkJoinTask a = new CheckedRecursiveAction() {
1000              protected void realCompute() {
1001 <                CCF f = new LCCF(null, 8);
1002 <                f.completeExceptionally(new FJException());
1003 <                try {
1004 <                    f.invoke();
1005 <                    shouldThrow();
1006 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
1001 >                CCF n = new LCCF(8);
1002 >                CCF f = new LCCF(n, 8);
1003 >                FJException ex = new FJException();
1004 >                f.completeExceptionally(ex);
1005 >                f.checkCompletedExceptionally(ex);
1006 >                n.checkCompletedExceptionally(ex);
1007              }};
1008          testInvokeOnPool(mainPool(), a);
1009      }
# Line 903 | Line 1014 | public class CountedCompleterTest extend
1014      public void testInvokeAll2() {
1015          ForkJoinTask a = new CheckedRecursiveAction() {
1016              protected void realCompute() {
1017 <                CCF f = new LCCF(null, 8);
1018 <                CCF g = new LCCF(null, 9);
1017 >                CCF f = new LCCF(8);
1018 >                CCF g = new LCCF(9);
1019                  invokeAll(f, g);
1020                  assertEquals(21, f.number);
1021                  assertEquals(34, g.number);
# Line 920 | Line 1031 | public class CountedCompleterTest extend
1031      public void testInvokeAll1() {
1032          ForkJoinTask a = new CheckedRecursiveAction() {
1033              protected void realCompute() {
1034 <                CCF f = new LCCF(null, 8);
1034 >                CCF f = new LCCF(8);
1035                  invokeAll(f);
1036                  checkCompletedNormally(f);
1037                  assertEquals(21, f.number);
# Line 934 | Line 1045 | public class CountedCompleterTest extend
1045      public void testInvokeAll3() {
1046          ForkJoinTask a = new CheckedRecursiveAction() {
1047              protected void realCompute() {
1048 <                CCF f = new LCCF(null, 8);
1049 <                CCF g = new LCCF(null, 9);
1050 <                CCF h = new LCCF(null, 7);
1048 >                CCF f = new LCCF(8);
1049 >                CCF g = new LCCF(9);
1050 >                CCF h = new LCCF(7);
1051                  invokeAll(f, g, h);
1052                  assertEquals(21, f.number);
1053                  assertEquals(34, g.number);
# Line 954 | Line 1065 | public class CountedCompleterTest extend
1065      public void testInvokeAllCollection() {
1066          ForkJoinTask a = new CheckedRecursiveAction() {
1067              protected void realCompute() {
1068 <                CCF f = new LCCF(null, 8);
1069 <                CCF g = new LCCF(null, 9);
1070 <                CCF h = new LCCF(null, 7);
1068 >                CCF f = new LCCF(8);
1069 >                CCF g = new LCCF(9);
1070 >                CCF h = new LCCF(7);
1071                  HashSet set = new HashSet();
1072                  set.add(f);
1073                  set.add(g);
# Line 978 | Line 1089 | public class CountedCompleterTest extend
1089      public void testInvokeAllNPE() {
1090          ForkJoinTask a = new CheckedRecursiveAction() {
1091              protected void realCompute() {
1092 <                CCF f = new LCCF(null, 8);
1093 <                CCF g = new LCCF(null, 9);
1092 >                CCF f = new LCCF(8);
1093 >                CCF g = new LCCF(9);
1094                  CCF h = null;
1095                  try {
1096                      invokeAll(f, g, h);
# Line 995 | Line 1106 | public class CountedCompleterTest extend
1106      public void testAbnormalInvokeAll2() {
1107          ForkJoinTask a = new CheckedRecursiveAction() {
1108              protected void realCompute() {
1109 <                CCF f = new LCCF(null, 8);
1110 <                FailingCCF g = new LFCCF(null, 9);
1109 >                CCF f = new LCCF(8);
1110 >                FailingCCF g = new LFCCF(9);
1111                  try {
1112                      invokeAll(f, g);
1113                      shouldThrow();
# Line 1013 | Line 1124 | public class CountedCompleterTest extend
1124      public void testAbnormalInvokeAll1() {
1125          ForkJoinTask a = new CheckedRecursiveAction() {
1126              protected void realCompute() {
1127 <                FailingCCF g = new LFCCF(null, 9);
1127 >                FailingCCF g = new LFCCF(9);
1128                  try {
1129                      invokeAll(g);
1130                      shouldThrow();
# Line 1030 | Line 1141 | public class CountedCompleterTest extend
1141      public void testAbnormalInvokeAll3() {
1142          ForkJoinTask a = new CheckedRecursiveAction() {
1143              protected void realCompute() {
1144 <                CCF f = new LCCF(null, 8);
1145 <                FailingCCF g = new LFCCF(null, 9);
1146 <                CCF h = new LCCF(null, 7);
1144 >                CCF f = new LCCF(8);
1145 >                FailingCCF g = new LFCCF(9);
1146 >                CCF h = new LCCF(7);
1147                  try {
1148                      invokeAll(f, g, h);
1149                      shouldThrow();
# Line 1044 | Line 1155 | public class CountedCompleterTest extend
1155      }
1156  
1157      /**
1158 <     * invokeAll(collection)  throws exception if any task does
1158 >     * invokeAll(collection) throws exception if any task does
1159       */
1160      public void testAbnormalInvokeAllCollection() {
1161          ForkJoinTask a = new CheckedRecursiveAction() {
1162              protected void realCompute() {
1163 <                FailingCCF f = new LFCCF(null, 8);
1164 <                CCF g = new LCCF(null, 9);
1165 <                CCF h = new LCCF(null, 7);
1163 >                FailingCCF f = new LFCCF(8);
1164 >                CCF g = new LCCF(9);
1165 >                CCF h = new LCCF(7);
1166                  HashSet set = new HashSet();
1167                  set.add(f);
1168                  set.add(g);
# Line 1073 | Line 1184 | public class CountedCompleterTest extend
1184      public void testTryUnfork() {
1185          ForkJoinTask a = new CheckedRecursiveAction() {
1186              protected void realCompute() {
1187 <                CCF g = new LCCF(null, 9);
1187 >                CCF g = new LCCF(9);
1188                  assertSame(g, g.fork());
1189 <                CCF f = new LCCF(null, 8);
1189 >                CCF f = new LCCF(8);
1190                  assertSame(f, f.fork());
1191                  assertTrue(f.tryUnfork());
1192                  helpQuiesce();
# Line 1092 | Line 1203 | public class CountedCompleterTest extend
1203      public void testGetSurplusQueuedTaskCount() {
1204          ForkJoinTask a = new CheckedRecursiveAction() {
1205              protected void realCompute() {
1206 <                CCF h = new LCCF(null, 7);
1206 >                CCF h = new LCCF(7);
1207                  assertSame(h, h.fork());
1208 <                CCF g = new LCCF(null, 9);
1208 >                CCF g = new LCCF(9);
1209                  assertSame(g, g.fork());
1210 <                CCF f = new LCCF(null, 8);
1210 >                CCF f = new LCCF(8);
1211                  assertSame(f, f.fork());
1212                  assertTrue(getSurplusQueuedTaskCount() > 0);
1213                  helpQuiesce();
# Line 1114 | Line 1225 | public class CountedCompleterTest extend
1225      public void testPeekNextLocalTask() {
1226          ForkJoinTask a = new CheckedRecursiveAction() {
1227              protected void realCompute() {
1228 <                CCF g = new LCCF(null, 9);
1228 >                CCF g = new LCCF(9);
1229                  assertSame(g, g.fork());
1230 <                CCF f = new LCCF(null, 8);
1230 >                CCF f = new LCCF(8);
1231                  assertSame(f, f.fork());
1232                  assertSame(f, peekNextLocalTask());
1233                  assertNull(f.join());
# Line 1134 | Line 1245 | public class CountedCompleterTest extend
1245      public void testPollNextLocalTask() {
1246          ForkJoinTask a = new CheckedRecursiveAction() {
1247              protected void realCompute() {
1248 <                CCF g = new LCCF(null, 9);
1248 >                CCF g = new LCCF(9);
1249                  assertSame(g, g.fork());
1250 <                CCF f = new LCCF(null, 8);
1250 >                CCF f = new LCCF(8);
1251                  assertSame(f, f.fork());
1252                  assertSame(f, pollNextLocalTask());
1253                  helpQuiesce();
# Line 1153 | Line 1264 | public class CountedCompleterTest extend
1264      public void testPollTask() {
1265          ForkJoinTask a = new CheckedRecursiveAction() {
1266              protected void realCompute() {
1267 <                CCF g = new LCCF(null, 9);
1267 >                CCF g = new LCCF(9);
1268                  assertSame(g, g.fork());
1269 <                CCF f = new LCCF(null, 8);
1269 >                CCF f = new LCCF(8);
1270                  assertSame(f, f.fork());
1271                  assertSame(f, pollTask());
1272                  helpQuiesce();
# Line 1171 | Line 1282 | public class CountedCompleterTest extend
1282      public void testPeekNextLocalTaskAsync() {
1283          ForkJoinTask a = new CheckedRecursiveAction() {
1284              protected void realCompute() {
1285 <                CCF g = new LCCF(null, 9);
1285 >                CCF g = new LCCF(9);
1286                  assertSame(g, g.fork());
1287 <                CCF f = new LCCF(null, 8);
1287 >                CCF f = new LCCF(8);
1288                  assertSame(f, f.fork());
1289                  assertSame(g, peekNextLocalTask());
1290                  assertNull(f.join());
# Line 1192 | Line 1303 | public class CountedCompleterTest extend
1303      public void testPollNextLocalTaskAsync() {
1304          ForkJoinTask a = new CheckedRecursiveAction() {
1305              protected void realCompute() {
1306 <                CCF g = new LCCF(null, 9);
1306 >                CCF g = new LCCF(9);
1307                  assertSame(g, g.fork());
1308 <                CCF f = new LCCF(null, 8);
1308 >                CCF f = new LCCF(8);
1309                  assertSame(f, f.fork());
1310                  assertSame(g, pollNextLocalTask());
1311                  helpQuiesce();
# Line 1212 | Line 1323 | public class CountedCompleterTest extend
1323      public void testPollTaskAsync() {
1324          ForkJoinTask a = new CheckedRecursiveAction() {
1325              protected void realCompute() {
1326 <                CCF g = new LCCF(null, 9);
1326 >                CCF g = new LCCF(9);
1327                  assertSame(g, g.fork());
1328 <                CCF f = new LCCF(null, 8);
1328 >                CCF f = new LCCF(8);
1329                  assertSame(f, f.fork());
1330                  assertSame(g, pollTask());
1331                  helpQuiesce();
# Line 1235 | Line 1346 | public class CountedCompleterTest extend
1346      public void testInvokeSingleton() {
1347          ForkJoinTask a = new CheckedRecursiveAction() {
1348              protected void realCompute() {
1349 <                CCF f = new LCCF(null, 8);
1349 >                CCF f = new LCCF(8);
1350                  assertNull(f.invoke());
1351                  assertEquals(21, f.number);
1352                  checkCompletedNormally(f);
# Line 1251 | Line 1362 | public class CountedCompleterTest extend
1362      public void testQuietlyInvokeSingleton() {
1363          ForkJoinTask a = new CheckedRecursiveAction() {
1364              protected void realCompute() {
1365 <                CCF f = new LCCF(null, 8);
1365 >                CCF f = new LCCF(8);
1366                  f.quietlyInvoke();
1367                  assertEquals(21, f.number);
1368                  checkCompletedNormally(f);
# Line 1265 | Line 1376 | public class CountedCompleterTest extend
1376      public void testForkJoinSingleton() {
1377          ForkJoinTask a = new CheckedRecursiveAction() {
1378              protected void realCompute() {
1379 <                CCF f = new LCCF(null, 8);
1379 >                CCF f = new LCCF(8);
1380                  assertSame(f, f.fork());
1381                  assertNull(f.join());
1382                  assertEquals(21, f.number);
# Line 1280 | Line 1391 | public class CountedCompleterTest extend
1391      public void testForkGetSingleton() {
1392          ForkJoinTask a = new CheckedRecursiveAction() {
1393              protected void realCompute() throws Exception {
1394 <                CCF f = new LCCF(null, 8);
1394 >                CCF f = new LCCF(8);
1395                  assertSame(f, f.fork());
1396                  assertNull(f.get());
1397                  assertEquals(21, f.number);
# Line 1295 | Line 1406 | public class CountedCompleterTest extend
1406      public void testForkTimedGetSingleton() {
1407          ForkJoinTask a = new CheckedRecursiveAction() {
1408              protected void realCompute() throws Exception {
1409 <                CCF f = new LCCF(null, 8);
1409 >                CCF f = new LCCF(8);
1410                  assertSame(f, f.fork());
1411                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1412                  assertEquals(21, f.number);
# Line 1310 | Line 1421 | public class CountedCompleterTest extend
1421      public void testForkTimedGetNPESingleton() {
1422          ForkJoinTask a = new CheckedRecursiveAction() {
1423              protected void realCompute() throws Exception {
1424 <                CCF f = new LCCF(null, 8);
1424 >                CCF f = new LCCF(8);
1425                  assertSame(f, f.fork());
1426                  try {
1427                      f.get(5L, null);
# Line 1326 | Line 1437 | public class CountedCompleterTest extend
1437      public void testForkQuietlyJoinSingleton() {
1438          ForkJoinTask a = new CheckedRecursiveAction() {
1439              protected void realCompute() {
1440 <                CCF f = new LCCF(null, 8);
1440 >                CCF f = new LCCF(8);
1441                  assertSame(f, f.fork());
1442                  f.quietlyJoin();
1443                  assertEquals(21, f.number);
# Line 1342 | Line 1453 | public class CountedCompleterTest extend
1453      public void testForkHelpQuiesceSingleton() {
1454          ForkJoinTask a = new CheckedRecursiveAction() {
1455              protected void realCompute() {
1456 <                CCF f = new LCCF(null, 8);
1456 >                CCF f = new LCCF(8);
1457                  assertSame(f, f.fork());
1458                  helpQuiesce();
1459                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1469 | public class CountedCompleterTest extend
1469      public void testAbnormalInvokeSingleton() {
1470          ForkJoinTask a = new CheckedRecursiveAction() {
1471              protected void realCompute() {
1472 <                FailingCCF f = new LFCCF(null, 8);
1472 >                FailingCCF f = new LFCCF(8);
1473                  try {
1474                      f.invoke();
1475                      shouldThrow();
# Line 1375 | Line 1486 | public class CountedCompleterTest extend
1486      public void testAbnormalQuietlyInvokeSingleton() {
1487          ForkJoinTask a = new CheckedRecursiveAction() {
1488              protected void realCompute() {
1489 <                FailingCCF f = new LFCCF(null, 8);
1489 >                FailingCCF f = new LFCCF(8);
1490                  f.quietlyInvoke();
1491                  assertTrue(f.getException() instanceof FJException);
1492                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1500 | public class CountedCompleterTest extend
1500      public void testAbnormalForkJoinSingleton() {
1501          ForkJoinTask a = new CheckedRecursiveAction() {
1502              protected void realCompute() {
1503 <                FailingCCF f = new LFCCF(null, 8);
1503 >                FailingCCF f = new LFCCF(8);
1504                  assertSame(f, f.fork());
1505                  try {
1506                      f.join();
# Line 1407 | Line 1518 | public class CountedCompleterTest extend
1518      public void testAbnormalForkGetSingleton() {
1519          ForkJoinTask a = new CheckedRecursiveAction() {
1520              protected void realCompute() throws Exception {
1521 <                FailingCCF f = new LFCCF(null, 8);
1521 >                FailingCCF f = new LFCCF(8);
1522                  assertSame(f, f.fork());
1523                  try {
1524                      f.get();
# Line 1427 | Line 1538 | public class CountedCompleterTest extend
1538      public void testAbnormalForkTimedGetSingleton() {
1539          ForkJoinTask a = new CheckedRecursiveAction() {
1540              protected void realCompute() throws Exception {
1541 <                FailingCCF f = new LFCCF(null, 8);
1541 >                FailingCCF f = new LFCCF(8);
1542                  assertSame(f, f.fork());
1543                  try {
1544                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1558 | public class CountedCompleterTest extend
1558      public void testAbnormalForkQuietlyJoinSingleton() {
1559          ForkJoinTask a = new CheckedRecursiveAction() {
1560              protected void realCompute() {
1561 <                FailingCCF f = new LFCCF(null, 8);
1561 >                FailingCCF f = new LFCCF(8);
1562                  assertSame(f, f.fork());
1563                  f.quietlyJoin();
1564                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1573 | public class CountedCompleterTest extend
1573      public void testCancelledInvokeSingleton() {
1574          ForkJoinTask a = new CheckedRecursiveAction() {
1575              protected void realCompute() {
1576 <                CCF f = new LCCF(null, 8);
1576 >                CCF f = new LCCF(8);
1577                  assertTrue(f.cancel(true));
1578                  try {
1579                      f.invoke();
# Line 1480 | Line 1591 | public class CountedCompleterTest extend
1591      public void testCancelledForkJoinSingleton() {
1592          ForkJoinTask a = new CheckedRecursiveAction() {
1593              protected void realCompute() {
1594 <                CCF f = new LCCF(null, 8);
1594 >                CCF f = new LCCF(8);
1595                  assertTrue(f.cancel(true));
1596                  assertSame(f, f.fork());
1597                  try {
# Line 1499 | Line 1610 | public class CountedCompleterTest extend
1610      public void testCancelledForkGetSingleton() {
1611          ForkJoinTask a = new CheckedRecursiveAction() {
1612              protected void realCompute() throws Exception {
1613 <                CCF f = new LCCF(null, 8);
1613 >                CCF f = new LCCF(8);
1614                  assertTrue(f.cancel(true));
1615                  assertSame(f, f.fork());
1616                  try {
# Line 1518 | Line 1629 | public class CountedCompleterTest extend
1629      public void testCancelledForkTimedGetSingleton() throws Exception {
1630          ForkJoinTask a = new CheckedRecursiveAction() {
1631              protected void realCompute() throws Exception {
1632 <                CCF f = new LCCF(null, 8);
1632 >                CCF f = new LCCF(8);
1633                  assertTrue(f.cancel(true));
1634                  assertSame(f, f.fork());
1635                  try {
# Line 1537 | Line 1648 | public class CountedCompleterTest extend
1648      public void testCancelledForkQuietlyJoinSingleton() {
1649          ForkJoinTask a = new CheckedRecursiveAction() {
1650              protected void realCompute() {
1651 <                CCF f = new LCCF(null, 8);
1651 >                CCF f = new LCCF(8);
1652                  assertTrue(f.cancel(true));
1653                  assertSame(f, f.fork());
1654                  f.quietlyJoin();
# Line 1552 | Line 1663 | public class CountedCompleterTest extend
1663      public void testCompleteExceptionallySingleton() {
1664          ForkJoinTask a = new CheckedRecursiveAction() {
1665              protected void realCompute() {
1666 <                CCF f = new LCCF(null, 8);
1667 <                f.completeExceptionally(new FJException());
1668 <                try {
1669 <                    f.invoke();
1670 <                    shouldThrow();
1671 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1666 >                CCF n = new LCCF(8);
1667 >                CCF f = new LCCF(n, 8);
1668 >                FJException ex = new FJException();
1669 >                f.completeExceptionally(ex);
1670 >                f.checkCompletedExceptionally(ex);
1671 >                n.checkCompletedExceptionally(ex);
1672              }};
1673          testInvokeOnPool(singletonPool(), a);
1674      }
# Line 1570 | Line 1679 | public class CountedCompleterTest extend
1679      public void testInvokeAll2Singleton() {
1680          ForkJoinTask a = new CheckedRecursiveAction() {
1681              protected void realCompute() {
1682 <                CCF f = new LCCF(null, 8);
1683 <                CCF g = new LCCF(null, 9);
1682 >                CCF f = new LCCF(8);
1683 >                CCF g = new LCCF(9);
1684                  invokeAll(f, g);
1685                  assertEquals(21, f.number);
1686                  assertEquals(34, g.number);
# Line 1587 | Line 1696 | public class CountedCompleterTest extend
1696      public void testInvokeAll1Singleton() {
1697          ForkJoinTask a = new CheckedRecursiveAction() {
1698              protected void realCompute() {
1699 <                CCF f = new LCCF(null, 8);
1699 >                CCF f = new LCCF(8);
1700                  invokeAll(f);
1701                  checkCompletedNormally(f);
1702                  assertEquals(21, f.number);
# Line 1601 | Line 1710 | public class CountedCompleterTest extend
1710      public void testInvokeAll3Singleton() {
1711          ForkJoinTask a = new CheckedRecursiveAction() {
1712              protected void realCompute() {
1713 <                CCF f = new LCCF(null, 8);
1714 <                CCF g = new LCCF(null, 9);
1715 <                CCF h = new LCCF(null, 7);
1713 >                CCF f = new LCCF(8);
1714 >                CCF g = new LCCF(9);
1715 >                CCF h = new LCCF(7);
1716                  invokeAll(f, g, h);
1717                  assertEquals(21, f.number);
1718                  assertEquals(34, g.number);
# Line 1621 | Line 1730 | public class CountedCompleterTest extend
1730      public void testInvokeAllCollectionSingleton() {
1731          ForkJoinTask a = new CheckedRecursiveAction() {
1732              protected void realCompute() {
1733 <                CCF f = new LCCF(null, 8);
1734 <                CCF g = new LCCF(null, 9);
1735 <                CCF h = new LCCF(null, 7);
1733 >                CCF f = new LCCF(8);
1734 >                CCF g = new LCCF(9);
1735 >                CCF h = new LCCF(7);
1736                  HashSet set = new HashSet();
1737                  set.add(f);
1738                  set.add(g);
# Line 1645 | Line 1754 | public class CountedCompleterTest extend
1754      public void testInvokeAllNPESingleton() {
1755          ForkJoinTask a = new CheckedRecursiveAction() {
1756              protected void realCompute() {
1757 <                CCF f = new LCCF(null, 8);
1758 <                CCF g = new LCCF(null, 9);
1757 >                CCF f = new LCCF(8);
1758 >                CCF g = new LCCF(9);
1759                  CCF h = null;
1760                  try {
1761                      invokeAll(f, g, h);
# Line 1662 | Line 1771 | public class CountedCompleterTest extend
1771      public void testAbnormalInvokeAll2Singleton() {
1772          ForkJoinTask a = new CheckedRecursiveAction() {
1773              protected void realCompute() {
1774 <                CCF f = new LCCF(null, 8);
1775 <                FailingCCF g = new LFCCF(null, 9);
1774 >                CCF f = new LCCF(8);
1775 >                FailingCCF g = new LFCCF(9);
1776                  try {
1777                      invokeAll(f, g);
1778                      shouldThrow();
# Line 1680 | Line 1789 | public class CountedCompleterTest extend
1789      public void testAbnormalInvokeAll1Singleton() {
1790          ForkJoinTask a = new CheckedRecursiveAction() {
1791              protected void realCompute() {
1792 <                FailingCCF g = new LFCCF(null, 9);
1792 >                FailingCCF g = new LFCCF(9);
1793                  try {
1794                      invokeAll(g);
1795                      shouldThrow();
# Line 1697 | Line 1806 | public class CountedCompleterTest extend
1806      public void testAbnormalInvokeAll3Singleton() {
1807          ForkJoinTask a = new CheckedRecursiveAction() {
1808              protected void realCompute() {
1809 <                CCF f = new LCCF(null, 8);
1810 <                FailingCCF g = new LFCCF(null, 9);
1811 <                CCF h = new LCCF(null, 7);
1809 >                CCF f = new LCCF(8);
1810 >                FailingCCF g = new LFCCF(9);
1811 >                CCF h = new LCCF(7);
1812                  try {
1813                      invokeAll(f, g, h);
1814                      shouldThrow();
# Line 1711 | Line 1820 | public class CountedCompleterTest extend
1820      }
1821  
1822      /**
1823 <     * invokeAll(collection)  throws exception if any task does
1823 >     * invokeAll(collection) throws exception if any task does
1824       */
1825      public void testAbnormalInvokeAllCollectionSingleton() {
1826          ForkJoinTask a = new CheckedRecursiveAction() {
1827              protected void realCompute() {
1828 <                FailingCCF f = new LFCCF(null, 8);
1829 <                CCF g = new LCCF(null, 9);
1830 <                CCF h = new LCCF(null, 7);
1828 >                FailingCCF f = new LFCCF(8);
1829 >                CCF g = new LCCF(9);
1830 >                CCF h = new LCCF(7);
1831                  HashSet set = new HashSet();
1832                  set.add(f);
1833                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines