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.23 by jsr166, Sun Oct 18 19:12:45 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 +        a.setPendingCount(-1);
370 +        assertEquals(-1, a.decrementPendingCountUnlessZero());
371 +        assertEquals(-2, a.getPendingCount());
372 +    }
373 +
374 +    /**
375 +     * compareAndSetPendingCount compares and sets the reported
376 +     * pending count
377 +     */
378 +    public void testCompareAndSetPendingCount() {
379 +        NoopCC a = new NoopCC();
380 +        assertEquals(0, a.getPendingCount());
381 +        assertTrue(a.compareAndSetPendingCount(0, 1));
382 +        assertEquals(1, a.getPendingCount());
383 +        assertTrue(a.compareAndSetPendingCount(1, 2));
384 +        assertEquals(2, a.getPendingCount());
385 +        assertFalse(a.compareAndSetPendingCount(1, 3));
386 +        assertEquals(2, a.getPendingCount());
387      }
388  
389      /**
390       * getCompleter returns parent or null if at root
391       */
392      public void testGetCompleter() {
393 <        NoopCountedCompleter a = new NoopCountedCompleter();
393 >        NoopCC a = new NoopCC();
394          assertNull(a.getCompleter());
395 <        CountedCompleter b = new NoopCountedCompleter(a);
396 <        assertEquals(a, b.getCompleter());
395 >        CountedCompleter b = new NoopCC(a);
396 >        assertSame(a, b.getCompleter());
397 >        CountedCompleter c = new NoopCC(b);
398 >        assertSame(b, c.getCompleter());
399      }
400  
401      /**
402       * getRoot returns self if no parent, else parent's root
403       */
404      public void testGetRoot() {
405 <        NoopCountedCompleter a = new NoopCountedCompleter();
406 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
407 <        assertEquals(a, a.getRoot());
408 <        assertEquals(a, b.getRoot());
405 >        NoopCC a = new NoopCC();
406 >        NoopCC b = new NoopCC(a);
407 >        NoopCC c = new NoopCC(b);
408 >        assertSame(a, a.getRoot());
409 >        assertSame(a, b.getRoot());
410 >        assertSame(a, c.getRoot());
411      }
412  
413      /**
414 <     * tryComplete causes completion if pending count is zero
414 >     * tryComplete decrements pending count unless zero, in which case
415 >     * causes completion
416       */
417 <    public void testTryComplete1() {
418 <        NoopCountedCompleter a = new NoopCountedCompleter();
417 >    public void testTryComplete() {
418 >        NoopCC a = new NoopCC();
419          assertEquals(0, a.getPendingCount());
420 +        int n = 3;
421 +        a.setPendingCount(n);
422 +        for (; n > 0; n--) {
423 +            assertEquals(n, a.getPendingCount());
424 +            a.tryComplete();
425 +            a.checkIncomplete();
426 +            assertEquals(n - 1, a.getPendingCount());
427 +        }
428          a.tryComplete();
429 <        assertTrue(a.post);
430 <        assertTrue(a.isDone());
429 >        assertEquals(0, a.computeN());
430 >        assertEquals(1, a.onCompletionN());
431 >        assertEquals(0, a.onExceptionalCompletionN());
432 >        assertEquals(0, a.setRawResultN());
433 >        checkCompletedNormally(a);
434      }
435  
436      /**
437 <     * propagateCompletion causes completion without invoking
438 <     * onCompletion if pending count is zero
437 >     * propagateCompletion decrements pending count unless zero, in
438 >     * which case causes completion, without invoking onCompletion
439       */
440      public void testPropagateCompletion() {
441 <        NoopCountedCompleter a = new NoopCountedCompleter();
441 >        NoopCC a = new NoopCC();
442          assertEquals(0, a.getPendingCount());
443 +        int n = 3;
444 +        a.setPendingCount(n);
445 +        for (; n > 0; n--) {
446 +            assertEquals(n, a.getPendingCount());
447 +            a.propagateCompletion();
448 +            a.checkIncomplete();
449 +            assertEquals(n - 1, a.getPendingCount());
450 +        }
451          a.propagateCompletion();
452 <        assertFalse(a.post);
453 <        assertTrue(a.isDone());
454 <    }
455 <
456 <    /**
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());
452 >        assertEquals(0, a.computeN());
453 >        assertEquals(0, a.onCompletionN());
454 >        assertEquals(0, a.onExceptionalCompletionN());
455 >        assertEquals(0, a.setRawResultN());
456 >        checkCompletedNormally(a);
457      }
458  
459      /**
460       * firstComplete returns this if pending count is zero else null
461       */
462      public void testFirstComplete() {
463 <        NoopCountedCompleter a = new NoopCountedCompleter();
463 >        NoopCC a = new NoopCC();
464          a.setPendingCount(1);
465          assertNull(a.firstComplete());
466 <        assertEquals(a, a.firstComplete());
466 >        a.checkIncomplete();
467 >        assertSame(a, a.firstComplete());
468 >        a.checkIncomplete();
469      }
470  
471      /**
# Line 370 | Line 473 | public class CountedCompleterTest extend
473       * zero else null
474       */
475      public void testNextComplete() {
476 <        NoopCountedCompleter a = new NoopCountedCompleter();
477 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
476 >        NoopCC a = new NoopCC();
477 >        NoopCC b = new NoopCC(a);
478          a.setPendingCount(1);
479          b.setPendingCount(1);
480          assertNull(b.firstComplete());
481 <        CountedCompleter c = b.firstComplete();
482 <        assertEquals(b, c);
483 <        CountedCompleter d = c.nextComplete();
484 <        assertNull(d);
485 <        CountedCompleter e = c.nextComplete();
486 <        assertEquals(a, e);
481 >        assertSame(b, b.firstComplete());
482 >        assertNull(b.nextComplete());
483 >        a.checkIncomplete();
484 >        b.checkIncomplete();
485 >        assertSame(a, b.nextComplete());
486 >        assertSame(a, b.nextComplete());
487 >        a.checkIncomplete();
488 >        b.checkIncomplete();
489 >        assertNull(a.nextComplete());
490 >        b.checkIncomplete();
491 >        checkCompletedNormally(a);
492      }
493  
494      /**
495       * quietlyCompleteRoot completes root task
496       */
497      public void testQuietlyCompleteRoot() {
498 <        NoopCountedCompleter a = new NoopCountedCompleter();
499 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
498 >        NoopCC a = new NoopCC();
499 >        NoopCC b = new NoopCC(a);
500 >        NoopCC c = new NoopCC(b);
501          a.setPendingCount(1);
502          b.setPendingCount(1);
503 <        b.quietlyCompleteRoot();
503 >        c.setPendingCount(1);
504 >        c.quietlyCompleteRoot();
505          assertTrue(a.isDone());
506          assertFalse(b.isDone());
507 +        assertFalse(c.isDone());
508      }
509  
510      // Invocation tests use some interdependent task classes
511      // to better test propagation etc
512  
513 <
514 <    // Version of Fibonacci with different classes for left vs right forks
515 <    abstract static class CCF extends CountedCompleter {
513 >    /**
514 >     * Version of Fibonacci with different classes for left vs right forks
515 >     */
516 >    abstract class CCF extends CheckedCC {
517          int number;
518          int rnumber;
519  
# Line 410 | Line 522 | public class CountedCompleterTest extend
522              this.number = n;
523          }
524  
525 <        public final void compute() {
414 <            CountedCompleter p;
525 >        protected final void realCompute() {
526              CCF f = this;
527              int n = number;
528              while (n >= 2) {
529                  new RCCF(f, n - 2).fork();
530                  f = new LCCF(f, --n);
531              }
532 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
532 >            f.complete(null);
533          }
534      }
535  
536 <    static final class LCCF extends CCF {
536 >    final class LCCF extends CCF {
537 >        public LCCF(int n) { this(null, n); }
538          public LCCF(CountedCompleter parent, int n) {
539              super(parent, n);
540          }
541          public final void onCompletion(CountedCompleter caller) {
542 +            super.onCompletion(caller);
543              CCF p = (CCF)getCompleter();
544              int n = number + rnumber;
545              if (p != null)
# Line 440 | Line 548 | public class CountedCompleterTest extend
548                  number = n;
549          }
550      }
551 <    static final class RCCF extends CCF {
551 >    final class RCCF extends CCF {
552          public RCCF(CountedCompleter parent, int n) {
553              super(parent, n);
554          }
555          public final void onCompletion(CountedCompleter caller) {
556 +            super.onCompletion(caller);
557              CCF p = (CCF)getCompleter();
558              int n = number + rnumber;
559              if (p != null)
# Line 455 | Line 564 | public class CountedCompleterTest extend
564      }
565  
566      // Version of CCF with forced failure in left completions
567 <    abstract static class FailingCCF extends CountedCompleter {
567 >    abstract class FailingCCF extends CheckedCC {
568          int number;
569          int rnumber;
570  
# Line 464 | Line 573 | public class CountedCompleterTest extend
573              this.number = n;
574          }
575  
576 <        public final void compute() {
468 <            CountedCompleter p;
576 >        protected final void realCompute() {
577              FailingCCF f = this;
578              int n = number;
579              while (n >= 2) {
580                  new RFCCF(f, n - 2).fork();
581                  f = new LFCCF(f, --n);
582              }
583 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
583 >            f.complete(null);
584          }
585      }
586  
587 <    static final class LFCCF extends FailingCCF {
587 >    final class LFCCF extends FailingCCF {
588 >        public LFCCF(int n) { this(null, n); }
589          public LFCCF(CountedCompleter parent, int n) {
590              super(parent, n);
591          }
592          public final void onCompletion(CountedCompleter caller) {
593 +            super.onCompletion(caller);
594              FailingCCF p = (FailingCCF)getCompleter();
595              int n = number + rnumber;
596              if (p != null)
# Line 494 | Line 599 | public class CountedCompleterTest extend
599                  number = n;
600          }
601      }
602 <    static final class RFCCF extends FailingCCF {
602 >    final class RFCCF extends FailingCCF {
603          public RFCCF(CountedCompleter parent, int n) {
604              super(parent, n);
605          }
606          public final void onCompletion(CountedCompleter caller) {
607 +            super.onCompletion(caller);
608              completeExceptionally(new FJException());
609          }
610      }
# Line 511 | Line 617 | public class CountedCompleterTest extend
617      public void testInvoke() {
618          ForkJoinTask a = new CheckedRecursiveAction() {
619              protected void realCompute() {
620 <                CCF f = new LCCF(null, 8);
620 >                CCF f = new LCCF(8);
621                  assertNull(f.invoke());
622                  assertEquals(21, f.number);
623                  checkCompletedNormally(f);
# Line 527 | Line 633 | public class CountedCompleterTest extend
633      public void testQuietlyInvoke() {
634          ForkJoinTask a = new CheckedRecursiveAction() {
635              protected void realCompute() {
636 <                CCF f = new LCCF(null, 8);
636 >                CCF f = new LCCF(8);
637                  f.quietlyInvoke();
638                  assertEquals(21, f.number);
639                  checkCompletedNormally(f);
# Line 541 | Line 647 | public class CountedCompleterTest extend
647      public void testForkJoin() {
648          ForkJoinTask a = new CheckedRecursiveAction() {
649              protected void realCompute() {
650 <                CCF f = new LCCF(null, 8);
650 >                CCF f = new LCCF(8);
651                  assertSame(f, f.fork());
652                  assertNull(f.join());
653                  assertEquals(21, f.number);
# Line 556 | Line 662 | public class CountedCompleterTest extend
662      public void testForkGet() {
663          ForkJoinTask a = new CheckedRecursiveAction() {
664              protected void realCompute() throws Exception {
665 <                CCF f = new LCCF(null, 8);
665 >                CCF f = new LCCF(8);
666                  assertSame(f, f.fork());
667                  assertNull(f.get());
668                  assertEquals(21, f.number);
# Line 571 | Line 677 | public class CountedCompleterTest extend
677      public void testForkTimedGet() {
678          ForkJoinTask a = new CheckedRecursiveAction() {
679              protected void realCompute() throws Exception {
680 <                CCF f = new LCCF(null, 8);
680 >                CCF f = new LCCF(8);
681                  assertSame(f, f.fork());
682                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
683                  assertEquals(21, f.number);
# Line 586 | Line 692 | public class CountedCompleterTest extend
692      public void testForkTimedGetNPE() {
693          ForkJoinTask a = new CheckedRecursiveAction() {
694              protected void realCompute() throws Exception {
695 <                CCF f = new LCCF(null, 8);
695 >                CCF f = new LCCF(8);
696                  assertSame(f, f.fork());
697                  try {
698                      f.get(5L, null);
# Line 602 | Line 708 | public class CountedCompleterTest extend
708      public void testForkQuietlyJoin() {
709          ForkJoinTask a = new CheckedRecursiveAction() {
710              protected void realCompute() {
711 <                CCF f = new LCCF(null, 8);
711 >                CCF f = new LCCF(8);
712                  assertSame(f, f.fork());
713                  f.quietlyJoin();
714                  assertEquals(21, f.number);
# Line 618 | Line 724 | public class CountedCompleterTest extend
724      public void testForkHelpQuiesce() {
725          ForkJoinTask a = new CheckedRecursiveAction() {
726              protected void realCompute() {
727 <                CCF f = new LCCF(null, 8);
727 >                CCF f = new LCCF(8);
728                  assertSame(f, f.fork());
729                  helpQuiesce();
730                  assertEquals(21, f.number);
# Line 634 | Line 740 | public class CountedCompleterTest extend
740      public void testAbnormalInvoke() {
741          ForkJoinTask a = new CheckedRecursiveAction() {
742              protected void realCompute() {
743 <                FailingCCF f = new LFCCF(null, 8);
743 >                FailingCCF f = new LFCCF(8);
744                  try {
745                      f.invoke();
746                      shouldThrow();
# Line 651 | Line 757 | public class CountedCompleterTest extend
757      public void testAbnormalQuietlyInvoke() {
758          ForkJoinTask a = new CheckedRecursiveAction() {
759              protected void realCompute() {
760 <                FailingCCF f = new LFCCF(null, 8);
760 >                FailingCCF f = new LFCCF(8);
761                  f.quietlyInvoke();
762                  assertTrue(f.getException() instanceof FJException);
763                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 771 | public class CountedCompleterTest extend
771      public void testAbnormalForkJoin() {
772          ForkJoinTask a = new CheckedRecursiveAction() {
773              protected void realCompute() {
774 <                FailingCCF f = new LFCCF(null, 8);
774 >                FailingCCF f = new LFCCF(8);
775                  assertSame(f, f.fork());
776                  try {
777                      f.join();
# Line 683 | Line 789 | public class CountedCompleterTest extend
789      public void testAbnormalForkGet() {
790          ForkJoinTask a = new CheckedRecursiveAction() {
791              protected void realCompute() throws Exception {
792 <                FailingCCF f = new LFCCF(null, 8);
792 >                FailingCCF f = new LFCCF(8);
793                  assertSame(f, f.fork());
794                  try {
795                      f.get();
# Line 703 | Line 809 | public class CountedCompleterTest extend
809      public void testAbnormalForkTimedGet() {
810          ForkJoinTask a = new CheckedRecursiveAction() {
811              protected void realCompute() throws Exception {
812 <                FailingCCF f = new LFCCF(null, 8);
812 >                FailingCCF f = new LFCCF(8);
813                  assertSame(f, f.fork());
814                  try {
815                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 829 | public class CountedCompleterTest extend
829      public void testAbnormalForkQuietlyJoin() {
830          ForkJoinTask a = new CheckedRecursiveAction() {
831              protected void realCompute() {
832 <                FailingCCF f = new LFCCF(null, 8);
832 >                FailingCCF f = new LFCCF(8);
833                  assertSame(f, f.fork());
834                  f.quietlyJoin();
835                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 844 | public class CountedCompleterTest extend
844      public void testCancelledInvoke() {
845          ForkJoinTask a = new CheckedRecursiveAction() {
846              protected void realCompute() {
847 <                CCF f = new LCCF(null, 8);
847 >                CCF f = new LCCF(8);
848                  assertTrue(f.cancel(true));
849                  try {
850                      f.invoke();
# Line 756 | Line 862 | public class CountedCompleterTest extend
862      public void testCancelledForkJoin() {
863          ForkJoinTask a = new CheckedRecursiveAction() {
864              protected void realCompute() {
865 <                CCF f = new LCCF(null, 8);
865 >                CCF f = new LCCF(8);
866                  assertTrue(f.cancel(true));
867                  assertSame(f, f.fork());
868                  try {
# Line 775 | Line 881 | public class CountedCompleterTest extend
881      public void testCancelledForkGet() {
882          ForkJoinTask a = new CheckedRecursiveAction() {
883              protected void realCompute() throws Exception {
884 <                CCF f = new LCCF(null, 8);
884 >                CCF f = new LCCF(8);
885                  assertTrue(f.cancel(true));
886                  assertSame(f, f.fork());
887                  try {
# Line 794 | Line 900 | public class CountedCompleterTest extend
900      public void testCancelledForkTimedGet() throws Exception {
901          ForkJoinTask a = new CheckedRecursiveAction() {
902              protected void realCompute() throws Exception {
903 <                CCF f = new LCCF(null, 8);
903 >                CCF f = new LCCF(8);
904                  assertTrue(f.cancel(true));
905                  assertSame(f, f.fork());
906                  try {
# Line 813 | Line 919 | public class CountedCompleterTest extend
919      public void testCancelledForkQuietlyJoin() {
920          ForkJoinTask a = new CheckedRecursiveAction() {
921              protected void realCompute() {
922 <                CCF f = new LCCF(null, 8);
922 >                CCF f = new LCCF(8);
923                  assertTrue(f.cancel(true));
924                  assertSame(f, f.fork());
925                  f.quietlyJoin();
# Line 885 | Line 991 | public class CountedCompleterTest extend
991      public void testCompleteExceptionally2() {
992          ForkJoinTask a = new CheckedRecursiveAction() {
993              protected void realCompute() {
994 <                CCF f = new LCCF(null, 8);
995 <                f.completeExceptionally(new FJException());
996 <                try {
997 <                    f.invoke();
998 <                    shouldThrow();
999 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
994 >                CCF n = new LCCF(8);
995 >                CCF f = new LCCF(n, 8);
996 >                FJException ex = new FJException();
997 >                f.completeExceptionally(ex);
998 >                f.checkCompletedExceptionally(ex);
999 >                n.checkCompletedExceptionally(ex);
1000              }};
1001          testInvokeOnPool(mainPool(), a);
1002      }
# Line 903 | Line 1007 | public class CountedCompleterTest extend
1007      public void testInvokeAll2() {
1008          ForkJoinTask a = new CheckedRecursiveAction() {
1009              protected void realCompute() {
1010 <                CCF f = new LCCF(null, 8);
1011 <                CCF g = new LCCF(null, 9);
1010 >                CCF f = new LCCF(8);
1011 >                CCF g = new LCCF(9);
1012                  invokeAll(f, g);
1013                  assertEquals(21, f.number);
1014                  assertEquals(34, g.number);
# Line 920 | Line 1024 | public class CountedCompleterTest extend
1024      public void testInvokeAll1() {
1025          ForkJoinTask a = new CheckedRecursiveAction() {
1026              protected void realCompute() {
1027 <                CCF f = new LCCF(null, 8);
1027 >                CCF f = new LCCF(8);
1028                  invokeAll(f);
1029                  checkCompletedNormally(f);
1030                  assertEquals(21, f.number);
# Line 934 | Line 1038 | public class CountedCompleterTest extend
1038      public void testInvokeAll3() {
1039          ForkJoinTask a = new CheckedRecursiveAction() {
1040              protected void realCompute() {
1041 <                CCF f = new LCCF(null, 8);
1042 <                CCF g = new LCCF(null, 9);
1043 <                CCF h = new LCCF(null, 7);
1041 >                CCF f = new LCCF(8);
1042 >                CCF g = new LCCF(9);
1043 >                CCF h = new LCCF(7);
1044                  invokeAll(f, g, h);
1045                  assertEquals(21, f.number);
1046                  assertEquals(34, g.number);
# Line 954 | Line 1058 | public class CountedCompleterTest extend
1058      public void testInvokeAllCollection() {
1059          ForkJoinTask a = new CheckedRecursiveAction() {
1060              protected void realCompute() {
1061 <                CCF f = new LCCF(null, 8);
1062 <                CCF g = new LCCF(null, 9);
1063 <                CCF h = new LCCF(null, 7);
1061 >                CCF f = new LCCF(8);
1062 >                CCF g = new LCCF(9);
1063 >                CCF h = new LCCF(7);
1064                  HashSet set = new HashSet();
1065                  set.add(f);
1066                  set.add(g);
# Line 978 | Line 1082 | public class CountedCompleterTest extend
1082      public void testInvokeAllNPE() {
1083          ForkJoinTask a = new CheckedRecursiveAction() {
1084              protected void realCompute() {
1085 <                CCF f = new LCCF(null, 8);
1086 <                CCF g = new LCCF(null, 9);
1085 >                CCF f = new LCCF(8);
1086 >                CCF g = new LCCF(9);
1087                  CCF h = null;
1088                  try {
1089                      invokeAll(f, g, h);
# Line 995 | Line 1099 | public class CountedCompleterTest extend
1099      public void testAbnormalInvokeAll2() {
1100          ForkJoinTask a = new CheckedRecursiveAction() {
1101              protected void realCompute() {
1102 <                CCF f = new LCCF(null, 8);
1103 <                FailingCCF g = new LFCCF(null, 9);
1102 >                CCF f = new LCCF(8);
1103 >                FailingCCF g = new LFCCF(9);
1104                  try {
1105                      invokeAll(f, g);
1106                      shouldThrow();
# Line 1013 | Line 1117 | public class CountedCompleterTest extend
1117      public void testAbnormalInvokeAll1() {
1118          ForkJoinTask a = new CheckedRecursiveAction() {
1119              protected void realCompute() {
1120 <                FailingCCF g = new LFCCF(null, 9);
1120 >                FailingCCF g = new LFCCF(9);
1121                  try {
1122                      invokeAll(g);
1123                      shouldThrow();
# Line 1030 | Line 1134 | public class CountedCompleterTest extend
1134      public void testAbnormalInvokeAll3() {
1135          ForkJoinTask a = new CheckedRecursiveAction() {
1136              protected void realCompute() {
1137 <                CCF f = new LCCF(null, 8);
1138 <                FailingCCF g = new LFCCF(null, 9);
1139 <                CCF h = new LCCF(null, 7);
1137 >                CCF f = new LCCF(8);
1138 >                FailingCCF g = new LFCCF(9);
1139 >                CCF h = new LCCF(7);
1140                  try {
1141                      invokeAll(f, g, h);
1142                      shouldThrow();
# Line 1044 | Line 1148 | public class CountedCompleterTest extend
1148      }
1149  
1150      /**
1151 <     * invokeAll(collection)  throws exception if any task does
1151 >     * invokeAll(collection) throws exception if any task does
1152       */
1153      public void testAbnormalInvokeAllCollection() {
1154          ForkJoinTask a = new CheckedRecursiveAction() {
1155              protected void realCompute() {
1156 <                FailingCCF f = new LFCCF(null, 8);
1157 <                CCF g = new LCCF(null, 9);
1158 <                CCF h = new LCCF(null, 7);
1156 >                FailingCCF f = new LFCCF(8);
1157 >                CCF g = new LCCF(9);
1158 >                CCF h = new LCCF(7);
1159                  HashSet set = new HashSet();
1160                  set.add(f);
1161                  set.add(g);
# Line 1073 | Line 1177 | public class CountedCompleterTest extend
1177      public void testTryUnfork() {
1178          ForkJoinTask a = new CheckedRecursiveAction() {
1179              protected void realCompute() {
1180 <                CCF g = new LCCF(null, 9);
1180 >                CCF g = new LCCF(9);
1181                  assertSame(g, g.fork());
1182 <                CCF f = new LCCF(null, 8);
1182 >                CCF f = new LCCF(8);
1183                  assertSame(f, f.fork());
1184                  assertTrue(f.tryUnfork());
1185                  helpQuiesce();
# Line 1092 | Line 1196 | public class CountedCompleterTest extend
1196      public void testGetSurplusQueuedTaskCount() {
1197          ForkJoinTask a = new CheckedRecursiveAction() {
1198              protected void realCompute() {
1199 <                CCF h = new LCCF(null, 7);
1199 >                CCF h = new LCCF(7);
1200                  assertSame(h, h.fork());
1201 <                CCF g = new LCCF(null, 9);
1201 >                CCF g = new LCCF(9);
1202                  assertSame(g, g.fork());
1203 <                CCF f = new LCCF(null, 8);
1203 >                CCF f = new LCCF(8);
1204                  assertSame(f, f.fork());
1205                  assertTrue(getSurplusQueuedTaskCount() > 0);
1206                  helpQuiesce();
# Line 1114 | Line 1218 | public class CountedCompleterTest extend
1218      public void testPeekNextLocalTask() {
1219          ForkJoinTask a = new CheckedRecursiveAction() {
1220              protected void realCompute() {
1221 <                CCF g = new LCCF(null, 9);
1221 >                CCF g = new LCCF(9);
1222                  assertSame(g, g.fork());
1223 <                CCF f = new LCCF(null, 8);
1223 >                CCF f = new LCCF(8);
1224                  assertSame(f, f.fork());
1225                  assertSame(f, peekNextLocalTask());
1226                  assertNull(f.join());
# Line 1134 | Line 1238 | public class CountedCompleterTest extend
1238      public void testPollNextLocalTask() {
1239          ForkJoinTask a = new CheckedRecursiveAction() {
1240              protected void realCompute() {
1241 <                CCF g = new LCCF(null, 9);
1241 >                CCF g = new LCCF(9);
1242                  assertSame(g, g.fork());
1243 <                CCF f = new LCCF(null, 8);
1243 >                CCF f = new LCCF(8);
1244                  assertSame(f, f.fork());
1245                  assertSame(f, pollNextLocalTask());
1246                  helpQuiesce();
# Line 1153 | Line 1257 | public class CountedCompleterTest extend
1257      public void testPollTask() {
1258          ForkJoinTask a = new CheckedRecursiveAction() {
1259              protected void realCompute() {
1260 <                CCF g = new LCCF(null, 9);
1260 >                CCF g = new LCCF(9);
1261                  assertSame(g, g.fork());
1262 <                CCF f = new LCCF(null, 8);
1262 >                CCF f = new LCCF(8);
1263                  assertSame(f, f.fork());
1264                  assertSame(f, pollTask());
1265                  helpQuiesce();
# Line 1171 | Line 1275 | public class CountedCompleterTest extend
1275      public void testPeekNextLocalTaskAsync() {
1276          ForkJoinTask a = new CheckedRecursiveAction() {
1277              protected void realCompute() {
1278 <                CCF g = new LCCF(null, 9);
1278 >                CCF g = new LCCF(9);
1279                  assertSame(g, g.fork());
1280 <                CCF f = new LCCF(null, 8);
1280 >                CCF f = new LCCF(8);
1281                  assertSame(f, f.fork());
1282                  assertSame(g, peekNextLocalTask());
1283                  assertNull(f.join());
# Line 1192 | Line 1296 | public class CountedCompleterTest extend
1296      public void testPollNextLocalTaskAsync() {
1297          ForkJoinTask a = new CheckedRecursiveAction() {
1298              protected void realCompute() {
1299 <                CCF g = new LCCF(null, 9);
1299 >                CCF g = new LCCF(9);
1300                  assertSame(g, g.fork());
1301 <                CCF f = new LCCF(null, 8);
1301 >                CCF f = new LCCF(8);
1302                  assertSame(f, f.fork());
1303                  assertSame(g, pollNextLocalTask());
1304                  helpQuiesce();
# Line 1212 | Line 1316 | public class CountedCompleterTest extend
1316      public void testPollTaskAsync() {
1317          ForkJoinTask a = new CheckedRecursiveAction() {
1318              protected void realCompute() {
1319 <                CCF g = new LCCF(null, 9);
1319 >                CCF g = new LCCF(9);
1320                  assertSame(g, g.fork());
1321 <                CCF f = new LCCF(null, 8);
1321 >                CCF f = new LCCF(8);
1322                  assertSame(f, f.fork());
1323                  assertSame(g, pollTask());
1324                  helpQuiesce();
# Line 1235 | Line 1339 | public class CountedCompleterTest extend
1339      public void testInvokeSingleton() {
1340          ForkJoinTask a = new CheckedRecursiveAction() {
1341              protected void realCompute() {
1342 <                CCF f = new LCCF(null, 8);
1342 >                CCF f = new LCCF(8);
1343                  assertNull(f.invoke());
1344                  assertEquals(21, f.number);
1345                  checkCompletedNormally(f);
# Line 1251 | Line 1355 | public class CountedCompleterTest extend
1355      public void testQuietlyInvokeSingleton() {
1356          ForkJoinTask a = new CheckedRecursiveAction() {
1357              protected void realCompute() {
1358 <                CCF f = new LCCF(null, 8);
1358 >                CCF f = new LCCF(8);
1359                  f.quietlyInvoke();
1360                  assertEquals(21, f.number);
1361                  checkCompletedNormally(f);
# Line 1265 | Line 1369 | public class CountedCompleterTest extend
1369      public void testForkJoinSingleton() {
1370          ForkJoinTask a = new CheckedRecursiveAction() {
1371              protected void realCompute() {
1372 <                CCF f = new LCCF(null, 8);
1372 >                CCF f = new LCCF(8);
1373                  assertSame(f, f.fork());
1374                  assertNull(f.join());
1375                  assertEquals(21, f.number);
# Line 1280 | Line 1384 | public class CountedCompleterTest extend
1384      public void testForkGetSingleton() {
1385          ForkJoinTask a = new CheckedRecursiveAction() {
1386              protected void realCompute() throws Exception {
1387 <                CCF f = new LCCF(null, 8);
1387 >                CCF f = new LCCF(8);
1388                  assertSame(f, f.fork());
1389                  assertNull(f.get());
1390                  assertEquals(21, f.number);
# Line 1295 | Line 1399 | public class CountedCompleterTest extend
1399      public void testForkTimedGetSingleton() {
1400          ForkJoinTask a = new CheckedRecursiveAction() {
1401              protected void realCompute() throws Exception {
1402 <                CCF f = new LCCF(null, 8);
1402 >                CCF f = new LCCF(8);
1403                  assertSame(f, f.fork());
1404                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1405                  assertEquals(21, f.number);
# Line 1310 | Line 1414 | public class CountedCompleterTest extend
1414      public void testForkTimedGetNPESingleton() {
1415          ForkJoinTask a = new CheckedRecursiveAction() {
1416              protected void realCompute() throws Exception {
1417 <                CCF f = new LCCF(null, 8);
1417 >                CCF f = new LCCF(8);
1418                  assertSame(f, f.fork());
1419                  try {
1420                      f.get(5L, null);
# Line 1326 | Line 1430 | public class CountedCompleterTest extend
1430      public void testForkQuietlyJoinSingleton() {
1431          ForkJoinTask a = new CheckedRecursiveAction() {
1432              protected void realCompute() {
1433 <                CCF f = new LCCF(null, 8);
1433 >                CCF f = new LCCF(8);
1434                  assertSame(f, f.fork());
1435                  f.quietlyJoin();
1436                  assertEquals(21, f.number);
# Line 1342 | Line 1446 | public class CountedCompleterTest extend
1446      public void testForkHelpQuiesceSingleton() {
1447          ForkJoinTask a = new CheckedRecursiveAction() {
1448              protected void realCompute() {
1449 <                CCF f = new LCCF(null, 8);
1449 >                CCF f = new LCCF(8);
1450                  assertSame(f, f.fork());
1451                  helpQuiesce();
1452                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1462 | public class CountedCompleterTest extend
1462      public void testAbnormalInvokeSingleton() {
1463          ForkJoinTask a = new CheckedRecursiveAction() {
1464              protected void realCompute() {
1465 <                FailingCCF f = new LFCCF(null, 8);
1465 >                FailingCCF f = new LFCCF(8);
1466                  try {
1467                      f.invoke();
1468                      shouldThrow();
# Line 1375 | Line 1479 | public class CountedCompleterTest extend
1479      public void testAbnormalQuietlyInvokeSingleton() {
1480          ForkJoinTask a = new CheckedRecursiveAction() {
1481              protected void realCompute() {
1482 <                FailingCCF f = new LFCCF(null, 8);
1482 >                FailingCCF f = new LFCCF(8);
1483                  f.quietlyInvoke();
1484                  assertTrue(f.getException() instanceof FJException);
1485                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1493 | public class CountedCompleterTest extend
1493      public void testAbnormalForkJoinSingleton() {
1494          ForkJoinTask a = new CheckedRecursiveAction() {
1495              protected void realCompute() {
1496 <                FailingCCF f = new LFCCF(null, 8);
1496 >                FailingCCF f = new LFCCF(8);
1497                  assertSame(f, f.fork());
1498                  try {
1499                      f.join();
# Line 1407 | Line 1511 | public class CountedCompleterTest extend
1511      public void testAbnormalForkGetSingleton() {
1512          ForkJoinTask a = new CheckedRecursiveAction() {
1513              protected void realCompute() throws Exception {
1514 <                FailingCCF f = new LFCCF(null, 8);
1514 >                FailingCCF f = new LFCCF(8);
1515                  assertSame(f, f.fork());
1516                  try {
1517                      f.get();
# Line 1427 | Line 1531 | public class CountedCompleterTest extend
1531      public void testAbnormalForkTimedGetSingleton() {
1532          ForkJoinTask a = new CheckedRecursiveAction() {
1533              protected void realCompute() throws Exception {
1534 <                FailingCCF f = new LFCCF(null, 8);
1534 >                FailingCCF f = new LFCCF(8);
1535                  assertSame(f, f.fork());
1536                  try {
1537                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1551 | public class CountedCompleterTest extend
1551      public void testAbnormalForkQuietlyJoinSingleton() {
1552          ForkJoinTask a = new CheckedRecursiveAction() {
1553              protected void realCompute() {
1554 <                FailingCCF f = new LFCCF(null, 8);
1554 >                FailingCCF f = new LFCCF(8);
1555                  assertSame(f, f.fork());
1556                  f.quietlyJoin();
1557                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1566 | public class CountedCompleterTest extend
1566      public void testCancelledInvokeSingleton() {
1567          ForkJoinTask a = new CheckedRecursiveAction() {
1568              protected void realCompute() {
1569 <                CCF f = new LCCF(null, 8);
1569 >                CCF f = new LCCF(8);
1570                  assertTrue(f.cancel(true));
1571                  try {
1572                      f.invoke();
# Line 1480 | Line 1584 | public class CountedCompleterTest extend
1584      public void testCancelledForkJoinSingleton() {
1585          ForkJoinTask a = new CheckedRecursiveAction() {
1586              protected void realCompute() {
1587 <                CCF f = new LCCF(null, 8);
1587 >                CCF f = new LCCF(8);
1588                  assertTrue(f.cancel(true));
1589                  assertSame(f, f.fork());
1590                  try {
# Line 1499 | Line 1603 | public class CountedCompleterTest extend
1603      public void testCancelledForkGetSingleton() {
1604          ForkJoinTask a = new CheckedRecursiveAction() {
1605              protected void realCompute() throws Exception {
1606 <                CCF f = new LCCF(null, 8);
1606 >                CCF f = new LCCF(8);
1607                  assertTrue(f.cancel(true));
1608                  assertSame(f, f.fork());
1609                  try {
# Line 1518 | Line 1622 | public class CountedCompleterTest extend
1622      public void testCancelledForkTimedGetSingleton() throws Exception {
1623          ForkJoinTask a = new CheckedRecursiveAction() {
1624              protected void realCompute() throws Exception {
1625 <                CCF f = new LCCF(null, 8);
1625 >                CCF f = new LCCF(8);
1626                  assertTrue(f.cancel(true));
1627                  assertSame(f, f.fork());
1628                  try {
# Line 1537 | Line 1641 | public class CountedCompleterTest extend
1641      public void testCancelledForkQuietlyJoinSingleton() {
1642          ForkJoinTask a = new CheckedRecursiveAction() {
1643              protected void realCompute() {
1644 <                CCF f = new LCCF(null, 8);
1644 >                CCF f = new LCCF(8);
1645                  assertTrue(f.cancel(true));
1646                  assertSame(f, f.fork());
1647                  f.quietlyJoin();
# Line 1552 | Line 1656 | public class CountedCompleterTest extend
1656      public void testCompleteExceptionallySingleton() {
1657          ForkJoinTask a = new CheckedRecursiveAction() {
1658              protected void realCompute() {
1659 <                CCF f = new LCCF(null, 8);
1660 <                f.completeExceptionally(new FJException());
1661 <                try {
1662 <                    f.invoke();
1663 <                    shouldThrow();
1664 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1659 >                CCF n = new LCCF(8);
1660 >                CCF f = new LCCF(n, 8);
1661 >                FJException ex = new FJException();
1662 >                f.completeExceptionally(ex);
1663 >                f.checkCompletedExceptionally(ex);
1664 >                n.checkCompletedExceptionally(ex);
1665              }};
1666          testInvokeOnPool(singletonPool(), a);
1667      }
# Line 1570 | Line 1672 | public class CountedCompleterTest extend
1672      public void testInvokeAll2Singleton() {
1673          ForkJoinTask a = new CheckedRecursiveAction() {
1674              protected void realCompute() {
1675 <                CCF f = new LCCF(null, 8);
1676 <                CCF g = new LCCF(null, 9);
1675 >                CCF f = new LCCF(8);
1676 >                CCF g = new LCCF(9);
1677                  invokeAll(f, g);
1678                  assertEquals(21, f.number);
1679                  assertEquals(34, g.number);
# Line 1587 | Line 1689 | public class CountedCompleterTest extend
1689      public void testInvokeAll1Singleton() {
1690          ForkJoinTask a = new CheckedRecursiveAction() {
1691              protected void realCompute() {
1692 <                CCF f = new LCCF(null, 8);
1692 >                CCF f = new LCCF(8);
1693                  invokeAll(f);
1694                  checkCompletedNormally(f);
1695                  assertEquals(21, f.number);
# Line 1601 | Line 1703 | public class CountedCompleterTest extend
1703      public void testInvokeAll3Singleton() {
1704          ForkJoinTask a = new CheckedRecursiveAction() {
1705              protected void realCompute() {
1706 <                CCF f = new LCCF(null, 8);
1707 <                CCF g = new LCCF(null, 9);
1708 <                CCF h = new LCCF(null, 7);
1706 >                CCF f = new LCCF(8);
1707 >                CCF g = new LCCF(9);
1708 >                CCF h = new LCCF(7);
1709                  invokeAll(f, g, h);
1710                  assertEquals(21, f.number);
1711                  assertEquals(34, g.number);
# Line 1621 | Line 1723 | public class CountedCompleterTest extend
1723      public void testInvokeAllCollectionSingleton() {
1724          ForkJoinTask a = new CheckedRecursiveAction() {
1725              protected void realCompute() {
1726 <                CCF f = new LCCF(null, 8);
1727 <                CCF g = new LCCF(null, 9);
1728 <                CCF h = new LCCF(null, 7);
1726 >                CCF f = new LCCF(8);
1727 >                CCF g = new LCCF(9);
1728 >                CCF h = new LCCF(7);
1729                  HashSet set = new HashSet();
1730                  set.add(f);
1731                  set.add(g);
# Line 1645 | Line 1747 | public class CountedCompleterTest extend
1747      public void testInvokeAllNPESingleton() {
1748          ForkJoinTask a = new CheckedRecursiveAction() {
1749              protected void realCompute() {
1750 <                CCF f = new LCCF(null, 8);
1751 <                CCF g = new LCCF(null, 9);
1750 >                CCF f = new LCCF(8);
1751 >                CCF g = new LCCF(9);
1752                  CCF h = null;
1753                  try {
1754                      invokeAll(f, g, h);
# Line 1662 | Line 1764 | public class CountedCompleterTest extend
1764      public void testAbnormalInvokeAll2Singleton() {
1765          ForkJoinTask a = new CheckedRecursiveAction() {
1766              protected void realCompute() {
1767 <                CCF f = new LCCF(null, 8);
1768 <                FailingCCF g = new LFCCF(null, 9);
1767 >                CCF f = new LCCF(8);
1768 >                FailingCCF g = new LFCCF(9);
1769                  try {
1770                      invokeAll(f, g);
1771                      shouldThrow();
# Line 1680 | Line 1782 | public class CountedCompleterTest extend
1782      public void testAbnormalInvokeAll1Singleton() {
1783          ForkJoinTask a = new CheckedRecursiveAction() {
1784              protected void realCompute() {
1785 <                FailingCCF g = new LFCCF(null, 9);
1785 >                FailingCCF g = new LFCCF(9);
1786                  try {
1787                      invokeAll(g);
1788                      shouldThrow();
# Line 1697 | Line 1799 | public class CountedCompleterTest extend
1799      public void testAbnormalInvokeAll3Singleton() {
1800          ForkJoinTask a = new CheckedRecursiveAction() {
1801              protected void realCompute() {
1802 <                CCF f = new LCCF(null, 8);
1803 <                FailingCCF g = new LFCCF(null, 9);
1804 <                CCF h = new LCCF(null, 7);
1802 >                CCF f = new LCCF(8);
1803 >                FailingCCF g = new LFCCF(9);
1804 >                CCF h = new LCCF(7);
1805                  try {
1806                      invokeAll(f, g, h);
1807                      shouldThrow();
# Line 1711 | Line 1813 | public class CountedCompleterTest extend
1813      }
1814  
1815      /**
1816 <     * invokeAll(collection)  throws exception if any task does
1816 >     * invokeAll(collection) throws exception if any task does
1817       */
1818      public void testAbnormalInvokeAllCollectionSingleton() {
1819          ForkJoinTask a = new CheckedRecursiveAction() {
1820              protected void realCompute() {
1821 <                FailingCCF f = new LFCCF(null, 8);
1822 <                CCF g = new LCCF(null, 9);
1823 <                CCF h = new LCCF(null, 7);
1821 >                FailingCCF f = new LFCCF(8);
1822 >                CCF g = new LCCF(9);
1823 >                CCF h = new LCCF(7);
1824                  HashSet set = new HashSet();
1825                  set.add(f);
1826                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines