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.25 by jsr166, Sun Oct 18 19:22:36 2015 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import java.util.concurrent.ExecutionException;
6 >
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13 + import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.CountedCompleter;
11 import java.util.concurrent.ForkJoinWorkerThread;
12 import java.util.concurrent.RecursiveAction;
13 import java.util.concurrent.TimeUnit;
16   import java.util.concurrent.TimeoutException;
17 < import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
18 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
19 < import static java.util.concurrent.TimeUnit.SECONDS;
20 < import java.util.HashSet;
21 < import junit.framework.*;
17 > import java.util.concurrent.atomic.AtomicInteger;
18 > import java.util.concurrent.atomic.AtomicReference;
19 >
20 > import junit.framework.Test;
21 > import junit.framework.TestSuite;
22  
23   public class CountedCompleterTest extends JSR166TestCase {
24  
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28  
29      public static Test suite() {
# Line 47 | Line 49 | public class CountedCompleterTest extend
49      }
50  
51      private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) {
52 <        try {
52 >        try (PoolCleaner cleaner = cleaner(pool)) {
53              assertFalse(a.isDone());
54              assertFalse(a.isCompletedNormally());
55              assertFalse(a.isCompletedAbnormally());
# Line 63 | Line 65 | public class CountedCompleterTest extend
65              assertFalse(a.isCancelled());
66              assertNull(a.getException());
67              assertNull(a.getRawResult());
66        } finally {
67            joinPool(pool);
68          }
69      }
70  
# Line 83 | Line 83 | public class CountedCompleterTest extend
83          } catch (Throwable fail) { threadUnexpectedException(fail); }
84      }
85  
86 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
87 <        checkCompletedNormally(a, null);
88 <    }
89 <
90 <    <T> void checkCompletedNormally(CountedCompleter<T> a, T expected) {
86 >    void checkCompletedNormally(CountedCompleter<?> a) {
87          assertTrue(a.isDone());
88          assertFalse(a.isCancelled());
89          assertTrue(a.isCompletedNormally());
90          assertFalse(a.isCompletedAbnormally());
91          assertNull(a.getException());
92 <        assertSame(expected, a.getRawResult());
92 >        assertNull(a.getRawResult());
93  
94          {
95              Thread.currentThread().interrupt();
96 <            long t0 = System.nanoTime();
97 <            assertSame(expected, a.join());
98 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
96 >            long startTime = System.nanoTime();
97 >            assertNull(a.join());
98 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
99              Thread.interrupted();
100          }
101  
102          {
103              Thread.currentThread().interrupt();
104 <            long t0 = System.nanoTime();
104 >            long startTime = System.nanoTime();
105              a.quietlyJoin();        // should be no-op
106 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
106 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
107              Thread.interrupted();
108          }
109  
110          assertFalse(a.cancel(false));
111          assertFalse(a.cancel(true));
112          try {
113 <            assertSame(expected, a.get());
113 >            assertNull(a.get());
114          } catch (Throwable fail) { threadUnexpectedException(fail); }
115          try {
116 <            assertSame(expected, a.get(5L, SECONDS));
116 >            assertNull(a.get(5L, SECONDS));
117          } catch (Throwable fail) { threadUnexpectedException(fail); }
118      }
119  
# Line 140 | Line 136 | public class CountedCompleterTest extend
136          Thread.interrupted();
137  
138          {
139 <            long t0 = System.nanoTime();
139 >            long startTime = System.nanoTime();
140              a.quietlyJoin();        // should be no-op
141 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
141 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
142          }
143  
144          try {
# Line 178 | Line 174 | public class CountedCompleterTest extend
174          Thread.interrupted();
175  
176          {
177 <            long t0 = System.nanoTime();
177 >            long startTime = System.nanoTime();
178              a.quietlyJoin();        // should be no-op
179 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
179 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
180          }
181  
182          try {
# Line 196 | Line 192 | public class CountedCompleterTest extend
192          } catch (ExecutionException success) {
193              assertSame(t.getClass(), success.getCause().getClass());
194          } catch (Throwable fail) { threadUnexpectedException(fail); }
195 +
196 +        try {
197 +            a.invoke();
198 +            shouldThrow();
199 +        } catch (Throwable success) {
200 +            assertSame(t, success);
201 +        }
202      }
203  
204      public static final class FJException extends RuntimeException {
205          FJException() { super(); }
206      }
207  
208 <    static final class NoopCountedCompleter extends CountedCompleter {
209 <        boolean post; // set true if onCompletion called
210 <        NoopCountedCompleter() { super(); }
211 <        NoopCountedCompleter(CountedCompleter p) { super(p); }
212 <        public void compute() {}
213 <        public final void onCompletion(CountedCompleter caller) {
214 <            post = true;
208 >    abstract class CheckedCC extends CountedCompleter<Object> {
209 >        final AtomicInteger computeN = new AtomicInteger(0);
210 >        final AtomicInteger onCompletionN = new AtomicInteger(0);
211 >        final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
212 >        final AtomicInteger setRawResultN = new AtomicInteger(0);
213 >        final AtomicReference<Object> rawResult = new AtomicReference<Object>(null);
214 >        int computeN() { return computeN.get(); }
215 >        int onCompletionN() { return onCompletionN.get(); }
216 >        int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }
217 >        int setRawResultN() { return setRawResultN.get(); }
218 >
219 >        CheckedCC() { super(); }
220 >        CheckedCC(CountedCompleter p) { super(p); }
221 >        CheckedCC(CountedCompleter p, int n) { super(p, n); }
222 >        abstract void realCompute();
223 >        public final void compute() {
224 >            computeN.incrementAndGet();
225 >            realCompute();
226 >        }
227 >        public void onCompletion(CountedCompleter caller) {
228 >            onCompletionN.incrementAndGet();
229 >            super.onCompletion(caller);
230 >        }
231 >        public boolean onExceptionalCompletion(Throwable ex,
232 >                                               CountedCompleter caller) {
233 >            onExceptionalCompletionN.incrementAndGet();
234 >            assertNotNull(ex);
235 >            assertTrue(isCompletedAbnormally());
236 >            assertTrue(super.onExceptionalCompletion(ex, caller));
237 >            return true;
238 >        }
239 >        protected void setRawResult(Object t) {
240 >            setRawResultN.incrementAndGet();
241 >            rawResult.set(t);
242 >            super.setRawResult(t);
243 >        }
244 >        void checkIncomplete() {
245 >            assertEquals(0, computeN());
246 >            assertEquals(0, onCompletionN());
247 >            assertEquals(0, onExceptionalCompletionN());
248 >            assertEquals(0, setRawResultN());
249 >            checkNotDone(this);
250 >        }
251 >        void checkCompletes(Object rawResult) {
252 >            checkIncomplete();
253 >            int pendingCount = getPendingCount();
254 >            complete(rawResult);
255 >            assertEquals(pendingCount, getPendingCount());
256 >            assertEquals(0, computeN());
257 >            assertEquals(1, onCompletionN());
258 >            assertEquals(0, onExceptionalCompletionN());
259 >            assertEquals(1, setRawResultN());
260 >            assertSame(rawResult, this.rawResult.get());
261 >            checkCompletedNormally(this);
262 >        }
263 >        void checkCompletesExceptionally(Throwable ex) {
264 >            checkIncomplete();
265 >            completeExceptionally(ex);
266 >            checkCompletedExceptionally(ex);
267 >        }
268 >        void checkCompletedExceptionally(Throwable ex) {
269 >            assertEquals(0, computeN());
270 >            assertEquals(0, onCompletionN());
271 >            assertEquals(1, onExceptionalCompletionN());
272 >            assertEquals(0, setRawResultN());
273 >            assertNull(this.rawResult.get());
274 >            checkCompletedAbnormally(this, ex);
275          }
276      }
277  
278 +    final class NoopCC extends CheckedCC {
279 +        NoopCC() { super(); }
280 +        NoopCC(CountedCompleter p) { super(p); }
281 +        NoopCC(CountedCompleter p, int initialPendingCount) {
282 +            super(p, initialPendingCount);
283 +        }
284 +        protected void realCompute() {}
285 +    }
286 +
287      /**
288       * A newly constructed CountedCompleter is not completed;
289 <     * complete() causes completion.
289 >     * complete() causes completion. pendingCount is ignored.
290       */
291      public void testComplete() {
292 <        NoopCountedCompleter a = new NoopCountedCompleter();
293 <        assertFalse(a.isDone());
294 <        assertFalse(a.isCompletedNormally());
295 <        assertFalse(a.isCompletedAbnormally());
296 <        assertFalse(a.isCancelled());
297 <        assertNull(a.getException());
298 <        assertNull(a.getRawResult());
299 <        assertFalse(a.post);
300 <        a.complete(null);
301 <        assertTrue(a.post);
302 <        assertTrue(a.isDone());
231 <        assertTrue(a.isCompletedNormally());
232 <        assertFalse(a.isCompletedAbnormally());
233 <        assertFalse(a.isCancelled());
234 <        assertNull(a.getException());
235 <        assertNull(a.getRawResult());
292 >        for (Object x : new Object[] { Boolean.TRUE, null }) {
293 >            for (int pendingCount : new int[] { 0, 42 }) {
294 >                testComplete(new NoopCC(), x, pendingCount);
295 >                testComplete(new NoopCC(new NoopCC()), x, pendingCount);
296 >            }
297 >        }
298 >    }
299 >    void testComplete(NoopCC cc, Object x, int pendingCount) {
300 >        cc.setPendingCount(pendingCount);
301 >        cc.checkCompletes(x);
302 >        assertEquals(pendingCount, cc.getPendingCount());
303      }
304  
305      /**
306       * completeExceptionally completes exceptionally
307       */
308      public void testCompleteExceptionally() {
309 <        NoopCountedCompleter a = new NoopCountedCompleter();
310 <        assertFalse(a.isDone());
311 <        assertFalse(a.isCompletedNormally());
312 <        assertFalse(a.isCompletedAbnormally());
313 <        assertFalse(a.isCancelled());
314 <        assertNull(a.getException());
315 <        assertNull(a.getRawResult());
316 <        assertFalse(a.post);
317 <        a.completeExceptionally(new FJException());
318 <        assertFalse(a.post);
319 <        assertTrue(a.isDone());
320 <        assertFalse(a.isCompletedNormally());
321 <        assertTrue(a.isCompletedAbnormally());
322 <        assertFalse(a.isCancelled());
323 <        assertTrue(a.getException() instanceof FJException);
324 <        assertNull(a.getRawResult());
309 >        new NoopCC()
310 >            .checkCompletesExceptionally(new FJException());
311 >        new NoopCC(new NoopCC())
312 >            .checkCompletesExceptionally(new FJException());
313 >    }
314 >
315 >    /**
316 >     * completeExceptionally(null) surprisingly has the same effect as
317 >     * completeExceptionally(new RuntimeException())
318 >     */
319 >    public void testCompleteExceptionally_null() {
320 >        NoopCC a = new NoopCC();
321 >        a.completeExceptionally(null);
322 >        try {
323 >            a.invoke();
324 >            shouldThrow();
325 >        } catch (RuntimeException success) {
326 >            assertSame(success.getClass(), RuntimeException.class);
327 >            assertNull(success.getCause());
328 >            a.checkCompletedExceptionally(success);
329 >        }
330      }
331  
332      /**
333       * setPendingCount sets the reported pending count
334       */
335      public void testSetPendingCount() {
336 <        NoopCountedCompleter a = new NoopCountedCompleter();
336 >        NoopCC a = new NoopCC();
337          assertEquals(0, a.getPendingCount());
338 <        a.setPendingCount(1);
339 <        assertEquals(1, a.getPendingCount());
340 <        a.setPendingCount(27);
341 <        assertEquals(27, a.getPendingCount());
338 >        int[] vals = {
339 >             -1, 0, 1,
340 >             Integer.MIN_VALUE,
341 >             Integer.MAX_VALUE,
342 >        };
343 >        for (int val : vals) {
344 >            a.setPendingCount(val);
345 >            assertEquals(val, a.getPendingCount());
346 >        }
347      }
348  
349      /**
350       * addToPendingCount adds to the reported pending count
351       */
352      public void testAddToPendingCount() {
353 <        NoopCountedCompleter a = new NoopCountedCompleter();
353 >        NoopCC a = new NoopCC();
354          assertEquals(0, a.getPendingCount());
355          a.addToPendingCount(1);
356          assertEquals(1, a.getPendingCount());
# Line 285 | Line 362 | public class CountedCompleterTest extend
362       * decrementPendingCountUnlessZero decrements reported pending
363       * count unless zero
364       */
365 <    public void testDecrementPendingCount() {
366 <        NoopCountedCompleter a = new NoopCountedCompleter();
367 <        assertEquals(0, a.getPendingCount());
368 <        a.addToPendingCount(1);
365 >    public void testDecrementPendingCountUnlessZero() {
366 >        NoopCC a = new NoopCC(null, 2);
367 >        assertEquals(2, a.getPendingCount());
368 >        assertEquals(2, a.decrementPendingCountUnlessZero());
369          assertEquals(1, a.getPendingCount());
370 <        a.decrementPendingCountUnlessZero();
370 >        assertEquals(1, a.decrementPendingCountUnlessZero());
371          assertEquals(0, a.getPendingCount());
372 <        a.decrementPendingCountUnlessZero();
372 >        assertEquals(0, a.decrementPendingCountUnlessZero());
373          assertEquals(0, a.getPendingCount());
374 +        a.setPendingCount(-1);
375 +        assertEquals(-1, a.decrementPendingCountUnlessZero());
376 +        assertEquals(-2, a.getPendingCount());
377 +    }
378 +
379 +    /**
380 +     * compareAndSetPendingCount compares and sets the reported
381 +     * pending count
382 +     */
383 +    public void testCompareAndSetPendingCount() {
384 +        NoopCC a = new NoopCC();
385 +        assertEquals(0, a.getPendingCount());
386 +        assertTrue(a.compareAndSetPendingCount(0, 1));
387 +        assertEquals(1, a.getPendingCount());
388 +        assertTrue(a.compareAndSetPendingCount(1, 2));
389 +        assertEquals(2, a.getPendingCount());
390 +        assertFalse(a.compareAndSetPendingCount(1, 3));
391 +        assertEquals(2, a.getPendingCount());
392      }
393  
394      /**
395       * getCompleter returns parent or null if at root
396       */
397      public void testGetCompleter() {
398 <        NoopCountedCompleter a = new NoopCountedCompleter();
398 >        NoopCC a = new NoopCC();
399          assertNull(a.getCompleter());
400 <        CountedCompleter b = new NoopCountedCompleter(a);
401 <        assertEquals(a, b.getCompleter());
400 >        CountedCompleter b = new NoopCC(a);
401 >        assertSame(a, b.getCompleter());
402 >        CountedCompleter c = new NoopCC(b);
403 >        assertSame(b, c.getCompleter());
404      }
405  
406      /**
407       * getRoot returns self if no parent, else parent's root
408       */
409      public void testGetRoot() {
410 <        NoopCountedCompleter a = new NoopCountedCompleter();
411 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
412 <        assertEquals(a, a.getRoot());
413 <        assertEquals(a, b.getRoot());
410 >        NoopCC a = new NoopCC();
411 >        NoopCC b = new NoopCC(a);
412 >        NoopCC c = new NoopCC(b);
413 >        assertSame(a, a.getRoot());
414 >        assertSame(a, b.getRoot());
415 >        assertSame(a, c.getRoot());
416      }
417  
418      /**
419 <     * tryComplete causes completion if pending count is zero
419 >     * tryComplete decrements pending count unless zero, in which case
420 >     * causes completion
421       */
422 <    public void testTryComplete1() {
423 <        NoopCountedCompleter a = new NoopCountedCompleter();
422 >    public void testTryComplete() {
423 >        NoopCC a = new NoopCC();
424          assertEquals(0, a.getPendingCount());
425 +        int n = 3;
426 +        a.setPendingCount(n);
427 +        for (; n > 0; n--) {
428 +            assertEquals(n, a.getPendingCount());
429 +            a.tryComplete();
430 +            a.checkIncomplete();
431 +            assertEquals(n - 1, a.getPendingCount());
432 +        }
433          a.tryComplete();
434 <        assertTrue(a.post);
435 <        assertTrue(a.isDone());
434 >        assertEquals(0, a.computeN());
435 >        assertEquals(1, a.onCompletionN());
436 >        assertEquals(0, a.onExceptionalCompletionN());
437 >        assertEquals(0, a.setRawResultN());
438 >        checkCompletedNormally(a);
439      }
440  
441      /**
442 <     * propagateCompletion causes completion without invoking
443 <     * onCompletion if pending count is zero
442 >     * propagateCompletion decrements pending count unless zero, in
443 >     * which case causes completion, without invoking onCompletion
444       */
445      public void testPropagateCompletion() {
446 <        NoopCountedCompleter a = new NoopCountedCompleter();
446 >        NoopCC a = new NoopCC();
447          assertEquals(0, a.getPendingCount());
448 +        int n = 3;
449 +        a.setPendingCount(n);
450 +        for (; n > 0; n--) {
451 +            assertEquals(n, a.getPendingCount());
452 +            a.propagateCompletion();
453 +            a.checkIncomplete();
454 +            assertEquals(n - 1, a.getPendingCount());
455 +        }
456          a.propagateCompletion();
457 <        assertFalse(a.post);
458 <        assertTrue(a.isDone());
459 <    }
460 <
461 <    /**
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());
457 >        assertEquals(0, a.computeN());
458 >        assertEquals(0, a.onCompletionN());
459 >        assertEquals(0, a.onExceptionalCompletionN());
460 >        assertEquals(0, a.setRawResultN());
461 >        checkCompletedNormally(a);
462      }
463  
464      /**
465       * firstComplete returns this if pending count is zero else null
466       */
467      public void testFirstComplete() {
468 <        NoopCountedCompleter a = new NoopCountedCompleter();
468 >        NoopCC a = new NoopCC();
469          a.setPendingCount(1);
470          assertNull(a.firstComplete());
471 <        assertEquals(a, a.firstComplete());
471 >        a.checkIncomplete();
472 >        assertSame(a, a.firstComplete());
473 >        a.checkIncomplete();
474      }
475  
476      /**
# Line 370 | Line 478 | public class CountedCompleterTest extend
478       * zero else null
479       */
480      public void testNextComplete() {
481 <        NoopCountedCompleter a = new NoopCountedCompleter();
482 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
481 >        NoopCC a = new NoopCC();
482 >        NoopCC b = new NoopCC(a);
483          a.setPendingCount(1);
484          b.setPendingCount(1);
485          assertNull(b.firstComplete());
486 <        CountedCompleter c = b.firstComplete();
487 <        assertEquals(b, c);
488 <        CountedCompleter d = c.nextComplete();
489 <        assertNull(d);
490 <        CountedCompleter e = c.nextComplete();
491 <        assertEquals(a, e);
486 >        assertSame(b, b.firstComplete());
487 >        assertNull(b.nextComplete());
488 >        a.checkIncomplete();
489 >        b.checkIncomplete();
490 >        assertSame(a, b.nextComplete());
491 >        assertSame(a, b.nextComplete());
492 >        a.checkIncomplete();
493 >        b.checkIncomplete();
494 >        assertNull(a.nextComplete());
495 >        b.checkIncomplete();
496 >        checkCompletedNormally(a);
497      }
498  
499      /**
500       * quietlyCompleteRoot completes root task
501       */
502      public void testQuietlyCompleteRoot() {
503 <        NoopCountedCompleter a = new NoopCountedCompleter();
504 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
503 >        NoopCC a = new NoopCC();
504 >        NoopCC b = new NoopCC(a);
505 >        NoopCC c = new NoopCC(b);
506          a.setPendingCount(1);
507          b.setPendingCount(1);
508 <        b.quietlyCompleteRoot();
508 >        c.setPendingCount(1);
509 >        c.quietlyCompleteRoot();
510          assertTrue(a.isDone());
511          assertFalse(b.isDone());
512 +        assertFalse(c.isDone());
513      }
514  
515      // Invocation tests use some interdependent task classes
516      // to better test propagation etc
517  
518 <
519 <    // Version of Fibonacci with different classes for left vs right forks
520 <    abstract static class CCF extends CountedCompleter {
518 >    /**
519 >     * Version of Fibonacci with different classes for left vs right forks
520 >     */
521 >    abstract class CCF extends CheckedCC {
522          int number;
523          int rnumber;
524  
# Line 410 | Line 527 | public class CountedCompleterTest extend
527              this.number = n;
528          }
529  
530 <        public final void compute() {
414 <            CountedCompleter p;
530 >        protected final void realCompute() {
531              CCF f = this;
532              int n = number;
533              while (n >= 2) {
534                  new RCCF(f, n - 2).fork();
535                  f = new LCCF(f, --n);
536              }
537 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
537 >            f.complete(null);
538          }
539      }
540  
541 <    static final class LCCF extends CCF {
541 >    final class LCCF extends CCF {
542 >        public LCCF(int n) { this(null, n); }
543          public LCCF(CountedCompleter parent, int n) {
544              super(parent, n);
545          }
546          public final void onCompletion(CountedCompleter caller) {
547 +            super.onCompletion(caller);
548              CCF p = (CCF)getCompleter();
549              int n = number + rnumber;
550              if (p != null)
# Line 440 | Line 553 | public class CountedCompleterTest extend
553                  number = n;
554          }
555      }
556 <    static final class RCCF extends CCF {
556 >    final class RCCF extends CCF {
557          public RCCF(CountedCompleter parent, int n) {
558              super(parent, n);
559          }
560          public final void onCompletion(CountedCompleter caller) {
561 +            super.onCompletion(caller);
562              CCF p = (CCF)getCompleter();
563              int n = number + rnumber;
564              if (p != null)
# Line 455 | Line 569 | public class CountedCompleterTest extend
569      }
570  
571      // Version of CCF with forced failure in left completions
572 <    abstract static class FailingCCF extends CountedCompleter {
572 >    abstract class FailingCCF extends CheckedCC {
573          int number;
574          int rnumber;
575  
# Line 464 | Line 578 | public class CountedCompleterTest extend
578              this.number = n;
579          }
580  
581 <        public final void compute() {
468 <            CountedCompleter p;
581 >        protected final void realCompute() {
582              FailingCCF f = this;
583              int n = number;
584              while (n >= 2) {
585                  new RFCCF(f, n - 2).fork();
586                  f = new LFCCF(f, --n);
587              }
588 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
588 >            f.complete(null);
589          }
590      }
591  
592 <    static final class LFCCF extends FailingCCF {
592 >    final class LFCCF extends FailingCCF {
593 >        public LFCCF(int n) { this(null, n); }
594          public LFCCF(CountedCompleter parent, int n) {
595              super(parent, n);
596          }
597          public final void onCompletion(CountedCompleter caller) {
598 +            super.onCompletion(caller);
599              FailingCCF p = (FailingCCF)getCompleter();
600              int n = number + rnumber;
601              if (p != null)
# Line 494 | Line 604 | public class CountedCompleterTest extend
604                  number = n;
605          }
606      }
607 <    static final class RFCCF extends FailingCCF {
607 >    final class RFCCF extends FailingCCF {
608          public RFCCF(CountedCompleter parent, int n) {
609              super(parent, n);
610          }
611          public final void onCompletion(CountedCompleter caller) {
612 +            super.onCompletion(caller);
613              completeExceptionally(new FJException());
614          }
615      }
# Line 511 | Line 622 | public class CountedCompleterTest extend
622      public void testInvoke() {
623          ForkJoinTask a = new CheckedRecursiveAction() {
624              protected void realCompute() {
625 <                CCF f = new LCCF(null, 8);
625 >                CCF f = new LCCF(8);
626                  assertNull(f.invoke());
627                  assertEquals(21, f.number);
628                  checkCompletedNormally(f);
# Line 527 | Line 638 | public class CountedCompleterTest extend
638      public void testQuietlyInvoke() {
639          ForkJoinTask a = new CheckedRecursiveAction() {
640              protected void realCompute() {
641 <                CCF f = new LCCF(null, 8);
641 >                CCF f = new LCCF(8);
642                  f.quietlyInvoke();
643                  assertEquals(21, f.number);
644                  checkCompletedNormally(f);
# Line 541 | Line 652 | public class CountedCompleterTest extend
652      public void testForkJoin() {
653          ForkJoinTask a = new CheckedRecursiveAction() {
654              protected void realCompute() {
655 <                CCF f = new LCCF(null, 8);
655 >                CCF f = new LCCF(8);
656                  assertSame(f, f.fork());
657                  assertNull(f.join());
658                  assertEquals(21, f.number);
# Line 556 | Line 667 | public class CountedCompleterTest extend
667      public void testForkGet() {
668          ForkJoinTask a = new CheckedRecursiveAction() {
669              protected void realCompute() throws Exception {
670 <                CCF f = new LCCF(null, 8);
670 >                CCF f = new LCCF(8);
671                  assertSame(f, f.fork());
672                  assertNull(f.get());
673                  assertEquals(21, f.number);
# Line 571 | Line 682 | public class CountedCompleterTest extend
682      public void testForkTimedGet() {
683          ForkJoinTask a = new CheckedRecursiveAction() {
684              protected void realCompute() throws Exception {
685 <                CCF f = new LCCF(null, 8);
685 >                CCF f = new LCCF(8);
686                  assertSame(f, f.fork());
687                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
688                  assertEquals(21, f.number);
# Line 586 | Line 697 | public class CountedCompleterTest extend
697      public void testForkTimedGetNPE() {
698          ForkJoinTask a = new CheckedRecursiveAction() {
699              protected void realCompute() throws Exception {
700 <                CCF f = new LCCF(null, 8);
700 >                CCF f = new LCCF(8);
701                  assertSame(f, f.fork());
702                  try {
703                      f.get(5L, null);
# Line 602 | Line 713 | public class CountedCompleterTest extend
713      public void testForkQuietlyJoin() {
714          ForkJoinTask a = new CheckedRecursiveAction() {
715              protected void realCompute() {
716 <                CCF f = new LCCF(null, 8);
716 >                CCF f = new LCCF(8);
717                  assertSame(f, f.fork());
718                  f.quietlyJoin();
719                  assertEquals(21, f.number);
# Line 618 | Line 729 | public class CountedCompleterTest extend
729      public void testForkHelpQuiesce() {
730          ForkJoinTask a = new CheckedRecursiveAction() {
731              protected void realCompute() {
732 <                CCF f = new LCCF(null, 8);
732 >                CCF f = new LCCF(8);
733                  assertSame(f, f.fork());
734                  helpQuiesce();
735                  assertEquals(21, f.number);
# Line 634 | Line 745 | public class CountedCompleterTest extend
745      public void testAbnormalInvoke() {
746          ForkJoinTask a = new CheckedRecursiveAction() {
747              protected void realCompute() {
748 <                FailingCCF f = new LFCCF(null, 8);
748 >                FailingCCF f = new LFCCF(8);
749                  try {
750                      f.invoke();
751                      shouldThrow();
# Line 651 | Line 762 | public class CountedCompleterTest extend
762      public void testAbnormalQuietlyInvoke() {
763          ForkJoinTask a = new CheckedRecursiveAction() {
764              protected void realCompute() {
765 <                FailingCCF f = new LFCCF(null, 8);
765 >                FailingCCF f = new LFCCF(8);
766                  f.quietlyInvoke();
767                  assertTrue(f.getException() instanceof FJException);
768                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 776 | public class CountedCompleterTest extend
776      public void testAbnormalForkJoin() {
777          ForkJoinTask a = new CheckedRecursiveAction() {
778              protected void realCompute() {
779 <                FailingCCF f = new LFCCF(null, 8);
779 >                FailingCCF f = new LFCCF(8);
780                  assertSame(f, f.fork());
781                  try {
782                      f.join();
# Line 683 | Line 794 | public class CountedCompleterTest extend
794      public void testAbnormalForkGet() {
795          ForkJoinTask a = new CheckedRecursiveAction() {
796              protected void realCompute() throws Exception {
797 <                FailingCCF f = new LFCCF(null, 8);
797 >                FailingCCF f = new LFCCF(8);
798                  assertSame(f, f.fork());
799                  try {
800                      f.get();
# Line 703 | Line 814 | public class CountedCompleterTest extend
814      public void testAbnormalForkTimedGet() {
815          ForkJoinTask a = new CheckedRecursiveAction() {
816              protected void realCompute() throws Exception {
817 <                FailingCCF f = new LFCCF(null, 8);
817 >                FailingCCF f = new LFCCF(8);
818                  assertSame(f, f.fork());
819                  try {
820                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 834 | public class CountedCompleterTest extend
834      public void testAbnormalForkQuietlyJoin() {
835          ForkJoinTask a = new CheckedRecursiveAction() {
836              protected void realCompute() {
837 <                FailingCCF f = new LFCCF(null, 8);
837 >                FailingCCF f = new LFCCF(8);
838                  assertSame(f, f.fork());
839                  f.quietlyJoin();
840                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 849 | public class CountedCompleterTest extend
849      public void testCancelledInvoke() {
850          ForkJoinTask a = new CheckedRecursiveAction() {
851              protected void realCompute() {
852 <                CCF f = new LCCF(null, 8);
852 >                CCF f = new LCCF(8);
853                  assertTrue(f.cancel(true));
854                  try {
855                      f.invoke();
# Line 756 | Line 867 | public class CountedCompleterTest extend
867      public void testCancelledForkJoin() {
868          ForkJoinTask a = new CheckedRecursiveAction() {
869              protected void realCompute() {
870 <                CCF f = new LCCF(null, 8);
870 >                CCF f = new LCCF(8);
871                  assertTrue(f.cancel(true));
872                  assertSame(f, f.fork());
873                  try {
# Line 775 | Line 886 | public class CountedCompleterTest extend
886      public void testCancelledForkGet() {
887          ForkJoinTask a = new CheckedRecursiveAction() {
888              protected void realCompute() throws Exception {
889 <                CCF f = new LCCF(null, 8);
889 >                CCF f = new LCCF(8);
890                  assertTrue(f.cancel(true));
891                  assertSame(f, f.fork());
892                  try {
# Line 794 | Line 905 | public class CountedCompleterTest extend
905      public void testCancelledForkTimedGet() throws Exception {
906          ForkJoinTask a = new CheckedRecursiveAction() {
907              protected void realCompute() throws Exception {
908 <                CCF f = new LCCF(null, 8);
908 >                CCF f = new LCCF(8);
909                  assertTrue(f.cancel(true));
910                  assertSame(f, f.fork());
911                  try {
# Line 813 | Line 924 | public class CountedCompleterTest extend
924      public void testCancelledForkQuietlyJoin() {
925          ForkJoinTask a = new CheckedRecursiveAction() {
926              protected void realCompute() {
927 <                CCF f = new LCCF(null, 8);
927 >                CCF f = new LCCF(8);
928                  assertTrue(f.cancel(true));
929                  assertSame(f, f.fork());
930                  f.quietlyJoin();
# Line 885 | Line 996 | public class CountedCompleterTest extend
996      public void testCompleteExceptionally2() {
997          ForkJoinTask a = new CheckedRecursiveAction() {
998              protected void realCompute() {
999 <                CCF f = new LCCF(null, 8);
1000 <                f.completeExceptionally(new FJException());
1001 <                try {
1002 <                    f.invoke();
1003 <                    shouldThrow();
1004 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
999 >                CCF n = new LCCF(8);
1000 >                CCF f = new LCCF(n, 8);
1001 >                FJException ex = new FJException();
1002 >                f.completeExceptionally(ex);
1003 >                f.checkCompletedExceptionally(ex);
1004 >                n.checkCompletedExceptionally(ex);
1005              }};
1006          testInvokeOnPool(mainPool(), a);
1007      }
# Line 903 | Line 1012 | public class CountedCompleterTest extend
1012      public void testInvokeAll2() {
1013          ForkJoinTask a = new CheckedRecursiveAction() {
1014              protected void realCompute() {
1015 <                CCF f = new LCCF(null, 8);
1016 <                CCF g = new LCCF(null, 9);
1015 >                CCF f = new LCCF(8);
1016 >                CCF g = new LCCF(9);
1017                  invokeAll(f, g);
1018                  assertEquals(21, f.number);
1019                  assertEquals(34, g.number);
# Line 920 | Line 1029 | public class CountedCompleterTest extend
1029      public void testInvokeAll1() {
1030          ForkJoinTask a = new CheckedRecursiveAction() {
1031              protected void realCompute() {
1032 <                CCF f = new LCCF(null, 8);
1032 >                CCF f = new LCCF(8);
1033                  invokeAll(f);
1034                  checkCompletedNormally(f);
1035                  assertEquals(21, f.number);
# Line 934 | Line 1043 | public class CountedCompleterTest extend
1043      public void testInvokeAll3() {
1044          ForkJoinTask a = new CheckedRecursiveAction() {
1045              protected void realCompute() {
1046 <                CCF f = new LCCF(null, 8);
1047 <                CCF g = new LCCF(null, 9);
1048 <                CCF h = new LCCF(null, 7);
1046 >                CCF f = new LCCF(8);
1047 >                CCF g = new LCCF(9);
1048 >                CCF h = new LCCF(7);
1049                  invokeAll(f, g, h);
1050                  assertEquals(21, f.number);
1051                  assertEquals(34, g.number);
# Line 954 | Line 1063 | public class CountedCompleterTest extend
1063      public void testInvokeAllCollection() {
1064          ForkJoinTask a = new CheckedRecursiveAction() {
1065              protected void realCompute() {
1066 <                CCF f = new LCCF(null, 8);
1067 <                CCF g = new LCCF(null, 9);
1068 <                CCF h = new LCCF(null, 7);
1066 >                CCF f = new LCCF(8);
1067 >                CCF g = new LCCF(9);
1068 >                CCF h = new LCCF(7);
1069                  HashSet set = new HashSet();
1070                  set.add(f);
1071                  set.add(g);
# Line 978 | Line 1087 | public class CountedCompleterTest extend
1087      public void testInvokeAllNPE() {
1088          ForkJoinTask a = new CheckedRecursiveAction() {
1089              protected void realCompute() {
1090 <                CCF f = new LCCF(null, 8);
1091 <                CCF g = new LCCF(null, 9);
1090 >                CCF f = new LCCF(8);
1091 >                CCF g = new LCCF(9);
1092                  CCF h = null;
1093                  try {
1094                      invokeAll(f, g, h);
# Line 995 | Line 1104 | public class CountedCompleterTest extend
1104      public void testAbnormalInvokeAll2() {
1105          ForkJoinTask a = new CheckedRecursiveAction() {
1106              protected void realCompute() {
1107 <                CCF f = new LCCF(null, 8);
1108 <                FailingCCF g = new LFCCF(null, 9);
1107 >                CCF f = new LCCF(8);
1108 >                FailingCCF g = new LFCCF(9);
1109                  try {
1110                      invokeAll(f, g);
1111                      shouldThrow();
# Line 1013 | Line 1122 | public class CountedCompleterTest extend
1122      public void testAbnormalInvokeAll1() {
1123          ForkJoinTask a = new CheckedRecursiveAction() {
1124              protected void realCompute() {
1125 <                FailingCCF g = new LFCCF(null, 9);
1125 >                FailingCCF g = new LFCCF(9);
1126                  try {
1127                      invokeAll(g);
1128                      shouldThrow();
# Line 1030 | Line 1139 | public class CountedCompleterTest extend
1139      public void testAbnormalInvokeAll3() {
1140          ForkJoinTask a = new CheckedRecursiveAction() {
1141              protected void realCompute() {
1142 <                CCF f = new LCCF(null, 8);
1143 <                FailingCCF g = new LFCCF(null, 9);
1144 <                CCF h = new LCCF(null, 7);
1142 >                CCF f = new LCCF(8);
1143 >                FailingCCF g = new LFCCF(9);
1144 >                CCF h = new LCCF(7);
1145                  try {
1146                      invokeAll(f, g, h);
1147                      shouldThrow();
# Line 1044 | Line 1153 | public class CountedCompleterTest extend
1153      }
1154  
1155      /**
1156 <     * invokeAll(collection)  throws exception if any task does
1156 >     * invokeAll(collection) throws exception if any task does
1157       */
1158      public void testAbnormalInvokeAllCollection() {
1159          ForkJoinTask a = new CheckedRecursiveAction() {
1160              protected void realCompute() {
1161 <                FailingCCF f = new LFCCF(null, 8);
1162 <                CCF g = new LCCF(null, 9);
1163 <                CCF h = new LCCF(null, 7);
1161 >                FailingCCF f = new LFCCF(8);
1162 >                CCF g = new LCCF(9);
1163 >                CCF h = new LCCF(7);
1164                  HashSet set = new HashSet();
1165                  set.add(f);
1166                  set.add(g);
# Line 1073 | Line 1182 | public class CountedCompleterTest extend
1182      public void testTryUnfork() {
1183          ForkJoinTask a = new CheckedRecursiveAction() {
1184              protected void realCompute() {
1185 <                CCF g = new LCCF(null, 9);
1185 >                CCF g = new LCCF(9);
1186                  assertSame(g, g.fork());
1187 <                CCF f = new LCCF(null, 8);
1187 >                CCF f = new LCCF(8);
1188                  assertSame(f, f.fork());
1189                  assertTrue(f.tryUnfork());
1190                  helpQuiesce();
# Line 1092 | Line 1201 | public class CountedCompleterTest extend
1201      public void testGetSurplusQueuedTaskCount() {
1202          ForkJoinTask a = new CheckedRecursiveAction() {
1203              protected void realCompute() {
1204 <                CCF h = new LCCF(null, 7);
1204 >                CCF h = new LCCF(7);
1205                  assertSame(h, h.fork());
1206 <                CCF g = new LCCF(null, 9);
1206 >                CCF g = new LCCF(9);
1207                  assertSame(g, g.fork());
1208 <                CCF f = new LCCF(null, 8);
1208 >                CCF f = new LCCF(8);
1209                  assertSame(f, f.fork());
1210                  assertTrue(getSurplusQueuedTaskCount() > 0);
1211                  helpQuiesce();
# Line 1114 | Line 1223 | public class CountedCompleterTest extend
1223      public void testPeekNextLocalTask() {
1224          ForkJoinTask a = new CheckedRecursiveAction() {
1225              protected void realCompute() {
1226 <                CCF g = new LCCF(null, 9);
1226 >                CCF g = new LCCF(9);
1227                  assertSame(g, g.fork());
1228 <                CCF f = new LCCF(null, 8);
1228 >                CCF f = new LCCF(8);
1229                  assertSame(f, f.fork());
1230                  assertSame(f, peekNextLocalTask());
1231                  assertNull(f.join());
# Line 1134 | Line 1243 | public class CountedCompleterTest extend
1243      public void testPollNextLocalTask() {
1244          ForkJoinTask a = new CheckedRecursiveAction() {
1245              protected void realCompute() {
1246 <                CCF g = new LCCF(null, 9);
1246 >                CCF g = new LCCF(9);
1247                  assertSame(g, g.fork());
1248 <                CCF f = new LCCF(null, 8);
1248 >                CCF f = new LCCF(8);
1249                  assertSame(f, f.fork());
1250                  assertSame(f, pollNextLocalTask());
1251                  helpQuiesce();
# Line 1153 | Line 1262 | public class CountedCompleterTest extend
1262      public void testPollTask() {
1263          ForkJoinTask a = new CheckedRecursiveAction() {
1264              protected void realCompute() {
1265 <                CCF g = new LCCF(null, 9);
1265 >                CCF g = new LCCF(9);
1266                  assertSame(g, g.fork());
1267 <                CCF f = new LCCF(null, 8);
1267 >                CCF f = new LCCF(8);
1268                  assertSame(f, f.fork());
1269                  assertSame(f, pollTask());
1270                  helpQuiesce();
# Line 1171 | Line 1280 | public class CountedCompleterTest extend
1280      public void testPeekNextLocalTaskAsync() {
1281          ForkJoinTask a = new CheckedRecursiveAction() {
1282              protected void realCompute() {
1283 <                CCF g = new LCCF(null, 9);
1283 >                CCF g = new LCCF(9);
1284                  assertSame(g, g.fork());
1285 <                CCF f = new LCCF(null, 8);
1285 >                CCF f = new LCCF(8);
1286                  assertSame(f, f.fork());
1287                  assertSame(g, peekNextLocalTask());
1288                  assertNull(f.join());
# Line 1192 | Line 1301 | public class CountedCompleterTest extend
1301      public void testPollNextLocalTaskAsync() {
1302          ForkJoinTask a = new CheckedRecursiveAction() {
1303              protected void realCompute() {
1304 <                CCF g = new LCCF(null, 9);
1304 >                CCF g = new LCCF(9);
1305                  assertSame(g, g.fork());
1306 <                CCF f = new LCCF(null, 8);
1306 >                CCF f = new LCCF(8);
1307                  assertSame(f, f.fork());
1308                  assertSame(g, pollNextLocalTask());
1309                  helpQuiesce();
# Line 1212 | Line 1321 | public class CountedCompleterTest extend
1321      public void testPollTaskAsync() {
1322          ForkJoinTask a = new CheckedRecursiveAction() {
1323              protected void realCompute() {
1324 <                CCF g = new LCCF(null, 9);
1324 >                CCF g = new LCCF(9);
1325                  assertSame(g, g.fork());
1326 <                CCF f = new LCCF(null, 8);
1326 >                CCF f = new LCCF(8);
1327                  assertSame(f, f.fork());
1328                  assertSame(g, pollTask());
1329                  helpQuiesce();
# Line 1235 | Line 1344 | public class CountedCompleterTest extend
1344      public void testInvokeSingleton() {
1345          ForkJoinTask a = new CheckedRecursiveAction() {
1346              protected void realCompute() {
1347 <                CCF f = new LCCF(null, 8);
1347 >                CCF f = new LCCF(8);
1348                  assertNull(f.invoke());
1349                  assertEquals(21, f.number);
1350                  checkCompletedNormally(f);
# Line 1251 | Line 1360 | public class CountedCompleterTest extend
1360      public void testQuietlyInvokeSingleton() {
1361          ForkJoinTask a = new CheckedRecursiveAction() {
1362              protected void realCompute() {
1363 <                CCF f = new LCCF(null, 8);
1363 >                CCF f = new LCCF(8);
1364                  f.quietlyInvoke();
1365                  assertEquals(21, f.number);
1366                  checkCompletedNormally(f);
# Line 1265 | Line 1374 | public class CountedCompleterTest extend
1374      public void testForkJoinSingleton() {
1375          ForkJoinTask a = new CheckedRecursiveAction() {
1376              protected void realCompute() {
1377 <                CCF f = new LCCF(null, 8);
1377 >                CCF f = new LCCF(8);
1378                  assertSame(f, f.fork());
1379                  assertNull(f.join());
1380                  assertEquals(21, f.number);
# Line 1280 | Line 1389 | public class CountedCompleterTest extend
1389      public void testForkGetSingleton() {
1390          ForkJoinTask a = new CheckedRecursiveAction() {
1391              protected void realCompute() throws Exception {
1392 <                CCF f = new LCCF(null, 8);
1392 >                CCF f = new LCCF(8);
1393                  assertSame(f, f.fork());
1394                  assertNull(f.get());
1395                  assertEquals(21, f.number);
# Line 1295 | Line 1404 | public class CountedCompleterTest extend
1404      public void testForkTimedGetSingleton() {
1405          ForkJoinTask a = new CheckedRecursiveAction() {
1406              protected void realCompute() throws Exception {
1407 <                CCF f = new LCCF(null, 8);
1407 >                CCF f = new LCCF(8);
1408                  assertSame(f, f.fork());
1409                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1410                  assertEquals(21, f.number);
# Line 1310 | Line 1419 | public class CountedCompleterTest extend
1419      public void testForkTimedGetNPESingleton() {
1420          ForkJoinTask a = new CheckedRecursiveAction() {
1421              protected void realCompute() throws Exception {
1422 <                CCF f = new LCCF(null, 8);
1422 >                CCF f = new LCCF(8);
1423                  assertSame(f, f.fork());
1424                  try {
1425                      f.get(5L, null);
# Line 1326 | Line 1435 | public class CountedCompleterTest extend
1435      public void testForkQuietlyJoinSingleton() {
1436          ForkJoinTask a = new CheckedRecursiveAction() {
1437              protected void realCompute() {
1438 <                CCF f = new LCCF(null, 8);
1438 >                CCF f = new LCCF(8);
1439                  assertSame(f, f.fork());
1440                  f.quietlyJoin();
1441                  assertEquals(21, f.number);
# Line 1342 | Line 1451 | public class CountedCompleterTest extend
1451      public void testForkHelpQuiesceSingleton() {
1452          ForkJoinTask a = new CheckedRecursiveAction() {
1453              protected void realCompute() {
1454 <                CCF f = new LCCF(null, 8);
1454 >                CCF f = new LCCF(8);
1455                  assertSame(f, f.fork());
1456                  helpQuiesce();
1457                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1467 | public class CountedCompleterTest extend
1467      public void testAbnormalInvokeSingleton() {
1468          ForkJoinTask a = new CheckedRecursiveAction() {
1469              protected void realCompute() {
1470 <                FailingCCF f = new LFCCF(null, 8);
1470 >                FailingCCF f = new LFCCF(8);
1471                  try {
1472                      f.invoke();
1473                      shouldThrow();
# Line 1375 | Line 1484 | public class CountedCompleterTest extend
1484      public void testAbnormalQuietlyInvokeSingleton() {
1485          ForkJoinTask a = new CheckedRecursiveAction() {
1486              protected void realCompute() {
1487 <                FailingCCF f = new LFCCF(null, 8);
1487 >                FailingCCF f = new LFCCF(8);
1488                  f.quietlyInvoke();
1489                  assertTrue(f.getException() instanceof FJException);
1490                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1498 | public class CountedCompleterTest extend
1498      public void testAbnormalForkJoinSingleton() {
1499          ForkJoinTask a = new CheckedRecursiveAction() {
1500              protected void realCompute() {
1501 <                FailingCCF f = new LFCCF(null, 8);
1501 >                FailingCCF f = new LFCCF(8);
1502                  assertSame(f, f.fork());
1503                  try {
1504                      f.join();
# Line 1407 | Line 1516 | public class CountedCompleterTest extend
1516      public void testAbnormalForkGetSingleton() {
1517          ForkJoinTask a = new CheckedRecursiveAction() {
1518              protected void realCompute() throws Exception {
1519 <                FailingCCF f = new LFCCF(null, 8);
1519 >                FailingCCF f = new LFCCF(8);
1520                  assertSame(f, f.fork());
1521                  try {
1522                      f.get();
# Line 1427 | Line 1536 | public class CountedCompleterTest extend
1536      public void testAbnormalForkTimedGetSingleton() {
1537          ForkJoinTask a = new CheckedRecursiveAction() {
1538              protected void realCompute() throws Exception {
1539 <                FailingCCF f = new LFCCF(null, 8);
1539 >                FailingCCF f = new LFCCF(8);
1540                  assertSame(f, f.fork());
1541                  try {
1542                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1556 | public class CountedCompleterTest extend
1556      public void testAbnormalForkQuietlyJoinSingleton() {
1557          ForkJoinTask a = new CheckedRecursiveAction() {
1558              protected void realCompute() {
1559 <                FailingCCF f = new LFCCF(null, 8);
1559 >                FailingCCF f = new LFCCF(8);
1560                  assertSame(f, f.fork());
1561                  f.quietlyJoin();
1562                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1571 | public class CountedCompleterTest extend
1571      public void testCancelledInvokeSingleton() {
1572          ForkJoinTask a = new CheckedRecursiveAction() {
1573              protected void realCompute() {
1574 <                CCF f = new LCCF(null, 8);
1574 >                CCF f = new LCCF(8);
1575                  assertTrue(f.cancel(true));
1576                  try {
1577                      f.invoke();
# Line 1480 | Line 1589 | public class CountedCompleterTest extend
1589      public void testCancelledForkJoinSingleton() {
1590          ForkJoinTask a = new CheckedRecursiveAction() {
1591              protected void realCompute() {
1592 <                CCF f = new LCCF(null, 8);
1592 >                CCF f = new LCCF(8);
1593                  assertTrue(f.cancel(true));
1594                  assertSame(f, f.fork());
1595                  try {
# Line 1499 | Line 1608 | public class CountedCompleterTest extend
1608      public void testCancelledForkGetSingleton() {
1609          ForkJoinTask a = new CheckedRecursiveAction() {
1610              protected void realCompute() throws Exception {
1611 <                CCF f = new LCCF(null, 8);
1611 >                CCF f = new LCCF(8);
1612                  assertTrue(f.cancel(true));
1613                  assertSame(f, f.fork());
1614                  try {
# Line 1518 | Line 1627 | public class CountedCompleterTest extend
1627      public void testCancelledForkTimedGetSingleton() throws Exception {
1628          ForkJoinTask a = new CheckedRecursiveAction() {
1629              protected void realCompute() throws Exception {
1630 <                CCF f = new LCCF(null, 8);
1630 >                CCF f = new LCCF(8);
1631                  assertTrue(f.cancel(true));
1632                  assertSame(f, f.fork());
1633                  try {
# Line 1537 | Line 1646 | public class CountedCompleterTest extend
1646      public void testCancelledForkQuietlyJoinSingleton() {
1647          ForkJoinTask a = new CheckedRecursiveAction() {
1648              protected void realCompute() {
1649 <                CCF f = new LCCF(null, 8);
1649 >                CCF f = new LCCF(8);
1650                  assertTrue(f.cancel(true));
1651                  assertSame(f, f.fork());
1652                  f.quietlyJoin();
# Line 1552 | Line 1661 | public class CountedCompleterTest extend
1661      public void testCompleteExceptionallySingleton() {
1662          ForkJoinTask a = new CheckedRecursiveAction() {
1663              protected void realCompute() {
1664 <                CCF f = new LCCF(null, 8);
1665 <                f.completeExceptionally(new FJException());
1666 <                try {
1667 <                    f.invoke();
1668 <                    shouldThrow();
1669 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1664 >                CCF n = new LCCF(8);
1665 >                CCF f = new LCCF(n, 8);
1666 >                FJException ex = new FJException();
1667 >                f.completeExceptionally(ex);
1668 >                f.checkCompletedExceptionally(ex);
1669 >                n.checkCompletedExceptionally(ex);
1670              }};
1671          testInvokeOnPool(singletonPool(), a);
1672      }
# Line 1570 | Line 1677 | public class CountedCompleterTest extend
1677      public void testInvokeAll2Singleton() {
1678          ForkJoinTask a = new CheckedRecursiveAction() {
1679              protected void realCompute() {
1680 <                CCF f = new LCCF(null, 8);
1681 <                CCF g = new LCCF(null, 9);
1680 >                CCF f = new LCCF(8);
1681 >                CCF g = new LCCF(9);
1682                  invokeAll(f, g);
1683                  assertEquals(21, f.number);
1684                  assertEquals(34, g.number);
# Line 1587 | Line 1694 | public class CountedCompleterTest extend
1694      public void testInvokeAll1Singleton() {
1695          ForkJoinTask a = new CheckedRecursiveAction() {
1696              protected void realCompute() {
1697 <                CCF f = new LCCF(null, 8);
1697 >                CCF f = new LCCF(8);
1698                  invokeAll(f);
1699                  checkCompletedNormally(f);
1700                  assertEquals(21, f.number);
# Line 1601 | Line 1708 | public class CountedCompleterTest extend
1708      public void testInvokeAll3Singleton() {
1709          ForkJoinTask a = new CheckedRecursiveAction() {
1710              protected void realCompute() {
1711 <                CCF f = new LCCF(null, 8);
1712 <                CCF g = new LCCF(null, 9);
1713 <                CCF h = new LCCF(null, 7);
1711 >                CCF f = new LCCF(8);
1712 >                CCF g = new LCCF(9);
1713 >                CCF h = new LCCF(7);
1714                  invokeAll(f, g, h);
1715                  assertEquals(21, f.number);
1716                  assertEquals(34, g.number);
# Line 1621 | Line 1728 | public class CountedCompleterTest extend
1728      public void testInvokeAllCollectionSingleton() {
1729          ForkJoinTask a = new CheckedRecursiveAction() {
1730              protected void realCompute() {
1731 <                CCF f = new LCCF(null, 8);
1732 <                CCF g = new LCCF(null, 9);
1733 <                CCF h = new LCCF(null, 7);
1731 >                CCF f = new LCCF(8);
1732 >                CCF g = new LCCF(9);
1733 >                CCF h = new LCCF(7);
1734                  HashSet set = new HashSet();
1735                  set.add(f);
1736                  set.add(g);
# Line 1645 | Line 1752 | public class CountedCompleterTest extend
1752      public void testInvokeAllNPESingleton() {
1753          ForkJoinTask a = new CheckedRecursiveAction() {
1754              protected void realCompute() {
1755 <                CCF f = new LCCF(null, 8);
1756 <                CCF g = new LCCF(null, 9);
1755 >                CCF f = new LCCF(8);
1756 >                CCF g = new LCCF(9);
1757                  CCF h = null;
1758                  try {
1759                      invokeAll(f, g, h);
# Line 1662 | Line 1769 | public class CountedCompleterTest extend
1769      public void testAbnormalInvokeAll2Singleton() {
1770          ForkJoinTask a = new CheckedRecursiveAction() {
1771              protected void realCompute() {
1772 <                CCF f = new LCCF(null, 8);
1773 <                FailingCCF g = new LFCCF(null, 9);
1772 >                CCF f = new LCCF(8);
1773 >                FailingCCF g = new LFCCF(9);
1774                  try {
1775                      invokeAll(f, g);
1776                      shouldThrow();
# Line 1680 | Line 1787 | public class CountedCompleterTest extend
1787      public void testAbnormalInvokeAll1Singleton() {
1788          ForkJoinTask a = new CheckedRecursiveAction() {
1789              protected void realCompute() {
1790 <                FailingCCF g = new LFCCF(null, 9);
1790 >                FailingCCF g = new LFCCF(9);
1791                  try {
1792                      invokeAll(g);
1793                      shouldThrow();
# Line 1697 | Line 1804 | public class CountedCompleterTest extend
1804      public void testAbnormalInvokeAll3Singleton() {
1805          ForkJoinTask a = new CheckedRecursiveAction() {
1806              protected void realCompute() {
1807 <                CCF f = new LCCF(null, 8);
1808 <                FailingCCF g = new LFCCF(null, 9);
1809 <                CCF h = new LCCF(null, 7);
1807 >                CCF f = new LCCF(8);
1808 >                FailingCCF g = new LFCCF(9);
1809 >                CCF h = new LCCF(7);
1810                  try {
1811                      invokeAll(f, g, h);
1812                      shouldThrow();
# Line 1711 | Line 1818 | public class CountedCompleterTest extend
1818      }
1819  
1820      /**
1821 <     * invokeAll(collection)  throws exception if any task does
1821 >     * invokeAll(collection) throws exception if any task does
1822       */
1823      public void testAbnormalInvokeAllCollectionSingleton() {
1824          ForkJoinTask a = new CheckedRecursiveAction() {
1825              protected void realCompute() {
1826 <                FailingCCF f = new LFCCF(null, 8);
1827 <                CCF g = new LCCF(null, 9);
1828 <                CCF h = new LCCF(null, 7);
1826 >                FailingCCF f = new LFCCF(8);
1827 >                CCF g = new LCCF(9);
1828 >                CCF h = new LCCF(7);
1829                  HashSet set = new HashSet();
1830                  set.add(f);
1831                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines