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.22 by jsr166, Sun Oct 18 18:54:49 2015 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import java.util.concurrent.ExecutionException;
6 >
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13 + import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.CountedCompleter;
11 import java.util.concurrent.ForkJoinWorkerThread;
12 import java.util.concurrent.RecursiveAction;
13 import java.util.concurrent.TimeUnit;
16   import java.util.concurrent.TimeoutException;
17 < import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
18 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import static java.util.concurrent.TimeUnit.SECONDS;
20 < import java.util.HashSet;
21 < import junit.framework.*;
17 > import java.util.concurrent.atomic.AtomicInteger;
18 > import java.util.concurrent.atomic.AtomicReference;
19 >
20 > import junit.framework.Test;
21 > import junit.framework.TestSuite;
22  
23   public class CountedCompleterTest extends JSR166TestCase {
24  
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28  
29      public static Test suite() {
# Line 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());
# Line 273 | Line 345 | public class CountedCompleterTest extend
345       * addToPendingCount adds to the reported pending count
346       */
347      public void testAddToPendingCount() {
348 <        NoopCountedCompleter a = new NoopCountedCompleter();
348 >        NoopCC a = new NoopCC();
349          assertEquals(0, a.getPendingCount());
350          a.addToPendingCount(1);
351          assertEquals(1, a.getPendingCount());
# Line 285 | 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      }
370  
371      /**
372 +     * compareAndSetPendingCount compares and sets the reported
373 +     * pending count
374 +     */
375 +    public void testCompareAndSetPendingCount() {
376 +        NoopCC a = new NoopCC();
377 +        assertEquals(0, a.getPendingCount());
378 +        assertTrue(a.compareAndSetPendingCount(0, 1));
379 +        assertEquals(1, a.getPendingCount());
380 +        assertTrue(a.compareAndSetPendingCount(1, 2));
381 +        assertEquals(2, a.getPendingCount());
382 +        assertFalse(a.compareAndSetPendingCount(1, 3));
383 +        assertEquals(2, a.getPendingCount());
384 +    }
385 +
386 +    /**
387       * getCompleter returns parent or null if at root
388       */
389      public void testGetCompleter() {
390 <        NoopCountedCompleter a = new NoopCountedCompleter();
390 >        NoopCC a = new NoopCC();
391          assertNull(a.getCompleter());
392 <        CountedCompleter b = new NoopCountedCompleter(a);
393 <        assertEquals(a, b.getCompleter());
392 >        CountedCompleter b = new NoopCC(a);
393 >        assertSame(a, b.getCompleter());
394 >        CountedCompleter c = new NoopCC(b);
395 >        assertSame(b, c.getCompleter());
396      }
397  
398      /**
399       * getRoot returns self if no parent, else parent's root
400       */
401      public void testGetRoot() {
402 <        NoopCountedCompleter a = new NoopCountedCompleter();
403 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
404 <        assertEquals(a, a.getRoot());
405 <        assertEquals(a, b.getRoot());
402 >        NoopCC a = new NoopCC();
403 >        NoopCC b = new NoopCC(a);
404 >        NoopCC c = new NoopCC(b);
405 >        assertSame(a, a.getRoot());
406 >        assertSame(a, b.getRoot());
407 >        assertSame(a, c.getRoot());
408      }
409  
410      /**
411 <     * tryComplete causes completion if pending count is zero
411 >     * tryComplete decrements pending count unless zero, in which case
412 >     * causes completion
413       */
414 <    public void testTryComplete1() {
415 <        NoopCountedCompleter a = new NoopCountedCompleter();
414 >    public void testTryComplete() {
415 >        NoopCC a = new NoopCC();
416          assertEquals(0, a.getPendingCount());
417 +        int n = 3;
418 +        a.setPendingCount(n);
419 +        for (; n > 0; n--) {
420 +            assertEquals(n, a.getPendingCount());
421 +            a.tryComplete();
422 +            a.checkIncomplete();
423 +            assertEquals(n - 1, a.getPendingCount());
424 +        }
425          a.tryComplete();
426 <        assertTrue(a.post);
427 <        assertTrue(a.isDone());
426 >        assertEquals(0, a.computeN());
427 >        assertEquals(1, a.onCompletionN());
428 >        assertEquals(0, a.onExceptionalCompletionN());
429 >        assertEquals(0, a.setRawResultN());
430 >        checkCompletedNormally(a);
431      }
432  
433      /**
434 <     * propagateCompletion causes completion without invoking
435 <     * onCompletion if pending count is zero
434 >     * propagateCompletion decrements pending count unless zero, in
435 >     * which case causes completion, without invoking onCompletion
436       */
437      public void testPropagateCompletion() {
438 <        NoopCountedCompleter a = new NoopCountedCompleter();
438 >        NoopCC a = new NoopCC();
439          assertEquals(0, a.getPendingCount());
440 +        int n = 3;
441 +        a.setPendingCount(n);
442 +        for (; n > 0; n--) {
443 +            assertEquals(n, a.getPendingCount());
444 +            a.propagateCompletion();
445 +            a.checkIncomplete();
446 +            assertEquals(n - 1, a.getPendingCount());
447 +        }
448          a.propagateCompletion();
449 <        assertFalse(a.post);
450 <        assertTrue(a.isDone());
451 <    }
452 <
453 <    /**
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());
449 >        assertEquals(0, a.computeN());
450 >        assertEquals(0, a.onCompletionN());
451 >        assertEquals(0, a.onExceptionalCompletionN());
452 >        assertEquals(0, a.setRawResultN());
453 >        checkCompletedNormally(a);
454      }
455  
456      /**
457       * firstComplete returns this if pending count is zero else null
458       */
459      public void testFirstComplete() {
460 <        NoopCountedCompleter a = new NoopCountedCompleter();
460 >        NoopCC a = new NoopCC();
461          a.setPendingCount(1);
462          assertNull(a.firstComplete());
463 <        assertEquals(a, a.firstComplete());
463 >        a.checkIncomplete();
464 >        assertSame(a, a.firstComplete());
465 >        a.checkIncomplete();
466      }
467  
468      /**
# Line 370 | Line 470 | public class CountedCompleterTest extend
470       * zero else null
471       */
472      public void testNextComplete() {
473 <        NoopCountedCompleter a = new NoopCountedCompleter();
474 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
473 >        NoopCC a = new NoopCC();
474 >        NoopCC b = new NoopCC(a);
475          a.setPendingCount(1);
476          b.setPendingCount(1);
477          assertNull(b.firstComplete());
478 <        CountedCompleter c = b.firstComplete();
479 <        assertEquals(b, c);
480 <        CountedCompleter d = c.nextComplete();
481 <        assertNull(d);
482 <        CountedCompleter e = c.nextComplete();
483 <        assertEquals(a, e);
478 >        assertSame(b, b.firstComplete());
479 >        assertNull(b.nextComplete());
480 >        a.checkIncomplete();
481 >        b.checkIncomplete();
482 >        assertSame(a, b.nextComplete());
483 >        assertSame(a, b.nextComplete());
484 >        a.checkIncomplete();
485 >        b.checkIncomplete();
486 >        assertNull(a.nextComplete());
487 >        b.checkIncomplete();
488 >        checkCompletedNormally(a);
489      }
490  
491      /**
492       * quietlyCompleteRoot completes root task
493       */
494      public void testQuietlyCompleteRoot() {
495 <        NoopCountedCompleter a = new NoopCountedCompleter();
496 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
495 >        NoopCC a = new NoopCC();
496 >        NoopCC b = new NoopCC(a);
497 >        NoopCC c = new NoopCC(b);
498          a.setPendingCount(1);
499          b.setPendingCount(1);
500 <        b.quietlyCompleteRoot();
500 >        c.setPendingCount(1);
501 >        c.quietlyCompleteRoot();
502          assertTrue(a.isDone());
503          assertFalse(b.isDone());
504 +        assertFalse(c.isDone());
505      }
506  
507      // Invocation tests use some interdependent task classes
508      // to better test propagation etc
509  
510 <
511 <    // Version of Fibonacci with different classes for left vs right forks
512 <    abstract static class CCF extends CountedCompleter {
510 >    /**
511 >     * Version of Fibonacci with different classes for left vs right forks
512 >     */
513 >    abstract class CCF extends CheckedCC {
514          int number;
515          int rnumber;
516  
# Line 410 | Line 519 | public class CountedCompleterTest extend
519              this.number = n;
520          }
521  
522 <        public final void compute() {
414 <            CountedCompleter p;
522 >        protected final void realCompute() {
523              CCF f = this;
524              int n = number;
525              while (n >= 2) {
526                  new RCCF(f, n - 2).fork();
527                  f = new LCCF(f, --n);
528              }
529 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
529 >            f.complete(null);
530          }
531      }
532  
533 <    static final class LCCF extends CCF {
533 >    final class LCCF extends CCF {
534 >        public LCCF(int n) { this(null, n); }
535          public LCCF(CountedCompleter parent, int n) {
536              super(parent, n);
537          }
538          public final void onCompletion(CountedCompleter caller) {
539 +            super.onCompletion(caller);
540              CCF p = (CCF)getCompleter();
541              int n = number + rnumber;
542              if (p != null)
# Line 440 | Line 545 | public class CountedCompleterTest extend
545                  number = n;
546          }
547      }
548 <    static final class RCCF extends CCF {
548 >    final class RCCF extends CCF {
549          public RCCF(CountedCompleter parent, int n) {
550              super(parent, n);
551          }
552          public final void onCompletion(CountedCompleter caller) {
553 +            super.onCompletion(caller);
554              CCF p = (CCF)getCompleter();
555              int n = number + rnumber;
556              if (p != null)
# Line 455 | Line 561 | public class CountedCompleterTest extend
561      }
562  
563      // Version of CCF with forced failure in left completions
564 <    abstract static class FailingCCF extends CountedCompleter {
564 >    abstract class FailingCCF extends CheckedCC {
565          int number;
566          int rnumber;
567  
# Line 464 | Line 570 | public class CountedCompleterTest extend
570              this.number = n;
571          }
572  
573 <        public final void compute() {
468 <            CountedCompleter p;
573 >        protected final void realCompute() {
574              FailingCCF f = this;
575              int n = number;
576              while (n >= 2) {
577                  new RFCCF(f, n - 2).fork();
578                  f = new LFCCF(f, --n);
579              }
580 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
580 >            f.complete(null);
581          }
582      }
583  
584 <    static final class LFCCF extends FailingCCF {
584 >    final class LFCCF extends FailingCCF {
585 >        public LFCCF(int n) { this(null, n); }
586          public LFCCF(CountedCompleter parent, int n) {
587              super(parent, n);
588          }
589          public final void onCompletion(CountedCompleter caller) {
590 +            super.onCompletion(caller);
591              FailingCCF p = (FailingCCF)getCompleter();
592              int n = number + rnumber;
593              if (p != null)
# Line 494 | Line 596 | public class CountedCompleterTest extend
596                  number = n;
597          }
598      }
599 <    static final class RFCCF extends FailingCCF {
599 >    final class RFCCF extends FailingCCF {
600          public RFCCF(CountedCompleter parent, int n) {
601              super(parent, n);
602          }
603          public final void onCompletion(CountedCompleter caller) {
604 +            super.onCompletion(caller);
605              completeExceptionally(new FJException());
606          }
607      }
# Line 511 | Line 614 | public class CountedCompleterTest extend
614      public void testInvoke() {
615          ForkJoinTask a = new CheckedRecursiveAction() {
616              protected void realCompute() {
617 <                CCF f = new LCCF(null, 8);
617 >                CCF f = new LCCF(8);
618                  assertNull(f.invoke());
619                  assertEquals(21, f.number);
620                  checkCompletedNormally(f);
# Line 527 | Line 630 | public class CountedCompleterTest extend
630      public void testQuietlyInvoke() {
631          ForkJoinTask a = new CheckedRecursiveAction() {
632              protected void realCompute() {
633 <                CCF f = new LCCF(null, 8);
633 >                CCF f = new LCCF(8);
634                  f.quietlyInvoke();
635                  assertEquals(21, f.number);
636                  checkCompletedNormally(f);
# Line 541 | Line 644 | public class CountedCompleterTest extend
644      public void testForkJoin() {
645          ForkJoinTask a = new CheckedRecursiveAction() {
646              protected void realCompute() {
647 <                CCF f = new LCCF(null, 8);
647 >                CCF f = new LCCF(8);
648                  assertSame(f, f.fork());
649                  assertNull(f.join());
650                  assertEquals(21, f.number);
# Line 556 | Line 659 | public class CountedCompleterTest extend
659      public void testForkGet() {
660          ForkJoinTask a = new CheckedRecursiveAction() {
661              protected void realCompute() throws Exception {
662 <                CCF f = new LCCF(null, 8);
662 >                CCF f = new LCCF(8);
663                  assertSame(f, f.fork());
664                  assertNull(f.get());
665                  assertEquals(21, f.number);
# Line 571 | Line 674 | public class CountedCompleterTest extend
674      public void testForkTimedGet() {
675          ForkJoinTask a = new CheckedRecursiveAction() {
676              protected void realCompute() throws Exception {
677 <                CCF f = new LCCF(null, 8);
677 >                CCF f = new LCCF(8);
678                  assertSame(f, f.fork());
679                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
680                  assertEquals(21, f.number);
# Line 586 | Line 689 | public class CountedCompleterTest extend
689      public void testForkTimedGetNPE() {
690          ForkJoinTask a = new CheckedRecursiveAction() {
691              protected void realCompute() throws Exception {
692 <                CCF f = new LCCF(null, 8);
692 >                CCF f = new LCCF(8);
693                  assertSame(f, f.fork());
694                  try {
695                      f.get(5L, null);
# Line 602 | Line 705 | public class CountedCompleterTest extend
705      public void testForkQuietlyJoin() {
706          ForkJoinTask a = new CheckedRecursiveAction() {
707              protected void realCompute() {
708 <                CCF f = new LCCF(null, 8);
708 >                CCF f = new LCCF(8);
709                  assertSame(f, f.fork());
710                  f.quietlyJoin();
711                  assertEquals(21, f.number);
# Line 618 | Line 721 | public class CountedCompleterTest extend
721      public void testForkHelpQuiesce() {
722          ForkJoinTask a = new CheckedRecursiveAction() {
723              protected void realCompute() {
724 <                CCF f = new LCCF(null, 8);
724 >                CCF f = new LCCF(8);
725                  assertSame(f, f.fork());
726                  helpQuiesce();
727                  assertEquals(21, f.number);
# Line 634 | Line 737 | public class CountedCompleterTest extend
737      public void testAbnormalInvoke() {
738          ForkJoinTask a = new CheckedRecursiveAction() {
739              protected void realCompute() {
740 <                FailingCCF f = new LFCCF(null, 8);
740 >                FailingCCF f = new LFCCF(8);
741                  try {
742                      f.invoke();
743                      shouldThrow();
# Line 651 | Line 754 | public class CountedCompleterTest extend
754      public void testAbnormalQuietlyInvoke() {
755          ForkJoinTask a = new CheckedRecursiveAction() {
756              protected void realCompute() {
757 <                FailingCCF f = new LFCCF(null, 8);
757 >                FailingCCF f = new LFCCF(8);
758                  f.quietlyInvoke();
759                  assertTrue(f.getException() instanceof FJException);
760                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 768 | public class CountedCompleterTest extend
768      public void testAbnormalForkJoin() {
769          ForkJoinTask a = new CheckedRecursiveAction() {
770              protected void realCompute() {
771 <                FailingCCF f = new LFCCF(null, 8);
771 >                FailingCCF f = new LFCCF(8);
772                  assertSame(f, f.fork());
773                  try {
774                      f.join();
# Line 683 | Line 786 | public class CountedCompleterTest extend
786      public void testAbnormalForkGet() {
787          ForkJoinTask a = new CheckedRecursiveAction() {
788              protected void realCompute() throws Exception {
789 <                FailingCCF f = new LFCCF(null, 8);
789 >                FailingCCF f = new LFCCF(8);
790                  assertSame(f, f.fork());
791                  try {
792                      f.get();
# Line 703 | Line 806 | public class CountedCompleterTest extend
806      public void testAbnormalForkTimedGet() {
807          ForkJoinTask a = new CheckedRecursiveAction() {
808              protected void realCompute() throws Exception {
809 <                FailingCCF f = new LFCCF(null, 8);
809 >                FailingCCF f = new LFCCF(8);
810                  assertSame(f, f.fork());
811                  try {
812                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 826 | public class CountedCompleterTest extend
826      public void testAbnormalForkQuietlyJoin() {
827          ForkJoinTask a = new CheckedRecursiveAction() {
828              protected void realCompute() {
829 <                FailingCCF f = new LFCCF(null, 8);
829 >                FailingCCF f = new LFCCF(8);
830                  assertSame(f, f.fork());
831                  f.quietlyJoin();
832                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 841 | public class CountedCompleterTest extend
841      public void testCancelledInvoke() {
842          ForkJoinTask a = new CheckedRecursiveAction() {
843              protected void realCompute() {
844 <                CCF f = new LCCF(null, 8);
844 >                CCF f = new LCCF(8);
845                  assertTrue(f.cancel(true));
846                  try {
847                      f.invoke();
# Line 756 | Line 859 | public class CountedCompleterTest extend
859      public void testCancelledForkJoin() {
860          ForkJoinTask a = new CheckedRecursiveAction() {
861              protected void realCompute() {
862 <                CCF f = new LCCF(null, 8);
862 >                CCF f = new LCCF(8);
863                  assertTrue(f.cancel(true));
864                  assertSame(f, f.fork());
865                  try {
# Line 775 | Line 878 | public class CountedCompleterTest extend
878      public void testCancelledForkGet() {
879          ForkJoinTask a = new CheckedRecursiveAction() {
880              protected void realCompute() throws Exception {
881 <                CCF f = new LCCF(null, 8);
881 >                CCF f = new LCCF(8);
882                  assertTrue(f.cancel(true));
883                  assertSame(f, f.fork());
884                  try {
# Line 794 | Line 897 | public class CountedCompleterTest extend
897      public void testCancelledForkTimedGet() throws Exception {
898          ForkJoinTask a = new CheckedRecursiveAction() {
899              protected void realCompute() throws Exception {
900 <                CCF f = new LCCF(null, 8);
900 >                CCF f = new LCCF(8);
901                  assertTrue(f.cancel(true));
902                  assertSame(f, f.fork());
903                  try {
# Line 813 | Line 916 | public class CountedCompleterTest extend
916      public void testCancelledForkQuietlyJoin() {
917          ForkJoinTask a = new CheckedRecursiveAction() {
918              protected void realCompute() {
919 <                CCF f = new LCCF(null, 8);
919 >                CCF f = new LCCF(8);
920                  assertTrue(f.cancel(true));
921                  assertSame(f, f.fork());
922                  f.quietlyJoin();
# Line 885 | Line 988 | public class CountedCompleterTest extend
988      public void testCompleteExceptionally2() {
989          ForkJoinTask a = new CheckedRecursiveAction() {
990              protected void realCompute() {
991 <                CCF f = new LCCF(null, 8);
992 <                f.completeExceptionally(new FJException());
993 <                try {
994 <                    f.invoke();
995 <                    shouldThrow();
996 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
991 >                CCF n = new LCCF(8);
992 >                CCF f = new LCCF(n, 8);
993 >                FJException ex = new FJException();
994 >                f.completeExceptionally(ex);
995 >                f.checkCompletedExceptionally(ex);
996 >                n.checkCompletedExceptionally(ex);
997              }};
998          testInvokeOnPool(mainPool(), a);
999      }
# Line 903 | Line 1004 | public class CountedCompleterTest extend
1004      public void testInvokeAll2() {
1005          ForkJoinTask a = new CheckedRecursiveAction() {
1006              protected void realCompute() {
1007 <                CCF f = new LCCF(null, 8);
1008 <                CCF g = new LCCF(null, 9);
1007 >                CCF f = new LCCF(8);
1008 >                CCF g = new LCCF(9);
1009                  invokeAll(f, g);
1010                  assertEquals(21, f.number);
1011                  assertEquals(34, g.number);
# Line 920 | Line 1021 | public class CountedCompleterTest extend
1021      public void testInvokeAll1() {
1022          ForkJoinTask a = new CheckedRecursiveAction() {
1023              protected void realCompute() {
1024 <                CCF f = new LCCF(null, 8);
1024 >                CCF f = new LCCF(8);
1025                  invokeAll(f);
1026                  checkCompletedNormally(f);
1027                  assertEquals(21, f.number);
# Line 934 | Line 1035 | public class CountedCompleterTest extend
1035      public void testInvokeAll3() {
1036          ForkJoinTask a = new CheckedRecursiveAction() {
1037              protected void realCompute() {
1038 <                CCF f = new LCCF(null, 8);
1039 <                CCF g = new LCCF(null, 9);
1040 <                CCF h = new LCCF(null, 7);
1038 >                CCF f = new LCCF(8);
1039 >                CCF g = new LCCF(9);
1040 >                CCF h = new LCCF(7);
1041                  invokeAll(f, g, h);
1042                  assertEquals(21, f.number);
1043                  assertEquals(34, g.number);
# Line 954 | Line 1055 | public class CountedCompleterTest extend
1055      public void testInvokeAllCollection() {
1056          ForkJoinTask a = new CheckedRecursiveAction() {
1057              protected void realCompute() {
1058 <                CCF f = new LCCF(null, 8);
1059 <                CCF g = new LCCF(null, 9);
1060 <                CCF h = new LCCF(null, 7);
1058 >                CCF f = new LCCF(8);
1059 >                CCF g = new LCCF(9);
1060 >                CCF h = new LCCF(7);
1061                  HashSet set = new HashSet();
1062                  set.add(f);
1063                  set.add(g);
# Line 978 | Line 1079 | public class CountedCompleterTest extend
1079      public void testInvokeAllNPE() {
1080          ForkJoinTask a = new CheckedRecursiveAction() {
1081              protected void realCompute() {
1082 <                CCF f = new LCCF(null, 8);
1083 <                CCF g = new LCCF(null, 9);
1082 >                CCF f = new LCCF(8);
1083 >                CCF g = new LCCF(9);
1084                  CCF h = null;
1085                  try {
1086                      invokeAll(f, g, h);
# Line 995 | Line 1096 | public class CountedCompleterTest extend
1096      public void testAbnormalInvokeAll2() {
1097          ForkJoinTask a = new CheckedRecursiveAction() {
1098              protected void realCompute() {
1099 <                CCF f = new LCCF(null, 8);
1100 <                FailingCCF g = new LFCCF(null, 9);
1099 >                CCF f = new LCCF(8);
1100 >                FailingCCF g = new LFCCF(9);
1101                  try {
1102                      invokeAll(f, g);
1103                      shouldThrow();
# Line 1013 | Line 1114 | public class CountedCompleterTest extend
1114      public void testAbnormalInvokeAll1() {
1115          ForkJoinTask a = new CheckedRecursiveAction() {
1116              protected void realCompute() {
1117 <                FailingCCF g = new LFCCF(null, 9);
1117 >                FailingCCF g = new LFCCF(9);
1118                  try {
1119                      invokeAll(g);
1120                      shouldThrow();
# Line 1030 | Line 1131 | public class CountedCompleterTest extend
1131      public void testAbnormalInvokeAll3() {
1132          ForkJoinTask a = new CheckedRecursiveAction() {
1133              protected void realCompute() {
1134 <                CCF f = new LCCF(null, 8);
1135 <                FailingCCF g = new LFCCF(null, 9);
1136 <                CCF h = new LCCF(null, 7);
1134 >                CCF f = new LCCF(8);
1135 >                FailingCCF g = new LFCCF(9);
1136 >                CCF h = new LCCF(7);
1137                  try {
1138                      invokeAll(f, g, h);
1139                      shouldThrow();
# Line 1044 | Line 1145 | public class CountedCompleterTest extend
1145      }
1146  
1147      /**
1148 <     * invokeAll(collection)  throws exception if any task does
1148 >     * invokeAll(collection) throws exception if any task does
1149       */
1150      public void testAbnormalInvokeAllCollection() {
1151          ForkJoinTask a = new CheckedRecursiveAction() {
1152              protected void realCompute() {
1153 <                FailingCCF f = new LFCCF(null, 8);
1154 <                CCF g = new LCCF(null, 9);
1155 <                CCF h = new LCCF(null, 7);
1153 >                FailingCCF f = new LFCCF(8);
1154 >                CCF g = new LCCF(9);
1155 >                CCF h = new LCCF(7);
1156                  HashSet set = new HashSet();
1157                  set.add(f);
1158                  set.add(g);
# Line 1073 | Line 1174 | public class CountedCompleterTest extend
1174      public void testTryUnfork() {
1175          ForkJoinTask a = new CheckedRecursiveAction() {
1176              protected void realCompute() {
1177 <                CCF g = new LCCF(null, 9);
1177 >                CCF g = new LCCF(9);
1178                  assertSame(g, g.fork());
1179 <                CCF f = new LCCF(null, 8);
1179 >                CCF f = new LCCF(8);
1180                  assertSame(f, f.fork());
1181                  assertTrue(f.tryUnfork());
1182                  helpQuiesce();
# Line 1092 | Line 1193 | public class CountedCompleterTest extend
1193      public void testGetSurplusQueuedTaskCount() {
1194          ForkJoinTask a = new CheckedRecursiveAction() {
1195              protected void realCompute() {
1196 <                CCF h = new LCCF(null, 7);
1196 >                CCF h = new LCCF(7);
1197                  assertSame(h, h.fork());
1198 <                CCF g = new LCCF(null, 9);
1198 >                CCF g = new LCCF(9);
1199                  assertSame(g, g.fork());
1200 <                CCF f = new LCCF(null, 8);
1200 >                CCF f = new LCCF(8);
1201                  assertSame(f, f.fork());
1202                  assertTrue(getSurplusQueuedTaskCount() > 0);
1203                  helpQuiesce();
# Line 1114 | Line 1215 | public class CountedCompleterTest extend
1215      public void testPeekNextLocalTask() {
1216          ForkJoinTask a = new CheckedRecursiveAction() {
1217              protected void realCompute() {
1218 <                CCF g = new LCCF(null, 9);
1218 >                CCF g = new LCCF(9);
1219                  assertSame(g, g.fork());
1220 <                CCF f = new LCCF(null, 8);
1220 >                CCF f = new LCCF(8);
1221                  assertSame(f, f.fork());
1222                  assertSame(f, peekNextLocalTask());
1223                  assertNull(f.join());
# Line 1134 | Line 1235 | public class CountedCompleterTest extend
1235      public void testPollNextLocalTask() {
1236          ForkJoinTask a = new CheckedRecursiveAction() {
1237              protected void realCompute() {
1238 <                CCF g = new LCCF(null, 9);
1238 >                CCF g = new LCCF(9);
1239                  assertSame(g, g.fork());
1240 <                CCF f = new LCCF(null, 8);
1240 >                CCF f = new LCCF(8);
1241                  assertSame(f, f.fork());
1242                  assertSame(f, pollNextLocalTask());
1243                  helpQuiesce();
# Line 1153 | Line 1254 | public class CountedCompleterTest extend
1254      public void testPollTask() {
1255          ForkJoinTask a = new CheckedRecursiveAction() {
1256              protected void realCompute() {
1257 <                CCF g = new LCCF(null, 9);
1257 >                CCF g = new LCCF(9);
1258                  assertSame(g, g.fork());
1259 <                CCF f = new LCCF(null, 8);
1259 >                CCF f = new LCCF(8);
1260                  assertSame(f, f.fork());
1261                  assertSame(f, pollTask());
1262                  helpQuiesce();
# Line 1171 | Line 1272 | public class CountedCompleterTest extend
1272      public void testPeekNextLocalTaskAsync() {
1273          ForkJoinTask a = new CheckedRecursiveAction() {
1274              protected void realCompute() {
1275 <                CCF g = new LCCF(null, 9);
1275 >                CCF g = new LCCF(9);
1276                  assertSame(g, g.fork());
1277 <                CCF f = new LCCF(null, 8);
1277 >                CCF f = new LCCF(8);
1278                  assertSame(f, f.fork());
1279                  assertSame(g, peekNextLocalTask());
1280                  assertNull(f.join());
# Line 1192 | Line 1293 | public class CountedCompleterTest extend
1293      public void testPollNextLocalTaskAsync() {
1294          ForkJoinTask a = new CheckedRecursiveAction() {
1295              protected void realCompute() {
1296 <                CCF g = new LCCF(null, 9);
1296 >                CCF g = new LCCF(9);
1297                  assertSame(g, g.fork());
1298 <                CCF f = new LCCF(null, 8);
1298 >                CCF f = new LCCF(8);
1299                  assertSame(f, f.fork());
1300                  assertSame(g, pollNextLocalTask());
1301                  helpQuiesce();
# Line 1212 | Line 1313 | public class CountedCompleterTest extend
1313      public void testPollTaskAsync() {
1314          ForkJoinTask a = new CheckedRecursiveAction() {
1315              protected void realCompute() {
1316 <                CCF g = new LCCF(null, 9);
1316 >                CCF g = new LCCF(9);
1317                  assertSame(g, g.fork());
1318 <                CCF f = new LCCF(null, 8);
1318 >                CCF f = new LCCF(8);
1319                  assertSame(f, f.fork());
1320                  assertSame(g, pollTask());
1321                  helpQuiesce();
# Line 1235 | Line 1336 | public class CountedCompleterTest extend
1336      public void testInvokeSingleton() {
1337          ForkJoinTask a = new CheckedRecursiveAction() {
1338              protected void realCompute() {
1339 <                CCF f = new LCCF(null, 8);
1339 >                CCF f = new LCCF(8);
1340                  assertNull(f.invoke());
1341                  assertEquals(21, f.number);
1342                  checkCompletedNormally(f);
# Line 1251 | Line 1352 | public class CountedCompleterTest extend
1352      public void testQuietlyInvokeSingleton() {
1353          ForkJoinTask a = new CheckedRecursiveAction() {
1354              protected void realCompute() {
1355 <                CCF f = new LCCF(null, 8);
1355 >                CCF f = new LCCF(8);
1356                  f.quietlyInvoke();
1357                  assertEquals(21, f.number);
1358                  checkCompletedNormally(f);
# Line 1265 | Line 1366 | public class CountedCompleterTest extend
1366      public void testForkJoinSingleton() {
1367          ForkJoinTask a = new CheckedRecursiveAction() {
1368              protected void realCompute() {
1369 <                CCF f = new LCCF(null, 8);
1369 >                CCF f = new LCCF(8);
1370                  assertSame(f, f.fork());
1371                  assertNull(f.join());
1372                  assertEquals(21, f.number);
# Line 1280 | Line 1381 | public class CountedCompleterTest extend
1381      public void testForkGetSingleton() {
1382          ForkJoinTask a = new CheckedRecursiveAction() {
1383              protected void realCompute() throws Exception {
1384 <                CCF f = new LCCF(null, 8);
1384 >                CCF f = new LCCF(8);
1385                  assertSame(f, f.fork());
1386                  assertNull(f.get());
1387                  assertEquals(21, f.number);
# Line 1295 | Line 1396 | public class CountedCompleterTest extend
1396      public void testForkTimedGetSingleton() {
1397          ForkJoinTask a = new CheckedRecursiveAction() {
1398              protected void realCompute() throws Exception {
1399 <                CCF f = new LCCF(null, 8);
1399 >                CCF f = new LCCF(8);
1400                  assertSame(f, f.fork());
1401                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1402                  assertEquals(21, f.number);
# Line 1310 | Line 1411 | public class CountedCompleterTest extend
1411      public void testForkTimedGetNPESingleton() {
1412          ForkJoinTask a = new CheckedRecursiveAction() {
1413              protected void realCompute() throws Exception {
1414 <                CCF f = new LCCF(null, 8);
1414 >                CCF f = new LCCF(8);
1415                  assertSame(f, f.fork());
1416                  try {
1417                      f.get(5L, null);
# Line 1326 | Line 1427 | public class CountedCompleterTest extend
1427      public void testForkQuietlyJoinSingleton() {
1428          ForkJoinTask a = new CheckedRecursiveAction() {
1429              protected void realCompute() {
1430 <                CCF f = new LCCF(null, 8);
1430 >                CCF f = new LCCF(8);
1431                  assertSame(f, f.fork());
1432                  f.quietlyJoin();
1433                  assertEquals(21, f.number);
# Line 1342 | Line 1443 | public class CountedCompleterTest extend
1443      public void testForkHelpQuiesceSingleton() {
1444          ForkJoinTask a = new CheckedRecursiveAction() {
1445              protected void realCompute() {
1446 <                CCF f = new LCCF(null, 8);
1446 >                CCF f = new LCCF(8);
1447                  assertSame(f, f.fork());
1448                  helpQuiesce();
1449                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1459 | public class CountedCompleterTest extend
1459      public void testAbnormalInvokeSingleton() {
1460          ForkJoinTask a = new CheckedRecursiveAction() {
1461              protected void realCompute() {
1462 <                FailingCCF f = new LFCCF(null, 8);
1462 >                FailingCCF f = new LFCCF(8);
1463                  try {
1464                      f.invoke();
1465                      shouldThrow();
# Line 1375 | Line 1476 | public class CountedCompleterTest extend
1476      public void testAbnormalQuietlyInvokeSingleton() {
1477          ForkJoinTask a = new CheckedRecursiveAction() {
1478              protected void realCompute() {
1479 <                FailingCCF f = new LFCCF(null, 8);
1479 >                FailingCCF f = new LFCCF(8);
1480                  f.quietlyInvoke();
1481                  assertTrue(f.getException() instanceof FJException);
1482                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1490 | public class CountedCompleterTest extend
1490      public void testAbnormalForkJoinSingleton() {
1491          ForkJoinTask a = new CheckedRecursiveAction() {
1492              protected void realCompute() {
1493 <                FailingCCF f = new LFCCF(null, 8);
1493 >                FailingCCF f = new LFCCF(8);
1494                  assertSame(f, f.fork());
1495                  try {
1496                      f.join();
# Line 1407 | Line 1508 | public class CountedCompleterTest extend
1508      public void testAbnormalForkGetSingleton() {
1509          ForkJoinTask a = new CheckedRecursiveAction() {
1510              protected void realCompute() throws Exception {
1511 <                FailingCCF f = new LFCCF(null, 8);
1511 >                FailingCCF f = new LFCCF(8);
1512                  assertSame(f, f.fork());
1513                  try {
1514                      f.get();
# Line 1427 | Line 1528 | public class CountedCompleterTest extend
1528      public void testAbnormalForkTimedGetSingleton() {
1529          ForkJoinTask a = new CheckedRecursiveAction() {
1530              protected void realCompute() throws Exception {
1531 <                FailingCCF f = new LFCCF(null, 8);
1531 >                FailingCCF f = new LFCCF(8);
1532                  assertSame(f, f.fork());
1533                  try {
1534                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1548 | public class CountedCompleterTest extend
1548      public void testAbnormalForkQuietlyJoinSingleton() {
1549          ForkJoinTask a = new CheckedRecursiveAction() {
1550              protected void realCompute() {
1551 <                FailingCCF f = new LFCCF(null, 8);
1551 >                FailingCCF f = new LFCCF(8);
1552                  assertSame(f, f.fork());
1553                  f.quietlyJoin();
1554                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1563 | public class CountedCompleterTest extend
1563      public void testCancelledInvokeSingleton() {
1564          ForkJoinTask a = new CheckedRecursiveAction() {
1565              protected void realCompute() {
1566 <                CCF f = new LCCF(null, 8);
1566 >                CCF f = new LCCF(8);
1567                  assertTrue(f.cancel(true));
1568                  try {
1569                      f.invoke();
# Line 1480 | Line 1581 | public class CountedCompleterTest extend
1581      public void testCancelledForkJoinSingleton() {
1582          ForkJoinTask a = new CheckedRecursiveAction() {
1583              protected void realCompute() {
1584 <                CCF f = new LCCF(null, 8);
1584 >                CCF f = new LCCF(8);
1585                  assertTrue(f.cancel(true));
1586                  assertSame(f, f.fork());
1587                  try {
# Line 1499 | Line 1600 | public class CountedCompleterTest extend
1600      public void testCancelledForkGetSingleton() {
1601          ForkJoinTask a = new CheckedRecursiveAction() {
1602              protected void realCompute() throws Exception {
1603 <                CCF f = new LCCF(null, 8);
1603 >                CCF f = new LCCF(8);
1604                  assertTrue(f.cancel(true));
1605                  assertSame(f, f.fork());
1606                  try {
# Line 1518 | Line 1619 | public class CountedCompleterTest extend
1619      public void testCancelledForkTimedGetSingleton() throws Exception {
1620          ForkJoinTask a = new CheckedRecursiveAction() {
1621              protected void realCompute() throws Exception {
1622 <                CCF f = new LCCF(null, 8);
1622 >                CCF f = new LCCF(8);
1623                  assertTrue(f.cancel(true));
1624                  assertSame(f, f.fork());
1625                  try {
# Line 1537 | Line 1638 | public class CountedCompleterTest extend
1638      public void testCancelledForkQuietlyJoinSingleton() {
1639          ForkJoinTask a = new CheckedRecursiveAction() {
1640              protected void realCompute() {
1641 <                CCF f = new LCCF(null, 8);
1641 >                CCF f = new LCCF(8);
1642                  assertTrue(f.cancel(true));
1643                  assertSame(f, f.fork());
1644                  f.quietlyJoin();
# Line 1552 | Line 1653 | public class CountedCompleterTest extend
1653      public void testCompleteExceptionallySingleton() {
1654          ForkJoinTask a = new CheckedRecursiveAction() {
1655              protected void realCompute() {
1656 <                CCF f = new LCCF(null, 8);
1657 <                f.completeExceptionally(new FJException());
1658 <                try {
1659 <                    f.invoke();
1660 <                    shouldThrow();
1661 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1656 >                CCF n = new LCCF(8);
1657 >                CCF f = new LCCF(n, 8);
1658 >                FJException ex = new FJException();
1659 >                f.completeExceptionally(ex);
1660 >                f.checkCompletedExceptionally(ex);
1661 >                n.checkCompletedExceptionally(ex);
1662              }};
1663          testInvokeOnPool(singletonPool(), a);
1664      }
# Line 1570 | Line 1669 | public class CountedCompleterTest extend
1669      public void testInvokeAll2Singleton() {
1670          ForkJoinTask a = new CheckedRecursiveAction() {
1671              protected void realCompute() {
1672 <                CCF f = new LCCF(null, 8);
1673 <                CCF g = new LCCF(null, 9);
1672 >                CCF f = new LCCF(8);
1673 >                CCF g = new LCCF(9);
1674                  invokeAll(f, g);
1675                  assertEquals(21, f.number);
1676                  assertEquals(34, g.number);
# Line 1587 | Line 1686 | public class CountedCompleterTest extend
1686      public void testInvokeAll1Singleton() {
1687          ForkJoinTask a = new CheckedRecursiveAction() {
1688              protected void realCompute() {
1689 <                CCF f = new LCCF(null, 8);
1689 >                CCF f = new LCCF(8);
1690                  invokeAll(f);
1691                  checkCompletedNormally(f);
1692                  assertEquals(21, f.number);
# Line 1601 | Line 1700 | public class CountedCompleterTest extend
1700      public void testInvokeAll3Singleton() {
1701          ForkJoinTask a = new CheckedRecursiveAction() {
1702              protected void realCompute() {
1703 <                CCF f = new LCCF(null, 8);
1704 <                CCF g = new LCCF(null, 9);
1705 <                CCF h = new LCCF(null, 7);
1703 >                CCF f = new LCCF(8);
1704 >                CCF g = new LCCF(9);
1705 >                CCF h = new LCCF(7);
1706                  invokeAll(f, g, h);
1707                  assertEquals(21, f.number);
1708                  assertEquals(34, g.number);
# Line 1621 | Line 1720 | public class CountedCompleterTest extend
1720      public void testInvokeAllCollectionSingleton() {
1721          ForkJoinTask a = new CheckedRecursiveAction() {
1722              protected void realCompute() {
1723 <                CCF f = new LCCF(null, 8);
1724 <                CCF g = new LCCF(null, 9);
1725 <                CCF h = new LCCF(null, 7);
1723 >                CCF f = new LCCF(8);
1724 >                CCF g = new LCCF(9);
1725 >                CCF h = new LCCF(7);
1726                  HashSet set = new HashSet();
1727                  set.add(f);
1728                  set.add(g);
# Line 1645 | Line 1744 | public class CountedCompleterTest extend
1744      public void testInvokeAllNPESingleton() {
1745          ForkJoinTask a = new CheckedRecursiveAction() {
1746              protected void realCompute() {
1747 <                CCF f = new LCCF(null, 8);
1748 <                CCF g = new LCCF(null, 9);
1747 >                CCF f = new LCCF(8);
1748 >                CCF g = new LCCF(9);
1749                  CCF h = null;
1750                  try {
1751                      invokeAll(f, g, h);
# Line 1662 | Line 1761 | public class CountedCompleterTest extend
1761      public void testAbnormalInvokeAll2Singleton() {
1762          ForkJoinTask a = new CheckedRecursiveAction() {
1763              protected void realCompute() {
1764 <                CCF f = new LCCF(null, 8);
1765 <                FailingCCF g = new LFCCF(null, 9);
1764 >                CCF f = new LCCF(8);
1765 >                FailingCCF g = new LFCCF(9);
1766                  try {
1767                      invokeAll(f, g);
1768                      shouldThrow();
# Line 1680 | Line 1779 | public class CountedCompleterTest extend
1779      public void testAbnormalInvokeAll1Singleton() {
1780          ForkJoinTask a = new CheckedRecursiveAction() {
1781              protected void realCompute() {
1782 <                FailingCCF g = new LFCCF(null, 9);
1782 >                FailingCCF g = new LFCCF(9);
1783                  try {
1784                      invokeAll(g);
1785                      shouldThrow();
# Line 1697 | Line 1796 | public class CountedCompleterTest extend
1796      public void testAbnormalInvokeAll3Singleton() {
1797          ForkJoinTask a = new CheckedRecursiveAction() {
1798              protected void realCompute() {
1799 <                CCF f = new LCCF(null, 8);
1800 <                FailingCCF g = new LFCCF(null, 9);
1801 <                CCF h = new LCCF(null, 7);
1799 >                CCF f = new LCCF(8);
1800 >                FailingCCF g = new LFCCF(9);
1801 >                CCF h = new LCCF(7);
1802                  try {
1803                      invokeAll(f, g, h);
1804                      shouldThrow();
# Line 1711 | Line 1810 | public class CountedCompleterTest extend
1810      }
1811  
1812      /**
1813 <     * invokeAll(collection)  throws exception if any task does
1813 >     * invokeAll(collection) throws exception if any task does
1814       */
1815      public void testAbnormalInvokeAllCollectionSingleton() {
1816          ForkJoinTask a = new CheckedRecursiveAction() {
1817              protected void realCompute() {
1818 <                FailingCCF f = new LFCCF(null, 8);
1819 <                CCF g = new LCCF(null, 9);
1820 <                CCF h = new LCCF(null, 7);
1818 >                FailingCCF f = new LFCCF(8);
1819 >                CCF g = new LCCF(9);
1820 >                CCF h = new LCCF(7);
1821                  HashSet set = new HashSet();
1822                  set.add(f);
1823                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines