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.21 by jsr166, Sun Oct 18 16:43:53 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);
230 <        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      }
303  
304      /**
305       * completeExceptionally completes exceptionally
306       */
307      public void testCompleteExceptionally() {
308 <        NoopCountedCompleter a = new NoopCountedCompleter();
309 <        assertFalse(a.isDone());
310 <        assertFalse(a.isCompletedNormally());
311 <        assertFalse(a.isCompletedAbnormally());
312 <        assertFalse(a.isCancelled());
313 <        assertNull(a.getException());
314 <        assertNull(a.getRawResult());
315 <        assertFalse(a.post);
316 <        a.completeExceptionally(new FJException());
317 <        assertFalse(a.post);
318 <        assertTrue(a.isDone());
319 <        assertFalse(a.isCompletedNormally());
320 <        assertTrue(a.isCompletedAbnormally());
321 <        assertFalse(a.isCancelled());
322 <        assertTrue(a.getException() instanceof FJException);
323 <        assertNull(a.getRawResult());
308 >        new NoopCC()
309 >            .checkCompletesExceptionally(new FJException());
310 >        new NoopCC(new NoopCC())
311 >            .checkCompletesExceptionally(new FJException());
312 >    }
313 >
314 >    /**
315 >     * completeExceptionally(null) surprisingly has the same effect as
316 >     * completeExceptionally(new RuntimeException())
317 >     */
318 >    public void testCompleteExceptionally_null() {
319 >        NoopCC a = new NoopCC();
320 >        a.completeExceptionally(null);
321 >        try {
322 >            a.invoke();
323 >            shouldThrow();
324 >        } catch (RuntimeException success) {
325 >            assertSame(success.getClass(), RuntimeException.class);
326 >            assertNull(success.getCause());
327 >            a.checkCompletedExceptionally(success);
328 >        }
329      }
330  
331      /**
332       * setPendingCount sets the reported pending count
333       */
334      public void testSetPendingCount() {
335 <        NoopCountedCompleter a = new NoopCountedCompleter();
335 >        NoopCC a = new NoopCC();
336          assertEquals(0, a.getPendingCount());
337          a.setPendingCount(1);
338          assertEquals(1, a.getPendingCount());
# Line 273 | Line 344 | public class CountedCompleterTest extend
344       * addToPendingCount adds to the reported pending count
345       */
346      public void testAddToPendingCount() {
347 <        NoopCountedCompleter a = new NoopCountedCompleter();
347 >        NoopCC a = new NoopCC();
348          assertEquals(0, a.getPendingCount());
349          a.addToPendingCount(1);
350          assertEquals(1, a.getPendingCount());
# Line 285 | Line 356 | public class CountedCompleterTest extend
356       * decrementPendingCountUnlessZero decrements reported pending
357       * count unless zero
358       */
359 <    public void testDecrementPendingCount() {
360 <        NoopCountedCompleter a = new NoopCountedCompleter();
361 <        assertEquals(0, a.getPendingCount());
362 <        a.addToPendingCount(1);
359 >    public void testDecrementPendingCountUnlessZero() {
360 >        NoopCC a = new NoopCC(null, 2);
361 >        assertEquals(2, a.getPendingCount());
362 >        assertEquals(2, a.decrementPendingCountUnlessZero());
363          assertEquals(1, a.getPendingCount());
364 <        a.decrementPendingCountUnlessZero();
364 >        assertEquals(1, a.decrementPendingCountUnlessZero());
365          assertEquals(0, a.getPendingCount());
366 <        a.decrementPendingCountUnlessZero();
366 >        assertEquals(0, a.decrementPendingCountUnlessZero());
367          assertEquals(0, a.getPendingCount());
368      }
369  
370      /**
371 +     * compareAndSetPendingCount compares and sets the reported
372 +     * pending count
373 +     */
374 +    public void testCompareAndSetPendingCount() {
375 +        NoopCC a = new NoopCC();
376 +        assertEquals(0, a.getPendingCount());
377 +        assertTrue(a.compareAndSetPendingCount(0, 1));
378 +        assertEquals(1, a.getPendingCount());
379 +        assertTrue(a.compareAndSetPendingCount(1, 2));
380 +        assertEquals(2, a.getPendingCount());
381 +        assertFalse(a.compareAndSetPendingCount(1, 3));
382 +        assertEquals(2, a.getPendingCount());
383 +    }
384 +
385 +    /**
386       * getCompleter returns parent or null if at root
387       */
388      public void testGetCompleter() {
389 <        NoopCountedCompleter a = new NoopCountedCompleter();
389 >        NoopCC a = new NoopCC();
390          assertNull(a.getCompleter());
391 <        CountedCompleter b = new NoopCountedCompleter(a);
392 <        assertEquals(a, b.getCompleter());
391 >        CountedCompleter b = new NoopCC(a);
392 >        assertSame(a, b.getCompleter());
393 >        CountedCompleter c = new NoopCC(b);
394 >        assertSame(b, c.getCompleter());
395      }
396  
397      /**
398       * getRoot returns self if no parent, else parent's root
399       */
400      public void testGetRoot() {
401 <        NoopCountedCompleter a = new NoopCountedCompleter();
402 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
403 <        assertEquals(a, a.getRoot());
404 <        assertEquals(a, b.getRoot());
401 >        NoopCC a = new NoopCC();
402 >        NoopCC b = new NoopCC(a);
403 >        NoopCC c = new NoopCC(b);
404 >        assertSame(a, a.getRoot());
405 >        assertSame(a, b.getRoot());
406 >        assertSame(a, c.getRoot());
407      }
408  
409      /**
410 <     * tryComplete causes completion if pending count is zero
410 >     * tryComplete decrements pending count unless zero, in which case
411 >     * causes completion
412       */
413 <    public void testTryComplete1() {
414 <        NoopCountedCompleter a = new NoopCountedCompleter();
413 >    public void testTryComplete() {
414 >        NoopCC a = new NoopCC();
415          assertEquals(0, a.getPendingCount());
416 +        int n = 3;
417 +        a.setPendingCount(n);
418 +        for (; n > 0; n--) {
419 +            assertEquals(n, a.getPendingCount());
420 +            a.tryComplete();
421 +            a.checkIncomplete();
422 +            assertEquals(n - 1, a.getPendingCount());
423 +        }
424          a.tryComplete();
425 <        assertTrue(a.post);
426 <        assertTrue(a.isDone());
425 >        assertEquals(0, a.computeN());
426 >        assertEquals(1, a.onCompletionN());
427 >        assertEquals(0, a.onExceptionalCompletionN());
428 >        assertEquals(0, a.setRawResultN());
429 >        checkCompletedNormally(a);
430      }
431  
432      /**
433 <     * propagateCompletion causes completion without invoking
434 <     * onCompletion if pending count is zero
433 >     * propagateCompletion decrements pending count unless zero, in
434 >     * which case causes completion, without invoking onCompletion
435       */
436      public void testPropagateCompletion() {
437 <        NoopCountedCompleter a = new NoopCountedCompleter();
437 >        NoopCC a = new NoopCC();
438          assertEquals(0, a.getPendingCount());
439 +        int n = 3;
440 +        a.setPendingCount(n);
441 +        for (; n > 0; n--) {
442 +            assertEquals(n, a.getPendingCount());
443 +            a.propagateCompletion();
444 +            a.checkIncomplete();
445 +            assertEquals(n - 1, a.getPendingCount());
446 +        }
447          a.propagateCompletion();
448 <        assertFalse(a.post);
449 <        assertTrue(a.isDone());
450 <    }
451 <
452 <    /**
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());
448 >        assertEquals(0, a.computeN());
449 >        assertEquals(0, a.onCompletionN());
450 >        assertEquals(0, a.onExceptionalCompletionN());
451 >        assertEquals(0, a.setRawResultN());
452 >        checkCompletedNormally(a);
453      }
454  
455      /**
456       * firstComplete returns this if pending count is zero else null
457       */
458      public void testFirstComplete() {
459 <        NoopCountedCompleter a = new NoopCountedCompleter();
459 >        NoopCC a = new NoopCC();
460          a.setPendingCount(1);
461          assertNull(a.firstComplete());
462 <        assertEquals(a, a.firstComplete());
462 >        a.checkIncomplete();
463 >        assertSame(a, a.firstComplete());
464 >        a.checkIncomplete();
465      }
466  
467      /**
# Line 370 | Line 469 | public class CountedCompleterTest extend
469       * zero else null
470       */
471      public void testNextComplete() {
472 <        NoopCountedCompleter a = new NoopCountedCompleter();
473 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
472 >        NoopCC a = new NoopCC();
473 >        NoopCC b = new NoopCC(a);
474          a.setPendingCount(1);
475          b.setPendingCount(1);
476          assertNull(b.firstComplete());
477 <        CountedCompleter c = b.firstComplete();
478 <        assertEquals(b, c);
479 <        CountedCompleter d = c.nextComplete();
480 <        assertNull(d);
481 <        CountedCompleter e = c.nextComplete();
482 <        assertEquals(a, e);
477 >        assertSame(b, b.firstComplete());
478 >        assertNull(b.nextComplete());
479 >        a.checkIncomplete();
480 >        b.checkIncomplete();
481 >        assertSame(a, b.nextComplete());
482 >        assertSame(a, b.nextComplete());
483 >        a.checkIncomplete();
484 >        b.checkIncomplete();
485 >        assertNull(a.nextComplete());
486 >        b.checkIncomplete();
487 >        checkCompletedNormally(a);
488      }
489  
490      /**
491       * quietlyCompleteRoot completes root task
492       */
493      public void testQuietlyCompleteRoot() {
494 <        NoopCountedCompleter a = new NoopCountedCompleter();
495 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
494 >        NoopCC a = new NoopCC();
495 >        NoopCC b = new NoopCC(a);
496 >        NoopCC c = new NoopCC(b);
497          a.setPendingCount(1);
498          b.setPendingCount(1);
499 <        b.quietlyCompleteRoot();
499 >        c.setPendingCount(1);
500 >        c.quietlyCompleteRoot();
501          assertTrue(a.isDone());
502          assertFalse(b.isDone());
503 +        assertFalse(c.isDone());
504      }
505  
506      // Invocation tests use some interdependent task classes
507      // to better test propagation etc
508  
509 <
510 <    // Version of Fibonacci with different classes for left vs right forks
511 <    abstract static class CCF extends CountedCompleter {
509 >    /**
510 >     * Version of Fibonacci with different classes for left vs right forks
511 >     */
512 >    abstract class CCF extends CheckedCC {
513          int number;
514          int rnumber;
515  
# Line 410 | Line 518 | public class CountedCompleterTest extend
518              this.number = n;
519          }
520  
521 <        public final void compute() {
414 <            CountedCompleter p;
521 >        protected final void realCompute() {
522              CCF f = this;
523              int n = number;
524              while (n >= 2) {
525                  new RCCF(f, n - 2).fork();
526                  f = new LCCF(f, --n);
527              }
528 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
528 >            f.complete(null);
529          }
530      }
531  
532 <    static final class LCCF extends CCF {
532 >    final class LCCF extends CCF {
533 >        public LCCF(int n) { this(null, n); }
534          public LCCF(CountedCompleter parent, int n) {
535              super(parent, n);
536          }
537          public final void onCompletion(CountedCompleter caller) {
538 +            super.onCompletion(caller);
539              CCF p = (CCF)getCompleter();
540              int n = number + rnumber;
541              if (p != null)
# Line 440 | Line 544 | public class CountedCompleterTest extend
544                  number = n;
545          }
546      }
547 <    static final class RCCF extends CCF {
547 >    final class RCCF extends CCF {
548          public RCCF(CountedCompleter parent, int n) {
549              super(parent, n);
550          }
551          public final void onCompletion(CountedCompleter caller) {
552 +            super.onCompletion(caller);
553              CCF p = (CCF)getCompleter();
554              int n = number + rnumber;
555              if (p != null)
# Line 455 | Line 560 | public class CountedCompleterTest extend
560      }
561  
562      // Version of CCF with forced failure in left completions
563 <    abstract static class FailingCCF extends CountedCompleter {
563 >    abstract class FailingCCF extends CheckedCC {
564          int number;
565          int rnumber;
566  
# Line 464 | Line 569 | public class CountedCompleterTest extend
569              this.number = n;
570          }
571  
572 <        public final void compute() {
468 <            CountedCompleter p;
572 >        protected final void realCompute() {
573              FailingCCF f = this;
574              int n = number;
575              while (n >= 2) {
576                  new RFCCF(f, n - 2).fork();
577                  f = new LFCCF(f, --n);
578              }
579 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
579 >            f.complete(null);
580          }
581      }
582  
583 <    static final class LFCCF extends FailingCCF {
583 >    final class LFCCF extends FailingCCF {
584 >        public LFCCF(int n) { this(null, n); }
585          public LFCCF(CountedCompleter parent, int n) {
586              super(parent, n);
587          }
588          public final void onCompletion(CountedCompleter caller) {
589 +            super.onCompletion(caller);
590              FailingCCF p = (FailingCCF)getCompleter();
591              int n = number + rnumber;
592              if (p != null)
# Line 494 | Line 595 | public class CountedCompleterTest extend
595                  number = n;
596          }
597      }
598 <    static final class RFCCF extends FailingCCF {
598 >    final class RFCCF extends FailingCCF {
599          public RFCCF(CountedCompleter parent, int n) {
600              super(parent, n);
601          }
602          public final void onCompletion(CountedCompleter caller) {
603 +            super.onCompletion(caller);
604              completeExceptionally(new FJException());
605          }
606      }
# Line 511 | Line 613 | public class CountedCompleterTest extend
613      public void testInvoke() {
614          ForkJoinTask a = new CheckedRecursiveAction() {
615              protected void realCompute() {
616 <                CCF f = new LCCF(null, 8);
616 >                CCF f = new LCCF(8);
617                  assertNull(f.invoke());
618                  assertEquals(21, f.number);
619                  checkCompletedNormally(f);
# Line 527 | Line 629 | public class CountedCompleterTest extend
629      public void testQuietlyInvoke() {
630          ForkJoinTask a = new CheckedRecursiveAction() {
631              protected void realCompute() {
632 <                CCF f = new LCCF(null, 8);
632 >                CCF f = new LCCF(8);
633                  f.quietlyInvoke();
634                  assertEquals(21, f.number);
635                  checkCompletedNormally(f);
# Line 541 | Line 643 | public class CountedCompleterTest extend
643      public void testForkJoin() {
644          ForkJoinTask a = new CheckedRecursiveAction() {
645              protected void realCompute() {
646 <                CCF f = new LCCF(null, 8);
646 >                CCF f = new LCCF(8);
647                  assertSame(f, f.fork());
648                  assertNull(f.join());
649                  assertEquals(21, f.number);
# Line 556 | Line 658 | public class CountedCompleterTest extend
658      public void testForkGet() {
659          ForkJoinTask a = new CheckedRecursiveAction() {
660              protected void realCompute() throws Exception {
661 <                CCF f = new LCCF(null, 8);
661 >                CCF f = new LCCF(8);
662                  assertSame(f, f.fork());
663                  assertNull(f.get());
664                  assertEquals(21, f.number);
# Line 571 | Line 673 | public class CountedCompleterTest extend
673      public void testForkTimedGet() {
674          ForkJoinTask a = new CheckedRecursiveAction() {
675              protected void realCompute() throws Exception {
676 <                CCF f = new LCCF(null, 8);
676 >                CCF f = new LCCF(8);
677                  assertSame(f, f.fork());
678                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
679                  assertEquals(21, f.number);
# Line 586 | Line 688 | public class CountedCompleterTest extend
688      public void testForkTimedGetNPE() {
689          ForkJoinTask a = new CheckedRecursiveAction() {
690              protected void realCompute() throws Exception {
691 <                CCF f = new LCCF(null, 8);
691 >                CCF f = new LCCF(8);
692                  assertSame(f, f.fork());
693                  try {
694                      f.get(5L, null);
# Line 602 | Line 704 | public class CountedCompleterTest extend
704      public void testForkQuietlyJoin() {
705          ForkJoinTask a = new CheckedRecursiveAction() {
706              protected void realCompute() {
707 <                CCF f = new LCCF(null, 8);
707 >                CCF f = new LCCF(8);
708                  assertSame(f, f.fork());
709                  f.quietlyJoin();
710                  assertEquals(21, f.number);
# Line 618 | Line 720 | public class CountedCompleterTest extend
720      public void testForkHelpQuiesce() {
721          ForkJoinTask a = new CheckedRecursiveAction() {
722              protected void realCompute() {
723 <                CCF f = new LCCF(null, 8);
723 >                CCF f = new LCCF(8);
724                  assertSame(f, f.fork());
725                  helpQuiesce();
726                  assertEquals(21, f.number);
# Line 634 | Line 736 | public class CountedCompleterTest extend
736      public void testAbnormalInvoke() {
737          ForkJoinTask a = new CheckedRecursiveAction() {
738              protected void realCompute() {
739 <                FailingCCF f = new LFCCF(null, 8);
739 >                FailingCCF f = new LFCCF(8);
740                  try {
741                      f.invoke();
742                      shouldThrow();
# Line 651 | Line 753 | public class CountedCompleterTest extend
753      public void testAbnormalQuietlyInvoke() {
754          ForkJoinTask a = new CheckedRecursiveAction() {
755              protected void realCompute() {
756 <                FailingCCF f = new LFCCF(null, 8);
756 >                FailingCCF f = new LFCCF(8);
757                  f.quietlyInvoke();
758                  assertTrue(f.getException() instanceof FJException);
759                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 767 | public class CountedCompleterTest extend
767      public void testAbnormalForkJoin() {
768          ForkJoinTask a = new CheckedRecursiveAction() {
769              protected void realCompute() {
770 <                FailingCCF f = new LFCCF(null, 8);
770 >                FailingCCF f = new LFCCF(8);
771                  assertSame(f, f.fork());
772                  try {
773                      f.join();
# Line 683 | Line 785 | public class CountedCompleterTest extend
785      public void testAbnormalForkGet() {
786          ForkJoinTask a = new CheckedRecursiveAction() {
787              protected void realCompute() throws Exception {
788 <                FailingCCF f = new LFCCF(null, 8);
788 >                FailingCCF f = new LFCCF(8);
789                  assertSame(f, f.fork());
790                  try {
791                      f.get();
# Line 703 | Line 805 | public class CountedCompleterTest extend
805      public void testAbnormalForkTimedGet() {
806          ForkJoinTask a = new CheckedRecursiveAction() {
807              protected void realCompute() throws Exception {
808 <                FailingCCF f = new LFCCF(null, 8);
808 >                FailingCCF f = new LFCCF(8);
809                  assertSame(f, f.fork());
810                  try {
811                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 825 | public class CountedCompleterTest extend
825      public void testAbnormalForkQuietlyJoin() {
826          ForkJoinTask a = new CheckedRecursiveAction() {
827              protected void realCompute() {
828 <                FailingCCF f = new LFCCF(null, 8);
828 >                FailingCCF f = new LFCCF(8);
829                  assertSame(f, f.fork());
830                  f.quietlyJoin();
831                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 840 | public class CountedCompleterTest extend
840      public void testCancelledInvoke() {
841          ForkJoinTask a = new CheckedRecursiveAction() {
842              protected void realCompute() {
843 <                CCF f = new LCCF(null, 8);
843 >                CCF f = new LCCF(8);
844                  assertTrue(f.cancel(true));
845                  try {
846                      f.invoke();
# Line 756 | Line 858 | public class CountedCompleterTest extend
858      public void testCancelledForkJoin() {
859          ForkJoinTask a = new CheckedRecursiveAction() {
860              protected void realCompute() {
861 <                CCF f = new LCCF(null, 8);
861 >                CCF f = new LCCF(8);
862                  assertTrue(f.cancel(true));
863                  assertSame(f, f.fork());
864                  try {
# Line 775 | Line 877 | public class CountedCompleterTest extend
877      public void testCancelledForkGet() {
878          ForkJoinTask a = new CheckedRecursiveAction() {
879              protected void realCompute() throws Exception {
880 <                CCF f = new LCCF(null, 8);
880 >                CCF f = new LCCF(8);
881                  assertTrue(f.cancel(true));
882                  assertSame(f, f.fork());
883                  try {
# Line 794 | Line 896 | public class CountedCompleterTest extend
896      public void testCancelledForkTimedGet() throws Exception {
897          ForkJoinTask a = new CheckedRecursiveAction() {
898              protected void realCompute() throws Exception {
899 <                CCF f = new LCCF(null, 8);
899 >                CCF f = new LCCF(8);
900                  assertTrue(f.cancel(true));
901                  assertSame(f, f.fork());
902                  try {
# Line 813 | Line 915 | public class CountedCompleterTest extend
915      public void testCancelledForkQuietlyJoin() {
916          ForkJoinTask a = new CheckedRecursiveAction() {
917              protected void realCompute() {
918 <                CCF f = new LCCF(null, 8);
918 >                CCF f = new LCCF(8);
919                  assertTrue(f.cancel(true));
920                  assertSame(f, f.fork());
921                  f.quietlyJoin();
# Line 885 | Line 987 | public class CountedCompleterTest extend
987      public void testCompleteExceptionally2() {
988          ForkJoinTask a = new CheckedRecursiveAction() {
989              protected void realCompute() {
990 <                CCF f = new LCCF(null, 8);
991 <                f.completeExceptionally(new FJException());
992 <                try {
993 <                    f.invoke();
994 <                    shouldThrow();
995 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
990 >                CCF n = new LCCF(8);
991 >                CCF f = new LCCF(n, 8);
992 >                FJException ex = new FJException();
993 >                f.completeExceptionally(ex);
994 >                f.checkCompletedExceptionally(ex);
995 >                n.checkCompletedExceptionally(ex);
996              }};
997          testInvokeOnPool(mainPool(), a);
998      }
# Line 903 | Line 1003 | public class CountedCompleterTest extend
1003      public void testInvokeAll2() {
1004          ForkJoinTask a = new CheckedRecursiveAction() {
1005              protected void realCompute() {
1006 <                CCF f = new LCCF(null, 8);
1007 <                CCF g = new LCCF(null, 9);
1006 >                CCF f = new LCCF(8);
1007 >                CCF g = new LCCF(9);
1008                  invokeAll(f, g);
1009                  assertEquals(21, f.number);
1010                  assertEquals(34, g.number);
# Line 920 | Line 1020 | public class CountedCompleterTest extend
1020      public void testInvokeAll1() {
1021          ForkJoinTask a = new CheckedRecursiveAction() {
1022              protected void realCompute() {
1023 <                CCF f = new LCCF(null, 8);
1023 >                CCF f = new LCCF(8);
1024                  invokeAll(f);
1025                  checkCompletedNormally(f);
1026                  assertEquals(21, f.number);
# Line 934 | Line 1034 | public class CountedCompleterTest extend
1034      public void testInvokeAll3() {
1035          ForkJoinTask a = new CheckedRecursiveAction() {
1036              protected void realCompute() {
1037 <                CCF f = new LCCF(null, 8);
1038 <                CCF g = new LCCF(null, 9);
1039 <                CCF h = new LCCF(null, 7);
1037 >                CCF f = new LCCF(8);
1038 >                CCF g = new LCCF(9);
1039 >                CCF h = new LCCF(7);
1040                  invokeAll(f, g, h);
1041                  assertEquals(21, f.number);
1042                  assertEquals(34, g.number);
# Line 954 | Line 1054 | public class CountedCompleterTest extend
1054      public void testInvokeAllCollection() {
1055          ForkJoinTask a = new CheckedRecursiveAction() {
1056              protected void realCompute() {
1057 <                CCF f = new LCCF(null, 8);
1058 <                CCF g = new LCCF(null, 9);
1059 <                CCF h = new LCCF(null, 7);
1057 >                CCF f = new LCCF(8);
1058 >                CCF g = new LCCF(9);
1059 >                CCF h = new LCCF(7);
1060                  HashSet set = new HashSet();
1061                  set.add(f);
1062                  set.add(g);
# Line 978 | Line 1078 | public class CountedCompleterTest extend
1078      public void testInvokeAllNPE() {
1079          ForkJoinTask a = new CheckedRecursiveAction() {
1080              protected void realCompute() {
1081 <                CCF f = new LCCF(null, 8);
1082 <                CCF g = new LCCF(null, 9);
1081 >                CCF f = new LCCF(8);
1082 >                CCF g = new LCCF(9);
1083                  CCF h = null;
1084                  try {
1085                      invokeAll(f, g, h);
# Line 995 | Line 1095 | public class CountedCompleterTest extend
1095      public void testAbnormalInvokeAll2() {
1096          ForkJoinTask a = new CheckedRecursiveAction() {
1097              protected void realCompute() {
1098 <                CCF f = new LCCF(null, 8);
1099 <                FailingCCF g = new LFCCF(null, 9);
1098 >                CCF f = new LCCF(8);
1099 >                FailingCCF g = new LFCCF(9);
1100                  try {
1101                      invokeAll(f, g);
1102                      shouldThrow();
# Line 1013 | Line 1113 | public class CountedCompleterTest extend
1113      public void testAbnormalInvokeAll1() {
1114          ForkJoinTask a = new CheckedRecursiveAction() {
1115              protected void realCompute() {
1116 <                FailingCCF g = new LFCCF(null, 9);
1116 >                FailingCCF g = new LFCCF(9);
1117                  try {
1118                      invokeAll(g);
1119                      shouldThrow();
# Line 1030 | Line 1130 | public class CountedCompleterTest extend
1130      public void testAbnormalInvokeAll3() {
1131          ForkJoinTask a = new CheckedRecursiveAction() {
1132              protected void realCompute() {
1133 <                CCF f = new LCCF(null, 8);
1134 <                FailingCCF g = new LFCCF(null, 9);
1135 <                CCF h = new LCCF(null, 7);
1133 >                CCF f = new LCCF(8);
1134 >                FailingCCF g = new LFCCF(9);
1135 >                CCF h = new LCCF(7);
1136                  try {
1137                      invokeAll(f, g, h);
1138                      shouldThrow();
# Line 1044 | Line 1144 | public class CountedCompleterTest extend
1144      }
1145  
1146      /**
1147 <     * invokeAll(collection)  throws exception if any task does
1147 >     * invokeAll(collection) throws exception if any task does
1148       */
1149      public void testAbnormalInvokeAllCollection() {
1150          ForkJoinTask a = new CheckedRecursiveAction() {
1151              protected void realCompute() {
1152 <                FailingCCF f = new LFCCF(null, 8);
1153 <                CCF g = new LCCF(null, 9);
1154 <                CCF h = new LCCF(null, 7);
1152 >                FailingCCF f = new LFCCF(8);
1153 >                CCF g = new LCCF(9);
1154 >                CCF h = new LCCF(7);
1155                  HashSet set = new HashSet();
1156                  set.add(f);
1157                  set.add(g);
# Line 1073 | Line 1173 | public class CountedCompleterTest extend
1173      public void testTryUnfork() {
1174          ForkJoinTask a = new CheckedRecursiveAction() {
1175              protected void realCompute() {
1176 <                CCF g = new LCCF(null, 9);
1176 >                CCF g = new LCCF(9);
1177                  assertSame(g, g.fork());
1178 <                CCF f = new LCCF(null, 8);
1178 >                CCF f = new LCCF(8);
1179                  assertSame(f, f.fork());
1180                  assertTrue(f.tryUnfork());
1181                  helpQuiesce();
# Line 1092 | Line 1192 | public class CountedCompleterTest extend
1192      public void testGetSurplusQueuedTaskCount() {
1193          ForkJoinTask a = new CheckedRecursiveAction() {
1194              protected void realCompute() {
1195 <                CCF h = new LCCF(null, 7);
1195 >                CCF h = new LCCF(7);
1196                  assertSame(h, h.fork());
1197 <                CCF g = new LCCF(null, 9);
1197 >                CCF g = new LCCF(9);
1198                  assertSame(g, g.fork());
1199 <                CCF f = new LCCF(null, 8);
1199 >                CCF f = new LCCF(8);
1200                  assertSame(f, f.fork());
1201                  assertTrue(getSurplusQueuedTaskCount() > 0);
1202                  helpQuiesce();
# Line 1114 | Line 1214 | public class CountedCompleterTest extend
1214      public void testPeekNextLocalTask() {
1215          ForkJoinTask a = new CheckedRecursiveAction() {
1216              protected void realCompute() {
1217 <                CCF g = new LCCF(null, 9);
1217 >                CCF g = new LCCF(9);
1218                  assertSame(g, g.fork());
1219 <                CCF f = new LCCF(null, 8);
1219 >                CCF f = new LCCF(8);
1220                  assertSame(f, f.fork());
1221                  assertSame(f, peekNextLocalTask());
1222                  assertNull(f.join());
# Line 1134 | Line 1234 | public class CountedCompleterTest extend
1234      public void testPollNextLocalTask() {
1235          ForkJoinTask a = new CheckedRecursiveAction() {
1236              protected void realCompute() {
1237 <                CCF g = new LCCF(null, 9);
1237 >                CCF g = new LCCF(9);
1238                  assertSame(g, g.fork());
1239 <                CCF f = new LCCF(null, 8);
1239 >                CCF f = new LCCF(8);
1240                  assertSame(f, f.fork());
1241                  assertSame(f, pollNextLocalTask());
1242                  helpQuiesce();
# Line 1153 | Line 1253 | public class CountedCompleterTest extend
1253      public void testPollTask() {
1254          ForkJoinTask a = new CheckedRecursiveAction() {
1255              protected void realCompute() {
1256 <                CCF g = new LCCF(null, 9);
1256 >                CCF g = new LCCF(9);
1257                  assertSame(g, g.fork());
1258 <                CCF f = new LCCF(null, 8);
1258 >                CCF f = new LCCF(8);
1259                  assertSame(f, f.fork());
1260                  assertSame(f, pollTask());
1261                  helpQuiesce();
# Line 1171 | Line 1271 | public class CountedCompleterTest extend
1271      public void testPeekNextLocalTaskAsync() {
1272          ForkJoinTask a = new CheckedRecursiveAction() {
1273              protected void realCompute() {
1274 <                CCF g = new LCCF(null, 9);
1274 >                CCF g = new LCCF(9);
1275                  assertSame(g, g.fork());
1276 <                CCF f = new LCCF(null, 8);
1276 >                CCF f = new LCCF(8);
1277                  assertSame(f, f.fork());
1278                  assertSame(g, peekNextLocalTask());
1279                  assertNull(f.join());
# Line 1192 | Line 1292 | public class CountedCompleterTest extend
1292      public void testPollNextLocalTaskAsync() {
1293          ForkJoinTask a = new CheckedRecursiveAction() {
1294              protected void realCompute() {
1295 <                CCF g = new LCCF(null, 9);
1295 >                CCF g = new LCCF(9);
1296                  assertSame(g, g.fork());
1297 <                CCF f = new LCCF(null, 8);
1297 >                CCF f = new LCCF(8);
1298                  assertSame(f, f.fork());
1299                  assertSame(g, pollNextLocalTask());
1300                  helpQuiesce();
# Line 1212 | Line 1312 | public class CountedCompleterTest extend
1312      public void testPollTaskAsync() {
1313          ForkJoinTask a = new CheckedRecursiveAction() {
1314              protected void realCompute() {
1315 <                CCF g = new LCCF(null, 9);
1315 >                CCF g = new LCCF(9);
1316                  assertSame(g, g.fork());
1317 <                CCF f = new LCCF(null, 8);
1317 >                CCF f = new LCCF(8);
1318                  assertSame(f, f.fork());
1319                  assertSame(g, pollTask());
1320                  helpQuiesce();
# Line 1235 | Line 1335 | public class CountedCompleterTest extend
1335      public void testInvokeSingleton() {
1336          ForkJoinTask a = new CheckedRecursiveAction() {
1337              protected void realCompute() {
1338 <                CCF f = new LCCF(null, 8);
1338 >                CCF f = new LCCF(8);
1339                  assertNull(f.invoke());
1340                  assertEquals(21, f.number);
1341                  checkCompletedNormally(f);
# Line 1251 | Line 1351 | public class CountedCompleterTest extend
1351      public void testQuietlyInvokeSingleton() {
1352          ForkJoinTask a = new CheckedRecursiveAction() {
1353              protected void realCompute() {
1354 <                CCF f = new LCCF(null, 8);
1354 >                CCF f = new LCCF(8);
1355                  f.quietlyInvoke();
1356                  assertEquals(21, f.number);
1357                  checkCompletedNormally(f);
# Line 1265 | Line 1365 | public class CountedCompleterTest extend
1365      public void testForkJoinSingleton() {
1366          ForkJoinTask a = new CheckedRecursiveAction() {
1367              protected void realCompute() {
1368 <                CCF f = new LCCF(null, 8);
1368 >                CCF f = new LCCF(8);
1369                  assertSame(f, f.fork());
1370                  assertNull(f.join());
1371                  assertEquals(21, f.number);
# Line 1280 | Line 1380 | public class CountedCompleterTest extend
1380      public void testForkGetSingleton() {
1381          ForkJoinTask a = new CheckedRecursiveAction() {
1382              protected void realCompute() throws Exception {
1383 <                CCF f = new LCCF(null, 8);
1383 >                CCF f = new LCCF(8);
1384                  assertSame(f, f.fork());
1385                  assertNull(f.get());
1386                  assertEquals(21, f.number);
# Line 1295 | Line 1395 | public class CountedCompleterTest extend
1395      public void testForkTimedGetSingleton() {
1396          ForkJoinTask a = new CheckedRecursiveAction() {
1397              protected void realCompute() throws Exception {
1398 <                CCF f = new LCCF(null, 8);
1398 >                CCF f = new LCCF(8);
1399                  assertSame(f, f.fork());
1400                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1401                  assertEquals(21, f.number);
# Line 1310 | Line 1410 | public class CountedCompleterTest extend
1410      public void testForkTimedGetNPESingleton() {
1411          ForkJoinTask a = new CheckedRecursiveAction() {
1412              protected void realCompute() throws Exception {
1413 <                CCF f = new LCCF(null, 8);
1413 >                CCF f = new LCCF(8);
1414                  assertSame(f, f.fork());
1415                  try {
1416                      f.get(5L, null);
# Line 1326 | Line 1426 | public class CountedCompleterTest extend
1426      public void testForkQuietlyJoinSingleton() {
1427          ForkJoinTask a = new CheckedRecursiveAction() {
1428              protected void realCompute() {
1429 <                CCF f = new LCCF(null, 8);
1429 >                CCF f = new LCCF(8);
1430                  assertSame(f, f.fork());
1431                  f.quietlyJoin();
1432                  assertEquals(21, f.number);
# Line 1342 | Line 1442 | public class CountedCompleterTest extend
1442      public void testForkHelpQuiesceSingleton() {
1443          ForkJoinTask a = new CheckedRecursiveAction() {
1444              protected void realCompute() {
1445 <                CCF f = new LCCF(null, 8);
1445 >                CCF f = new LCCF(8);
1446                  assertSame(f, f.fork());
1447                  helpQuiesce();
1448                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1458 | public class CountedCompleterTest extend
1458      public void testAbnormalInvokeSingleton() {
1459          ForkJoinTask a = new CheckedRecursiveAction() {
1460              protected void realCompute() {
1461 <                FailingCCF f = new LFCCF(null, 8);
1461 >                FailingCCF f = new LFCCF(8);
1462                  try {
1463                      f.invoke();
1464                      shouldThrow();
# Line 1375 | Line 1475 | public class CountedCompleterTest extend
1475      public void testAbnormalQuietlyInvokeSingleton() {
1476          ForkJoinTask a = new CheckedRecursiveAction() {
1477              protected void realCompute() {
1478 <                FailingCCF f = new LFCCF(null, 8);
1478 >                FailingCCF f = new LFCCF(8);
1479                  f.quietlyInvoke();
1480                  assertTrue(f.getException() instanceof FJException);
1481                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1489 | public class CountedCompleterTest extend
1489      public void testAbnormalForkJoinSingleton() {
1490          ForkJoinTask a = new CheckedRecursiveAction() {
1491              protected void realCompute() {
1492 <                FailingCCF f = new LFCCF(null, 8);
1492 >                FailingCCF f = new LFCCF(8);
1493                  assertSame(f, f.fork());
1494                  try {
1495                      f.join();
# Line 1407 | Line 1507 | public class CountedCompleterTest extend
1507      public void testAbnormalForkGetSingleton() {
1508          ForkJoinTask a = new CheckedRecursiveAction() {
1509              protected void realCompute() throws Exception {
1510 <                FailingCCF f = new LFCCF(null, 8);
1510 >                FailingCCF f = new LFCCF(8);
1511                  assertSame(f, f.fork());
1512                  try {
1513                      f.get();
# Line 1427 | Line 1527 | public class CountedCompleterTest extend
1527      public void testAbnormalForkTimedGetSingleton() {
1528          ForkJoinTask a = new CheckedRecursiveAction() {
1529              protected void realCompute() throws Exception {
1530 <                FailingCCF f = new LFCCF(null, 8);
1530 >                FailingCCF f = new LFCCF(8);
1531                  assertSame(f, f.fork());
1532                  try {
1533                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1547 | public class CountedCompleterTest extend
1547      public void testAbnormalForkQuietlyJoinSingleton() {
1548          ForkJoinTask a = new CheckedRecursiveAction() {
1549              protected void realCompute() {
1550 <                FailingCCF f = new LFCCF(null, 8);
1550 >                FailingCCF f = new LFCCF(8);
1551                  assertSame(f, f.fork());
1552                  f.quietlyJoin();
1553                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1562 | public class CountedCompleterTest extend
1562      public void testCancelledInvokeSingleton() {
1563          ForkJoinTask a = new CheckedRecursiveAction() {
1564              protected void realCompute() {
1565 <                CCF f = new LCCF(null, 8);
1565 >                CCF f = new LCCF(8);
1566                  assertTrue(f.cancel(true));
1567                  try {
1568                      f.invoke();
# Line 1480 | Line 1580 | public class CountedCompleterTest extend
1580      public void testCancelledForkJoinSingleton() {
1581          ForkJoinTask a = new CheckedRecursiveAction() {
1582              protected void realCompute() {
1583 <                CCF f = new LCCF(null, 8);
1583 >                CCF f = new LCCF(8);
1584                  assertTrue(f.cancel(true));
1585                  assertSame(f, f.fork());
1586                  try {
# Line 1499 | Line 1599 | public class CountedCompleterTest extend
1599      public void testCancelledForkGetSingleton() {
1600          ForkJoinTask a = new CheckedRecursiveAction() {
1601              protected void realCompute() throws Exception {
1602 <                CCF f = new LCCF(null, 8);
1602 >                CCF f = new LCCF(8);
1603                  assertTrue(f.cancel(true));
1604                  assertSame(f, f.fork());
1605                  try {
# Line 1518 | Line 1618 | public class CountedCompleterTest extend
1618      public void testCancelledForkTimedGetSingleton() throws Exception {
1619          ForkJoinTask a = new CheckedRecursiveAction() {
1620              protected void realCompute() throws Exception {
1621 <                CCF f = new LCCF(null, 8);
1621 >                CCF f = new LCCF(8);
1622                  assertTrue(f.cancel(true));
1623                  assertSame(f, f.fork());
1624                  try {
# Line 1537 | Line 1637 | public class CountedCompleterTest extend
1637      public void testCancelledForkQuietlyJoinSingleton() {
1638          ForkJoinTask a = new CheckedRecursiveAction() {
1639              protected void realCompute() {
1640 <                CCF f = new LCCF(null, 8);
1640 >                CCF f = new LCCF(8);
1641                  assertTrue(f.cancel(true));
1642                  assertSame(f, f.fork());
1643                  f.quietlyJoin();
# Line 1552 | Line 1652 | public class CountedCompleterTest extend
1652      public void testCompleteExceptionallySingleton() {
1653          ForkJoinTask a = new CheckedRecursiveAction() {
1654              protected void realCompute() {
1655 <                CCF f = new LCCF(null, 8);
1656 <                f.completeExceptionally(new FJException());
1657 <                try {
1658 <                    f.invoke();
1659 <                    shouldThrow();
1660 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1655 >                CCF n = new LCCF(8);
1656 >                CCF f = new LCCF(n, 8);
1657 >                FJException ex = new FJException();
1658 >                f.completeExceptionally(ex);
1659 >                f.checkCompletedExceptionally(ex);
1660 >                n.checkCompletedExceptionally(ex);
1661              }};
1662          testInvokeOnPool(singletonPool(), a);
1663      }
# Line 1570 | Line 1668 | public class CountedCompleterTest extend
1668      public void testInvokeAll2Singleton() {
1669          ForkJoinTask a = new CheckedRecursiveAction() {
1670              protected void realCompute() {
1671 <                CCF f = new LCCF(null, 8);
1672 <                CCF g = new LCCF(null, 9);
1671 >                CCF f = new LCCF(8);
1672 >                CCF g = new LCCF(9);
1673                  invokeAll(f, g);
1674                  assertEquals(21, f.number);
1675                  assertEquals(34, g.number);
# Line 1587 | Line 1685 | public class CountedCompleterTest extend
1685      public void testInvokeAll1Singleton() {
1686          ForkJoinTask a = new CheckedRecursiveAction() {
1687              protected void realCompute() {
1688 <                CCF f = new LCCF(null, 8);
1688 >                CCF f = new LCCF(8);
1689                  invokeAll(f);
1690                  checkCompletedNormally(f);
1691                  assertEquals(21, f.number);
# Line 1601 | Line 1699 | public class CountedCompleterTest extend
1699      public void testInvokeAll3Singleton() {
1700          ForkJoinTask a = new CheckedRecursiveAction() {
1701              protected void realCompute() {
1702 <                CCF f = new LCCF(null, 8);
1703 <                CCF g = new LCCF(null, 9);
1704 <                CCF h = new LCCF(null, 7);
1702 >                CCF f = new LCCF(8);
1703 >                CCF g = new LCCF(9);
1704 >                CCF h = new LCCF(7);
1705                  invokeAll(f, g, h);
1706                  assertEquals(21, f.number);
1707                  assertEquals(34, g.number);
# Line 1621 | Line 1719 | public class CountedCompleterTest extend
1719      public void testInvokeAllCollectionSingleton() {
1720          ForkJoinTask a = new CheckedRecursiveAction() {
1721              protected void realCompute() {
1722 <                CCF f = new LCCF(null, 8);
1723 <                CCF g = new LCCF(null, 9);
1724 <                CCF h = new LCCF(null, 7);
1722 >                CCF f = new LCCF(8);
1723 >                CCF g = new LCCF(9);
1724 >                CCF h = new LCCF(7);
1725                  HashSet set = new HashSet();
1726                  set.add(f);
1727                  set.add(g);
# Line 1645 | Line 1743 | public class CountedCompleterTest extend
1743      public void testInvokeAllNPESingleton() {
1744          ForkJoinTask a = new CheckedRecursiveAction() {
1745              protected void realCompute() {
1746 <                CCF f = new LCCF(null, 8);
1747 <                CCF g = new LCCF(null, 9);
1746 >                CCF f = new LCCF(8);
1747 >                CCF g = new LCCF(9);
1748                  CCF h = null;
1749                  try {
1750                      invokeAll(f, g, h);
# Line 1662 | Line 1760 | public class CountedCompleterTest extend
1760      public void testAbnormalInvokeAll2Singleton() {
1761          ForkJoinTask a = new CheckedRecursiveAction() {
1762              protected void realCompute() {
1763 <                CCF f = new LCCF(null, 8);
1764 <                FailingCCF g = new LFCCF(null, 9);
1763 >                CCF f = new LCCF(8);
1764 >                FailingCCF g = new LFCCF(9);
1765                  try {
1766                      invokeAll(f, g);
1767                      shouldThrow();
# Line 1680 | Line 1778 | public class CountedCompleterTest extend
1778      public void testAbnormalInvokeAll1Singleton() {
1779          ForkJoinTask a = new CheckedRecursiveAction() {
1780              protected void realCompute() {
1781 <                FailingCCF g = new LFCCF(null, 9);
1781 >                FailingCCF g = new LFCCF(9);
1782                  try {
1783                      invokeAll(g);
1784                      shouldThrow();
# Line 1697 | Line 1795 | public class CountedCompleterTest extend
1795      public void testAbnormalInvokeAll3Singleton() {
1796          ForkJoinTask a = new CheckedRecursiveAction() {
1797              protected void realCompute() {
1798 <                CCF f = new LCCF(null, 8);
1799 <                FailingCCF g = new LFCCF(null, 9);
1800 <                CCF h = new LCCF(null, 7);
1798 >                CCF f = new LCCF(8);
1799 >                FailingCCF g = new LFCCF(9);
1800 >                CCF h = new LCCF(7);
1801                  try {
1802                      invokeAll(f, g, h);
1803                      shouldThrow();
# Line 1711 | Line 1809 | public class CountedCompleterTest extend
1809      }
1810  
1811      /**
1812 <     * invokeAll(collection)  throws exception if any task does
1812 >     * invokeAll(collection) throws exception if any task does
1813       */
1814      public void testAbnormalInvokeAllCollectionSingleton() {
1815          ForkJoinTask a = new CheckedRecursiveAction() {
1816              protected void realCompute() {
1817 <                FailingCCF f = new LFCCF(null, 8);
1818 <                CCF g = new LCCF(null, 9);
1819 <                CCF h = new LCCF(null, 7);
1817 >                FailingCCF f = new LFCCF(8);
1818 >                CCF g = new LCCF(9);
1819 >                CCF h = new LCCF(7);
1820                  HashSet set = new HashSet();
1821                  set.add(f);
1822                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines