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.31 by jsr166, Wed Jan 4 06:09:58 2017 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;
16 < 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.ThreadLocalRandom;
17   import java.util.concurrent.TimeoutException;
18 < import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
19 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 < import static java.util.concurrent.TimeUnit.SECONDS;
21 < import java.util.HashSet;
22 < import junit.framework.*;
18 > import java.util.concurrent.atomic.AtomicInteger;
19 > import java.util.concurrent.atomic.AtomicReference;
20 >
21 > import junit.framework.Test;
22 > import junit.framework.TestSuite;
23  
24   public class CountedCompleterTest extends JSR166TestCase {
25  
26      public static void main(String[] args) {
27 <        junit.textui.TestRunner.run(suite());
27 >        main(suite(), args);
28      }
29  
30      public static Test suite() {
# Line 47 | Line 50 | public class CountedCompleterTest extend
50      }
51  
52      private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) {
53 <        try {
53 >        try (PoolCleaner cleaner = cleaner(pool)) {
54              assertFalse(a.isDone());
55              assertFalse(a.isCompletedNormally());
56              assertFalse(a.isCompletedAbnormally());
# Line 63 | Line 66 | public class CountedCompleterTest extend
66              assertFalse(a.isCancelled());
67              assertNull(a.getException());
68              assertNull(a.getRawResult());
66        } finally {
67            joinPool(pool);
69          }
70      }
71  
# Line 83 | Line 84 | public class CountedCompleterTest extend
84          } catch (Throwable fail) { threadUnexpectedException(fail); }
85      }
86  
87 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
87 <        checkCompletedNormally(a, null);
88 <    }
89 <
90 <    <T> void checkCompletedNormally(CountedCompleter<T> a, T expected) {
87 >    void checkCompletedNormally(CountedCompleter<?> a) {
88          assertTrue(a.isDone());
89          assertFalse(a.isCancelled());
90          assertTrue(a.isCompletedNormally());
91          assertFalse(a.isCompletedAbnormally());
92          assertNull(a.getException());
93 <        assertSame(expected, a.getRawResult());
93 >        assertNull(a.getRawResult());
94  
95          {
96              Thread.currentThread().interrupt();
97 <            long t0 = System.nanoTime();
98 <            assertSame(expected, a.join());
99 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
97 >            long startTime = System.nanoTime();
98 >            assertNull(a.join());
99 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
100              Thread.interrupted();
101          }
102  
103          {
104              Thread.currentThread().interrupt();
105 <            long t0 = System.nanoTime();
105 >            long startTime = System.nanoTime();
106              a.quietlyJoin();        // should be no-op
107 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
107 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
108              Thread.interrupted();
109          }
110  
111          assertFalse(a.cancel(false));
112          assertFalse(a.cancel(true));
113          try {
114 <            assertSame(expected, a.get());
114 >            assertNull(a.get());
115          } catch (Throwable fail) { threadUnexpectedException(fail); }
116          try {
117 <            assertSame(expected, a.get(5L, SECONDS));
117 >            assertNull(a.get(5L, SECONDS));
118          } catch (Throwable fail) { threadUnexpectedException(fail); }
119      }
120  
# Line 140 | Line 137 | public class CountedCompleterTest extend
137          Thread.interrupted();
138  
139          {
140 <            long t0 = System.nanoTime();
140 >            long startTime = System.nanoTime();
141              a.quietlyJoin();        // should be no-op
142 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
142 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
143          }
144  
145          try {
# Line 178 | Line 175 | public class CountedCompleterTest extend
175          Thread.interrupted();
176  
177          {
178 <            long t0 = System.nanoTime();
178 >            long startTime = System.nanoTime();
179              a.quietlyJoin();        // should be no-op
180 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
180 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
181          }
182  
183          try {
# Line 196 | Line 193 | public class CountedCompleterTest extend
193          } catch (ExecutionException success) {
194              assertSame(t.getClass(), success.getCause().getClass());
195          } catch (Throwable fail) { threadUnexpectedException(fail); }
196 +
197 +        try {
198 +            a.invoke();
199 +            shouldThrow();
200 +        } catch (Throwable success) {
201 +            assertSame(t, success);
202 +        }
203      }
204  
205      public static final class FJException extends RuntimeException {
206          FJException() { super(); }
207      }
208  
209 <    static final class NoopCountedCompleter extends CountedCompleter {
210 <        boolean post; // set true if onCompletion called
211 <        NoopCountedCompleter() { super(); }
212 <        NoopCountedCompleter(CountedCompleter p) { super(p); }
213 <        public void compute() {}
214 <        public final void onCompletion(CountedCompleter caller) {
215 <            post = true;
209 >    abstract class CheckedCC extends CountedCompleter<Object> {
210 >        final AtomicInteger computeN = new AtomicInteger(0);
211 >        final AtomicInteger onCompletionN = new AtomicInteger(0);
212 >        final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
213 >        final AtomicInteger setRawResultN = new AtomicInteger(0);
214 >        final AtomicReference<Object> rawResult = new AtomicReference<>(null);
215 >        int computeN() { return computeN.get(); }
216 >        int onCompletionN() { return onCompletionN.get(); }
217 >        int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }
218 >        int setRawResultN() { return setRawResultN.get(); }
219 >
220 >        CheckedCC() { super(); }
221 >        CheckedCC(CountedCompleter p) { super(p); }
222 >        CheckedCC(CountedCompleter p, int n) { super(p, n); }
223 >        abstract void realCompute();
224 >        public final void compute() {
225 >            computeN.incrementAndGet();
226 >            realCompute();
227 >        }
228 >        public void onCompletion(CountedCompleter caller) {
229 >            onCompletionN.incrementAndGet();
230 >            super.onCompletion(caller);
231 >        }
232 >        public boolean onExceptionalCompletion(Throwable ex,
233 >                                               CountedCompleter caller) {
234 >            onExceptionalCompletionN.incrementAndGet();
235 >            assertNotNull(ex);
236 >            assertTrue(isCompletedAbnormally());
237 >            assertTrue(super.onExceptionalCompletion(ex, caller));
238 >            return true;
239 >        }
240 >        protected void setRawResult(Object t) {
241 >            setRawResultN.incrementAndGet();
242 >            rawResult.set(t);
243 >            super.setRawResult(t);
244 >        }
245 >        void checkIncomplete() {
246 >            assertEquals(0, computeN());
247 >            assertEquals(0, onCompletionN());
248 >            assertEquals(0, onExceptionalCompletionN());
249 >            assertEquals(0, setRawResultN());
250 >            checkNotDone(this);
251 >        }
252 >        void checkCompletes(Object rawResult) {
253 >            checkIncomplete();
254 >            int pendingCount = getPendingCount();
255 >            complete(rawResult);
256 >            assertEquals(pendingCount, getPendingCount());
257 >            assertEquals(0, computeN());
258 >            assertEquals(1, onCompletionN());
259 >            assertEquals(0, onExceptionalCompletionN());
260 >            assertEquals(1, setRawResultN());
261 >            assertSame(rawResult, this.rawResult.get());
262 >            checkCompletedNormally(this);
263 >        }
264 >        void checkCompletesExceptionally(Throwable ex) {
265 >            checkIncomplete();
266 >            completeExceptionally(ex);
267 >            checkCompletedExceptionally(ex);
268 >        }
269 >        void checkCompletedExceptionally(Throwable ex) {
270 >            assertEquals(0, computeN());
271 >            assertEquals(0, onCompletionN());
272 >            assertEquals(1, onExceptionalCompletionN());
273 >            assertEquals(0, setRawResultN());
274 >            assertNull(this.rawResult.get());
275 >            checkCompletedAbnormally(this, ex);
276          }
277      }
278  
279 +    final class NoopCC extends CheckedCC {
280 +        NoopCC() { super(); }
281 +        NoopCC(CountedCompleter p) { super(p); }
282 +        NoopCC(CountedCompleter p, int initialPendingCount) {
283 +            super(p, initialPendingCount);
284 +        }
285 +        protected void realCompute() {}
286 +    }
287 +
288      /**
289       * A newly constructed CountedCompleter is not completed;
290 <     * complete() causes completion.
290 >     * complete() causes completion. pendingCount is ignored.
291       */
292      public void testComplete() {
293 <        NoopCountedCompleter a = new NoopCountedCompleter();
294 <        assertFalse(a.isDone());
295 <        assertFalse(a.isCompletedNormally());
296 <        assertFalse(a.isCompletedAbnormally());
297 <        assertFalse(a.isCancelled());
298 <        assertNull(a.getException());
299 <        assertNull(a.getRawResult());
300 <        assertFalse(a.post);
301 <        a.complete(null);
302 <        assertTrue(a.post);
303 <        assertTrue(a.isDone());
231 <        assertTrue(a.isCompletedNormally());
232 <        assertFalse(a.isCompletedAbnormally());
233 <        assertFalse(a.isCancelled());
234 <        assertNull(a.getException());
235 <        assertNull(a.getRawResult());
293 >        for (Object x : new Object[] { Boolean.TRUE, null }) {
294 >            for (int pendingCount : new int[] { 0, 42 }) {
295 >                testComplete(new NoopCC(), x, pendingCount);
296 >                testComplete(new NoopCC(new NoopCC()), x, pendingCount);
297 >            }
298 >        }
299 >    }
300 >    void testComplete(NoopCC cc, Object x, int pendingCount) {
301 >        cc.setPendingCount(pendingCount);
302 >        cc.checkCompletes(x);
303 >        assertEquals(pendingCount, cc.getPendingCount());
304      }
305  
306      /**
307       * completeExceptionally completes exceptionally
308       */
309      public void testCompleteExceptionally() {
310 <        NoopCountedCompleter a = new NoopCountedCompleter();
311 <        assertFalse(a.isDone());
312 <        assertFalse(a.isCompletedNormally());
313 <        assertFalse(a.isCompletedAbnormally());
314 <        assertFalse(a.isCancelled());
315 <        assertNull(a.getException());
316 <        assertNull(a.getRawResult());
317 <        assertFalse(a.post);
318 <        a.completeExceptionally(new FJException());
319 <        assertFalse(a.post);
320 <        assertTrue(a.isDone());
321 <        assertFalse(a.isCompletedNormally());
322 <        assertTrue(a.isCompletedAbnormally());
323 <        assertFalse(a.isCancelled());
324 <        assertTrue(a.getException() instanceof FJException);
325 <        assertNull(a.getRawResult());
310 >        new NoopCC()
311 >            .checkCompletesExceptionally(new FJException());
312 >        new NoopCC(new NoopCC())
313 >            .checkCompletesExceptionally(new FJException());
314 >    }
315 >
316 >    /**
317 >     * completeExceptionally(null) surprisingly has the same effect as
318 >     * completeExceptionally(new RuntimeException())
319 >     */
320 >    public void testCompleteExceptionally_null() {
321 >        NoopCC a = new NoopCC();
322 >        a.completeExceptionally(null);
323 >        try {
324 >            a.invoke();
325 >            shouldThrow();
326 >        } catch (RuntimeException success) {
327 >            assertSame(success.getClass(), RuntimeException.class);
328 >            assertNull(success.getCause());
329 >            a.checkCompletedExceptionally(success);
330 >        }
331      }
332  
333      /**
334       * setPendingCount sets the reported pending count
335       */
336      public void testSetPendingCount() {
337 <        NoopCountedCompleter a = new NoopCountedCompleter();
337 >        NoopCC a = new NoopCC();
338          assertEquals(0, a.getPendingCount());
339 <        a.setPendingCount(1);
340 <        assertEquals(1, a.getPendingCount());
341 <        a.setPendingCount(27);
342 <        assertEquals(27, a.getPendingCount());
339 >        int[] vals = {
340 >             -1, 0, 1,
341 >             Integer.MIN_VALUE,
342 >             Integer.MAX_VALUE,
343 >        };
344 >        for (int val : vals) {
345 >            a.setPendingCount(val);
346 >            assertEquals(val, a.getPendingCount());
347 >        }
348      }
349  
350      /**
351       * addToPendingCount adds to the reported pending count
352       */
353      public void testAddToPendingCount() {
354 <        NoopCountedCompleter a = new NoopCountedCompleter();
354 >        NoopCC a = new NoopCC();
355          assertEquals(0, a.getPendingCount());
356          a.addToPendingCount(1);
357          assertEquals(1, a.getPendingCount());
358          a.addToPendingCount(27);
359          assertEquals(28, a.getPendingCount());
360 +        a.addToPendingCount(-28);
361 +        assertEquals(0, a.getPendingCount());
362      }
363  
364      /**
365       * decrementPendingCountUnlessZero decrements reported pending
366       * count unless zero
367       */
368 <    public void testDecrementPendingCount() {
369 <        NoopCountedCompleter a = new NoopCountedCompleter();
370 <        assertEquals(0, a.getPendingCount());
371 <        a.addToPendingCount(1);
368 >    public void testDecrementPendingCountUnlessZero() {
369 >        NoopCC a = new NoopCC(null, 2);
370 >        assertEquals(2, a.getPendingCount());
371 >        assertEquals(2, a.decrementPendingCountUnlessZero());
372          assertEquals(1, a.getPendingCount());
373 <        a.decrementPendingCountUnlessZero();
373 >        assertEquals(1, a.decrementPendingCountUnlessZero());
374          assertEquals(0, a.getPendingCount());
375 <        a.decrementPendingCountUnlessZero();
375 >        assertEquals(0, a.decrementPendingCountUnlessZero());
376 >        assertEquals(0, a.getPendingCount());
377 >        a.setPendingCount(-1);
378 >        assertEquals(-1, a.decrementPendingCountUnlessZero());
379 >        assertEquals(-2, a.getPendingCount());
380 >    }
381 >
382 >    /**
383 >     * compareAndSetPendingCount compares and sets the reported
384 >     * pending count
385 >     */
386 >    public void testCompareAndSetPendingCount() {
387 >        NoopCC a = new NoopCC();
388          assertEquals(0, a.getPendingCount());
389 +        assertTrue(a.compareAndSetPendingCount(0, 1));
390 +        assertEquals(1, a.getPendingCount());
391 +        assertTrue(a.compareAndSetPendingCount(1, 2));
392 +        assertEquals(2, a.getPendingCount());
393 +        assertFalse(a.compareAndSetPendingCount(1, 3));
394 +        assertEquals(2, a.getPendingCount());
395      }
396  
397      /**
398       * getCompleter returns parent or null if at root
399       */
400      public void testGetCompleter() {
401 <        NoopCountedCompleter a = new NoopCountedCompleter();
401 >        NoopCC a = new NoopCC();
402          assertNull(a.getCompleter());
403 <        CountedCompleter b = new NoopCountedCompleter(a);
404 <        assertEquals(a, b.getCompleter());
403 >        CountedCompleter b = new NoopCC(a);
404 >        assertSame(a, b.getCompleter());
405 >        CountedCompleter c = new NoopCC(b);
406 >        assertSame(b, c.getCompleter());
407      }
408  
409      /**
410       * getRoot returns self if no parent, else parent's root
411       */
412      public void testGetRoot() {
413 <        NoopCountedCompleter a = new NoopCountedCompleter();
414 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
415 <        assertEquals(a, a.getRoot());
416 <        assertEquals(a, b.getRoot());
413 >        NoopCC a = new NoopCC();
414 >        NoopCC b = new NoopCC(a);
415 >        NoopCC c = new NoopCC(b);
416 >        assertSame(a, a.getRoot());
417 >        assertSame(a, b.getRoot());
418 >        assertSame(a, c.getRoot());
419      }
420  
421      /**
422 <     * tryComplete causes completion if pending count is zero
422 >     * tryComplete decrements pending count unless zero, in which case
423 >     * causes completion
424       */
425 <    public void testTryComplete1() {
426 <        NoopCountedCompleter a = new NoopCountedCompleter();
425 >    public void testTryComplete() {
426 >        NoopCC a = new NoopCC();
427          assertEquals(0, a.getPendingCount());
428 +        int n = 3;
429 +        a.setPendingCount(n);
430 +        for (; n > 0; n--) {
431 +            assertEquals(n, a.getPendingCount());
432 +            a.tryComplete();
433 +            a.checkIncomplete();
434 +            assertEquals(n - 1, a.getPendingCount());
435 +        }
436          a.tryComplete();
437 <        assertTrue(a.post);
438 <        assertTrue(a.isDone());
437 >        assertEquals(0, a.computeN());
438 >        assertEquals(1, a.onCompletionN());
439 >        assertEquals(0, a.onExceptionalCompletionN());
440 >        assertEquals(0, a.setRawResultN());
441 >        checkCompletedNormally(a);
442      }
443  
444      /**
445 <     * propagateCompletion causes completion without invoking
446 <     * onCompletion if pending count is zero
445 >     * propagateCompletion decrements pending count unless zero, in
446 >     * which case causes completion, without invoking onCompletion
447       */
448      public void testPropagateCompletion() {
449 <        NoopCountedCompleter a = new NoopCountedCompleter();
449 >        NoopCC a = new NoopCC();
450          assertEquals(0, a.getPendingCount());
451 +        int n = 3;
452 +        a.setPendingCount(n);
453 +        for (; n > 0; n--) {
454 +            assertEquals(n, a.getPendingCount());
455 +            a.propagateCompletion();
456 +            a.checkIncomplete();
457 +            assertEquals(n - 1, a.getPendingCount());
458 +        }
459          a.propagateCompletion();
460 <        assertFalse(a.post);
461 <        assertTrue(a.isDone());
462 <    }
463 <
464 <    /**
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());
460 >        assertEquals(0, a.computeN());
461 >        assertEquals(0, a.onCompletionN());
462 >        assertEquals(0, a.onExceptionalCompletionN());
463 >        assertEquals(0, a.setRawResultN());
464 >        checkCompletedNormally(a);
465      }
466  
467      /**
468       * firstComplete returns this if pending count is zero else null
469       */
470      public void testFirstComplete() {
471 <        NoopCountedCompleter a = new NoopCountedCompleter();
471 >        NoopCC a = new NoopCC();
472          a.setPendingCount(1);
473          assertNull(a.firstComplete());
474 <        assertEquals(a, a.firstComplete());
474 >        a.checkIncomplete();
475 >        assertSame(a, a.firstComplete());
476 >        a.checkIncomplete();
477      }
478  
479      /**
# Line 370 | Line 481 | public class CountedCompleterTest extend
481       * zero else null
482       */
483      public void testNextComplete() {
484 <        NoopCountedCompleter a = new NoopCountedCompleter();
485 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
484 >        NoopCC a = new NoopCC();
485 >        NoopCC b = new NoopCC(a);
486          a.setPendingCount(1);
487          b.setPendingCount(1);
488          assertNull(b.firstComplete());
489 <        CountedCompleter c = b.firstComplete();
490 <        assertEquals(b, c);
491 <        CountedCompleter d = c.nextComplete();
492 <        assertNull(d);
493 <        CountedCompleter e = c.nextComplete();
494 <        assertEquals(a, e);
489 >        assertSame(b, b.firstComplete());
490 >        assertNull(b.nextComplete());
491 >        a.checkIncomplete();
492 >        b.checkIncomplete();
493 >        assertSame(a, b.nextComplete());
494 >        assertSame(a, b.nextComplete());
495 >        a.checkIncomplete();
496 >        b.checkIncomplete();
497 >        assertNull(a.nextComplete());
498 >        b.checkIncomplete();
499 >        checkCompletedNormally(a);
500      }
501  
502      /**
503 <     * quietlyCompleteRoot completes root task
503 >     * quietlyCompleteRoot completes root task and only root task
504       */
505      public void testQuietlyCompleteRoot() {
506 <        NoopCountedCompleter a = new NoopCountedCompleter();
507 <        NoopCountedCompleter b = new NoopCountedCompleter(a);
506 >        NoopCC a = new NoopCC();
507 >        NoopCC b = new NoopCC(a);
508 >        NoopCC c = new NoopCC(b);
509          a.setPendingCount(1);
510          b.setPendingCount(1);
511 <        b.quietlyCompleteRoot();
511 >        c.setPendingCount(1);
512 >        c.quietlyCompleteRoot();
513          assertTrue(a.isDone());
514          assertFalse(b.isDone());
515 +        assertFalse(c.isDone());
516      }
517  
518      // Invocation tests use some interdependent task classes
519      // to better test propagation etc
520  
521 <
522 <    // Version of Fibonacci with different classes for left vs right forks
523 <    abstract static class CCF extends CountedCompleter {
521 >    /**
522 >     * Version of Fibonacci with different classes for left vs right forks
523 >     */
524 >    abstract class CCF extends CheckedCC {
525          int number;
526          int rnumber;
527  
# Line 410 | Line 530 | public class CountedCompleterTest extend
530              this.number = n;
531          }
532  
533 <        public final void compute() {
414 <            CountedCompleter p;
533 >        protected final void realCompute() {
534              CCF f = this;
535              int n = number;
536              while (n >= 2) {
537                  new RCCF(f, n - 2).fork();
538                  f = new LCCF(f, --n);
539              }
540 <            f.number = n;
422 <            f.onCompletion(f);
423 <            if ((p = f.getCompleter()) != null)
424 <                p.tryComplete();
425 <            else
426 <                f.quietlyComplete();
540 >            f.complete(null);
541          }
542      }
543  
544 <    static final class LCCF extends CCF {
544 >    final class LCCF extends CCF {
545 >        public LCCF(int n) { this(null, n); }
546          public LCCF(CountedCompleter parent, int n) {
547              super(parent, n);
548          }
549          public final void onCompletion(CountedCompleter caller) {
550 +            super.onCompletion(caller);
551              CCF p = (CCF)getCompleter();
552              int n = number + rnumber;
553              if (p != null)
# Line 440 | Line 556 | public class CountedCompleterTest extend
556                  number = n;
557          }
558      }
559 <    static final class RCCF extends CCF {
559 >    final class RCCF extends CCF {
560          public RCCF(CountedCompleter parent, int n) {
561              super(parent, n);
562          }
563          public final void onCompletion(CountedCompleter caller) {
564 +            super.onCompletion(caller);
565              CCF p = (CCF)getCompleter();
566              int n = number + rnumber;
567              if (p != null)
# Line 455 | Line 572 | public class CountedCompleterTest extend
572      }
573  
574      // Version of CCF with forced failure in left completions
575 <    abstract static class FailingCCF extends CountedCompleter {
575 >    abstract class FailingCCF extends CheckedCC {
576          int number;
577          int rnumber;
578  
# Line 464 | Line 581 | public class CountedCompleterTest extend
581              this.number = n;
582          }
583  
584 <        public final void compute() {
468 <            CountedCompleter p;
584 >        protected final void realCompute() {
585              FailingCCF f = this;
586              int n = number;
587              while (n >= 2) {
588                  new RFCCF(f, n - 2).fork();
589                  f = new LFCCF(f, --n);
590              }
591 <            f.number = n;
476 <            f.onCompletion(f);
477 <            if ((p = f.getCompleter()) != null)
478 <                p.tryComplete();
479 <            else
480 <                f.quietlyComplete();
591 >            f.complete(null);
592          }
593      }
594  
595 <    static final class LFCCF extends FailingCCF {
595 >    final class LFCCF extends FailingCCF {
596 >        public LFCCF(int n) { this(null, n); }
597          public LFCCF(CountedCompleter parent, int n) {
598              super(parent, n);
599          }
600          public final void onCompletion(CountedCompleter caller) {
601 +            super.onCompletion(caller);
602              FailingCCF p = (FailingCCF)getCompleter();
603              int n = number + rnumber;
604              if (p != null)
# Line 494 | Line 607 | public class CountedCompleterTest extend
607                  number = n;
608          }
609      }
610 <    static final class RFCCF extends FailingCCF {
610 >    final class RFCCF extends FailingCCF {
611          public RFCCF(CountedCompleter parent, int n) {
612              super(parent, n);
613          }
614          public final void onCompletion(CountedCompleter caller) {
615 +            super.onCompletion(caller);
616              completeExceptionally(new FJException());
617          }
618      }
# Line 511 | Line 625 | public class CountedCompleterTest extend
625      public void testInvoke() {
626          ForkJoinTask a = new CheckedRecursiveAction() {
627              protected void realCompute() {
628 <                CCF f = new LCCF(null, 8);
628 >                CCF f = new LCCF(8);
629                  assertNull(f.invoke());
630                  assertEquals(21, f.number);
631                  checkCompletedNormally(f);
# Line 527 | Line 641 | public class CountedCompleterTest extend
641      public void testQuietlyInvoke() {
642          ForkJoinTask a = new CheckedRecursiveAction() {
643              protected void realCompute() {
644 <                CCF f = new LCCF(null, 8);
644 >                CCF f = new LCCF(8);
645                  f.quietlyInvoke();
646                  assertEquals(21, f.number);
647                  checkCompletedNormally(f);
# Line 541 | Line 655 | public class CountedCompleterTest extend
655      public void testForkJoin() {
656          ForkJoinTask a = new CheckedRecursiveAction() {
657              protected void realCompute() {
658 <                CCF f = new LCCF(null, 8);
658 >                CCF f = new LCCF(8);
659                  assertSame(f, f.fork());
660                  assertNull(f.join());
661                  assertEquals(21, f.number);
# Line 556 | Line 670 | public class CountedCompleterTest extend
670      public void testForkGet() {
671          ForkJoinTask a = new CheckedRecursiveAction() {
672              protected void realCompute() throws Exception {
673 <                CCF f = new LCCF(null, 8);
673 >                CCF f = new LCCF(8);
674                  assertSame(f, f.fork());
675                  assertNull(f.get());
676                  assertEquals(21, f.number);
# Line 571 | Line 685 | public class CountedCompleterTest extend
685      public void testForkTimedGet() {
686          ForkJoinTask a = new CheckedRecursiveAction() {
687              protected void realCompute() throws Exception {
688 <                CCF f = new LCCF(null, 8);
688 >                CCF f = new LCCF(8);
689                  assertSame(f, f.fork());
690                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
691                  assertEquals(21, f.number);
# Line 586 | Line 700 | public class CountedCompleterTest extend
700      public void testForkTimedGetNPE() {
701          ForkJoinTask a = new CheckedRecursiveAction() {
702              protected void realCompute() throws Exception {
703 <                CCF f = new LCCF(null, 8);
703 >                CCF f = new LCCF(8);
704                  assertSame(f, f.fork());
705                  try {
706                      f.get(5L, null);
# Line 602 | Line 716 | public class CountedCompleterTest extend
716      public void testForkQuietlyJoin() {
717          ForkJoinTask a = new CheckedRecursiveAction() {
718              protected void realCompute() {
719 <                CCF f = new LCCF(null, 8);
719 >                CCF f = new LCCF(8);
720                  assertSame(f, f.fork());
721                  f.quietlyJoin();
722                  assertEquals(21, f.number);
# Line 618 | Line 732 | public class CountedCompleterTest extend
732      public void testForkHelpQuiesce() {
733          ForkJoinTask a = new CheckedRecursiveAction() {
734              protected void realCompute() {
735 <                CCF f = new LCCF(null, 8);
735 >                CCF f = new LCCF(8);
736                  assertSame(f, f.fork());
737                  helpQuiesce();
738                  assertEquals(21, f.number);
# Line 634 | Line 748 | public class CountedCompleterTest extend
748      public void testAbnormalInvoke() {
749          ForkJoinTask a = new CheckedRecursiveAction() {
750              protected void realCompute() {
751 <                FailingCCF f = new LFCCF(null, 8);
751 >                FailingCCF f = new LFCCF(8);
752                  try {
753                      f.invoke();
754                      shouldThrow();
# Line 651 | Line 765 | public class CountedCompleterTest extend
765      public void testAbnormalQuietlyInvoke() {
766          ForkJoinTask a = new CheckedRecursiveAction() {
767              protected void realCompute() {
768 <                FailingCCF f = new LFCCF(null, 8);
768 >                FailingCCF f = new LFCCF(8);
769                  f.quietlyInvoke();
770                  assertTrue(f.getException() instanceof FJException);
771                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 779 | public class CountedCompleterTest extend
779      public void testAbnormalForkJoin() {
780          ForkJoinTask a = new CheckedRecursiveAction() {
781              protected void realCompute() {
782 <                FailingCCF f = new LFCCF(null, 8);
782 >                FailingCCF f = new LFCCF(8);
783                  assertSame(f, f.fork());
784                  try {
785                      f.join();
# Line 683 | Line 797 | public class CountedCompleterTest extend
797      public void testAbnormalForkGet() {
798          ForkJoinTask a = new CheckedRecursiveAction() {
799              protected void realCompute() throws Exception {
800 <                FailingCCF f = new LFCCF(null, 8);
800 >                FailingCCF f = new LFCCF(8);
801                  assertSame(f, f.fork());
802                  try {
803                      f.get();
# Line 703 | Line 817 | public class CountedCompleterTest extend
817      public void testAbnormalForkTimedGet() {
818          ForkJoinTask a = new CheckedRecursiveAction() {
819              protected void realCompute() throws Exception {
820 <                FailingCCF f = new LFCCF(null, 8);
820 >                FailingCCF f = new LFCCF(8);
821                  assertSame(f, f.fork());
822                  try {
823                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 837 | public class CountedCompleterTest extend
837      public void testAbnormalForkQuietlyJoin() {
838          ForkJoinTask a = new CheckedRecursiveAction() {
839              protected void realCompute() {
840 <                FailingCCF f = new LFCCF(null, 8);
840 >                FailingCCF f = new LFCCF(8);
841                  assertSame(f, f.fork());
842                  f.quietlyJoin();
843                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 852 | public class CountedCompleterTest extend
852      public void testCancelledInvoke() {
853          ForkJoinTask a = new CheckedRecursiveAction() {
854              protected void realCompute() {
855 <                CCF f = new LCCF(null, 8);
855 >                CCF f = new LCCF(8);
856                  assertTrue(f.cancel(true));
857                  try {
858                      f.invoke();
# Line 756 | Line 870 | public class CountedCompleterTest extend
870      public void testCancelledForkJoin() {
871          ForkJoinTask a = new CheckedRecursiveAction() {
872              protected void realCompute() {
873 <                CCF f = new LCCF(null, 8);
873 >                CCF f = new LCCF(8);
874                  assertTrue(f.cancel(true));
875                  assertSame(f, f.fork());
876                  try {
# Line 775 | Line 889 | public class CountedCompleterTest extend
889      public void testCancelledForkGet() {
890          ForkJoinTask a = new CheckedRecursiveAction() {
891              protected void realCompute() throws Exception {
892 <                CCF f = new LCCF(null, 8);
892 >                CCF f = new LCCF(8);
893                  assertTrue(f.cancel(true));
894                  assertSame(f, f.fork());
895                  try {
# Line 794 | Line 908 | public class CountedCompleterTest extend
908      public void testCancelledForkTimedGet() throws Exception {
909          ForkJoinTask a = new CheckedRecursiveAction() {
910              protected void realCompute() throws Exception {
911 <                CCF f = new LCCF(null, 8);
911 >                CCF f = new LCCF(8);
912                  assertTrue(f.cancel(true));
913                  assertSame(f, f.fork());
914                  try {
# Line 813 | Line 927 | public class CountedCompleterTest extend
927      public void testCancelledForkQuietlyJoin() {
928          ForkJoinTask a = new CheckedRecursiveAction() {
929              protected void realCompute() {
930 <                CCF f = new LCCF(null, 8);
930 >                CCF f = new LCCF(8);
931                  assertTrue(f.cancel(true));
932                  assertSame(f, f.fork());
933                  f.quietlyJoin();
# Line 885 | Line 999 | public class CountedCompleterTest extend
999      public void testCompleteExceptionally2() {
1000          ForkJoinTask a = new CheckedRecursiveAction() {
1001              protected void realCompute() {
1002 <                CCF f = new LCCF(null, 8);
1003 <                f.completeExceptionally(new FJException());
1004 <                try {
1005 <                    f.invoke();
1006 <                    shouldThrow();
1007 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
1002 >                CCF n = new LCCF(8);
1003 >                CCF f = new LCCF(n, 8);
1004 >                FJException ex = new FJException();
1005 >                f.completeExceptionally(ex);
1006 >                f.checkCompletedExceptionally(ex);
1007 >                n.checkCompletedExceptionally(ex);
1008              }};
1009          testInvokeOnPool(mainPool(), a);
1010      }
# Line 903 | Line 1015 | public class CountedCompleterTest extend
1015      public void testInvokeAll2() {
1016          ForkJoinTask a = new CheckedRecursiveAction() {
1017              protected void realCompute() {
1018 <                CCF f = new LCCF(null, 8);
1019 <                CCF g = new LCCF(null, 9);
1018 >                CCF f = new LCCF(8);
1019 >                CCF g = new LCCF(9);
1020                  invokeAll(f, g);
1021                  assertEquals(21, f.number);
1022                  assertEquals(34, g.number);
# Line 920 | Line 1032 | public class CountedCompleterTest extend
1032      public void testInvokeAll1() {
1033          ForkJoinTask a = new CheckedRecursiveAction() {
1034              protected void realCompute() {
1035 <                CCF f = new LCCF(null, 8);
1035 >                CCF f = new LCCF(8);
1036                  invokeAll(f);
1037                  checkCompletedNormally(f);
1038                  assertEquals(21, f.number);
# Line 934 | Line 1046 | public class CountedCompleterTest extend
1046      public void testInvokeAll3() {
1047          ForkJoinTask a = new CheckedRecursiveAction() {
1048              protected void realCompute() {
1049 <                CCF f = new LCCF(null, 8);
1050 <                CCF g = new LCCF(null, 9);
1051 <                CCF h = new LCCF(null, 7);
1049 >                CCF f = new LCCF(8);
1050 >                CCF g = new LCCF(9);
1051 >                CCF h = new LCCF(7);
1052                  invokeAll(f, g, h);
1053                  assertEquals(21, f.number);
1054                  assertEquals(34, g.number);
# Line 954 | Line 1066 | public class CountedCompleterTest extend
1066      public void testInvokeAllCollection() {
1067          ForkJoinTask a = new CheckedRecursiveAction() {
1068              protected void realCompute() {
1069 <                CCF f = new LCCF(null, 8);
1070 <                CCF g = new LCCF(null, 9);
1071 <                CCF h = new LCCF(null, 7);
1069 >                CCF f = new LCCF(8);
1070 >                CCF g = new LCCF(9);
1071 >                CCF h = new LCCF(7);
1072                  HashSet set = new HashSet();
1073                  set.add(f);
1074                  set.add(g);
# Line 978 | Line 1090 | public class CountedCompleterTest extend
1090      public void testInvokeAllNPE() {
1091          ForkJoinTask a = new CheckedRecursiveAction() {
1092              protected void realCompute() {
1093 <                CCF f = new LCCF(null, 8);
1094 <                CCF g = new LCCF(null, 9);
1093 >                CCF f = new LCCF(8);
1094 >                CCF g = new LCCF(9);
1095                  CCF h = null;
1096                  try {
1097                      invokeAll(f, g, h);
# Line 995 | Line 1107 | public class CountedCompleterTest extend
1107      public void testAbnormalInvokeAll2() {
1108          ForkJoinTask a = new CheckedRecursiveAction() {
1109              protected void realCompute() {
1110 <                CCF f = new LCCF(null, 8);
1111 <                FailingCCF g = new LFCCF(null, 9);
1110 >                CCF f = new LCCF(8);
1111 >                FailingCCF g = new LFCCF(9);
1112                  try {
1113                      invokeAll(f, g);
1114                      shouldThrow();
# Line 1013 | Line 1125 | public class CountedCompleterTest extend
1125      public void testAbnormalInvokeAll1() {
1126          ForkJoinTask a = new CheckedRecursiveAction() {
1127              protected void realCompute() {
1128 <                FailingCCF g = new LFCCF(null, 9);
1128 >                FailingCCF g = new LFCCF(9);
1129                  try {
1130                      invokeAll(g);
1131                      shouldThrow();
# Line 1030 | Line 1142 | public class CountedCompleterTest extend
1142      public void testAbnormalInvokeAll3() {
1143          ForkJoinTask a = new CheckedRecursiveAction() {
1144              protected void realCompute() {
1145 <                CCF f = new LCCF(null, 8);
1146 <                FailingCCF g = new LFCCF(null, 9);
1147 <                CCF h = new LCCF(null, 7);
1145 >                CCF f = new LCCF(8);
1146 >                FailingCCF g = new LFCCF(9);
1147 >                CCF h = new LCCF(7);
1148                  try {
1149                      invokeAll(f, g, h);
1150                      shouldThrow();
# Line 1044 | Line 1156 | public class CountedCompleterTest extend
1156      }
1157  
1158      /**
1159 <     * invokeAll(collection)  throws exception if any task does
1159 >     * invokeAll(collection) throws exception if any task does
1160       */
1161      public void testAbnormalInvokeAllCollection() {
1162          ForkJoinTask a = new CheckedRecursiveAction() {
1163              protected void realCompute() {
1164 <                FailingCCF f = new LFCCF(null, 8);
1165 <                CCF g = new LCCF(null, 9);
1166 <                CCF h = new LCCF(null, 7);
1164 >                FailingCCF f = new LFCCF(8);
1165 >                CCF g = new LCCF(9);
1166 >                CCF h = new LCCF(7);
1167                  HashSet set = new HashSet();
1168                  set.add(f);
1169                  set.add(g);
# Line 1073 | Line 1185 | public class CountedCompleterTest extend
1185      public void testTryUnfork() {
1186          ForkJoinTask a = new CheckedRecursiveAction() {
1187              protected void realCompute() {
1188 <                CCF g = new LCCF(null, 9);
1188 >                CCF g = new LCCF(9);
1189                  assertSame(g, g.fork());
1190 <                CCF f = new LCCF(null, 8);
1190 >                CCF f = new LCCF(8);
1191                  assertSame(f, f.fork());
1192                  assertTrue(f.tryUnfork());
1193                  helpQuiesce();
# Line 1092 | Line 1204 | public class CountedCompleterTest extend
1204      public void testGetSurplusQueuedTaskCount() {
1205          ForkJoinTask a = new CheckedRecursiveAction() {
1206              protected void realCompute() {
1207 <                CCF h = new LCCF(null, 7);
1207 >                CCF h = new LCCF(7);
1208                  assertSame(h, h.fork());
1209 <                CCF g = new LCCF(null, 9);
1209 >                CCF g = new LCCF(9);
1210                  assertSame(g, g.fork());
1211 <                CCF f = new LCCF(null, 8);
1211 >                CCF f = new LCCF(8);
1212                  assertSame(f, f.fork());
1213                  assertTrue(getSurplusQueuedTaskCount() > 0);
1214                  helpQuiesce();
# Line 1114 | Line 1226 | public class CountedCompleterTest extend
1226      public void testPeekNextLocalTask() {
1227          ForkJoinTask a = new CheckedRecursiveAction() {
1228              protected void realCompute() {
1229 <                CCF g = new LCCF(null, 9);
1229 >                CCF g = new LCCF(9);
1230                  assertSame(g, g.fork());
1231 <                CCF f = new LCCF(null, 8);
1231 >                CCF f = new LCCF(8);
1232                  assertSame(f, f.fork());
1233                  assertSame(f, peekNextLocalTask());
1234                  assertNull(f.join());
# Line 1134 | Line 1246 | public class CountedCompleterTest extend
1246      public void testPollNextLocalTask() {
1247          ForkJoinTask a = new CheckedRecursiveAction() {
1248              protected void realCompute() {
1249 <                CCF g = new LCCF(null, 9);
1249 >                CCF g = new LCCF(9);
1250                  assertSame(g, g.fork());
1251 <                CCF f = new LCCF(null, 8);
1251 >                CCF f = new LCCF(8);
1252                  assertSame(f, f.fork());
1253                  assertSame(f, pollNextLocalTask());
1254                  helpQuiesce();
# Line 1153 | Line 1265 | public class CountedCompleterTest extend
1265      public void testPollTask() {
1266          ForkJoinTask a = new CheckedRecursiveAction() {
1267              protected void realCompute() {
1268 <                CCF g = new LCCF(null, 9);
1268 >                CCF g = new LCCF(9);
1269                  assertSame(g, g.fork());
1270 <                CCF f = new LCCF(null, 8);
1270 >                CCF f = new LCCF(8);
1271                  assertSame(f, f.fork());
1272                  assertSame(f, pollTask());
1273                  helpQuiesce();
# Line 1171 | Line 1283 | public class CountedCompleterTest extend
1283      public void testPeekNextLocalTaskAsync() {
1284          ForkJoinTask a = new CheckedRecursiveAction() {
1285              protected void realCompute() {
1286 <                CCF g = new LCCF(null, 9);
1286 >                CCF g = new LCCF(9);
1287                  assertSame(g, g.fork());
1288 <                CCF f = new LCCF(null, 8);
1288 >                CCF f = new LCCF(8);
1289                  assertSame(f, f.fork());
1290                  assertSame(g, peekNextLocalTask());
1291                  assertNull(f.join());
# Line 1192 | Line 1304 | public class CountedCompleterTest extend
1304      public void testPollNextLocalTaskAsync() {
1305          ForkJoinTask a = new CheckedRecursiveAction() {
1306              protected void realCompute() {
1307 <                CCF g = new LCCF(null, 9);
1307 >                CCF g = new LCCF(9);
1308                  assertSame(g, g.fork());
1309 <                CCF f = new LCCF(null, 8);
1309 >                CCF f = new LCCF(8);
1310                  assertSame(f, f.fork());
1311                  assertSame(g, pollNextLocalTask());
1312                  helpQuiesce();
# Line 1212 | Line 1324 | public class CountedCompleterTest extend
1324      public void testPollTaskAsync() {
1325          ForkJoinTask a = new CheckedRecursiveAction() {
1326              protected void realCompute() {
1327 <                CCF g = new LCCF(null, 9);
1327 >                CCF g = new LCCF(9);
1328                  assertSame(g, g.fork());
1329 <                CCF f = new LCCF(null, 8);
1329 >                CCF f = new LCCF(8);
1330                  assertSame(f, f.fork());
1331                  assertSame(g, pollTask());
1332                  helpQuiesce();
# Line 1235 | Line 1347 | public class CountedCompleterTest extend
1347      public void testInvokeSingleton() {
1348          ForkJoinTask a = new CheckedRecursiveAction() {
1349              protected void realCompute() {
1350 <                CCF f = new LCCF(null, 8);
1350 >                CCF f = new LCCF(8);
1351                  assertNull(f.invoke());
1352                  assertEquals(21, f.number);
1353                  checkCompletedNormally(f);
# Line 1251 | Line 1363 | public class CountedCompleterTest extend
1363      public void testQuietlyInvokeSingleton() {
1364          ForkJoinTask a = new CheckedRecursiveAction() {
1365              protected void realCompute() {
1366 <                CCF f = new LCCF(null, 8);
1366 >                CCF f = new LCCF(8);
1367                  f.quietlyInvoke();
1368                  assertEquals(21, f.number);
1369                  checkCompletedNormally(f);
# Line 1265 | Line 1377 | public class CountedCompleterTest extend
1377      public void testForkJoinSingleton() {
1378          ForkJoinTask a = new CheckedRecursiveAction() {
1379              protected void realCompute() {
1380 <                CCF f = new LCCF(null, 8);
1380 >                CCF f = new LCCF(8);
1381                  assertSame(f, f.fork());
1382                  assertNull(f.join());
1383                  assertEquals(21, f.number);
# Line 1280 | Line 1392 | public class CountedCompleterTest extend
1392      public void testForkGetSingleton() {
1393          ForkJoinTask a = new CheckedRecursiveAction() {
1394              protected void realCompute() throws Exception {
1395 <                CCF f = new LCCF(null, 8);
1395 >                CCF f = new LCCF(8);
1396                  assertSame(f, f.fork());
1397                  assertNull(f.get());
1398                  assertEquals(21, f.number);
# Line 1295 | Line 1407 | public class CountedCompleterTest extend
1407      public void testForkTimedGetSingleton() {
1408          ForkJoinTask a = new CheckedRecursiveAction() {
1409              protected void realCompute() throws Exception {
1410 <                CCF f = new LCCF(null, 8);
1410 >                CCF f = new LCCF(8);
1411                  assertSame(f, f.fork());
1412                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1413                  assertEquals(21, f.number);
# Line 1310 | Line 1422 | public class CountedCompleterTest extend
1422      public void testForkTimedGetNPESingleton() {
1423          ForkJoinTask a = new CheckedRecursiveAction() {
1424              protected void realCompute() throws Exception {
1425 <                CCF f = new LCCF(null, 8);
1425 >                CCF f = new LCCF(8);
1426                  assertSame(f, f.fork());
1427                  try {
1428                      f.get(5L, null);
# Line 1326 | Line 1438 | public class CountedCompleterTest extend
1438      public void testForkQuietlyJoinSingleton() {
1439          ForkJoinTask a = new CheckedRecursiveAction() {
1440              protected void realCompute() {
1441 <                CCF f = new LCCF(null, 8);
1441 >                CCF f = new LCCF(8);
1442                  assertSame(f, f.fork());
1443                  f.quietlyJoin();
1444                  assertEquals(21, f.number);
# Line 1342 | Line 1454 | public class CountedCompleterTest extend
1454      public void testForkHelpQuiesceSingleton() {
1455          ForkJoinTask a = new CheckedRecursiveAction() {
1456              protected void realCompute() {
1457 <                CCF f = new LCCF(null, 8);
1457 >                CCF f = new LCCF(8);
1458                  assertSame(f, f.fork());
1459                  helpQuiesce();
1460                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1470 | public class CountedCompleterTest extend
1470      public void testAbnormalInvokeSingleton() {
1471          ForkJoinTask a = new CheckedRecursiveAction() {
1472              protected void realCompute() {
1473 <                FailingCCF f = new LFCCF(null, 8);
1473 >                FailingCCF f = new LFCCF(8);
1474                  try {
1475                      f.invoke();
1476                      shouldThrow();
# Line 1375 | Line 1487 | public class CountedCompleterTest extend
1487      public void testAbnormalQuietlyInvokeSingleton() {
1488          ForkJoinTask a = new CheckedRecursiveAction() {
1489              protected void realCompute() {
1490 <                FailingCCF f = new LFCCF(null, 8);
1490 >                FailingCCF f = new LFCCF(8);
1491                  f.quietlyInvoke();
1492                  assertTrue(f.getException() instanceof FJException);
1493                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1501 | public class CountedCompleterTest extend
1501      public void testAbnormalForkJoinSingleton() {
1502          ForkJoinTask a = new CheckedRecursiveAction() {
1503              protected void realCompute() {
1504 <                FailingCCF f = new LFCCF(null, 8);
1504 >                FailingCCF f = new LFCCF(8);
1505                  assertSame(f, f.fork());
1506                  try {
1507                      f.join();
# Line 1407 | Line 1519 | public class CountedCompleterTest extend
1519      public void testAbnormalForkGetSingleton() {
1520          ForkJoinTask a = new CheckedRecursiveAction() {
1521              protected void realCompute() throws Exception {
1522 <                FailingCCF f = new LFCCF(null, 8);
1522 >                FailingCCF f = new LFCCF(8);
1523                  assertSame(f, f.fork());
1524                  try {
1525                      f.get();
# Line 1427 | Line 1539 | public class CountedCompleterTest extend
1539      public void testAbnormalForkTimedGetSingleton() {
1540          ForkJoinTask a = new CheckedRecursiveAction() {
1541              protected void realCompute() throws Exception {
1542 <                FailingCCF f = new LFCCF(null, 8);
1542 >                FailingCCF f = new LFCCF(8);
1543                  assertSame(f, f.fork());
1544                  try {
1545                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1559 | public class CountedCompleterTest extend
1559      public void testAbnormalForkQuietlyJoinSingleton() {
1560          ForkJoinTask a = new CheckedRecursiveAction() {
1561              protected void realCompute() {
1562 <                FailingCCF f = new LFCCF(null, 8);
1562 >                FailingCCF f = new LFCCF(8);
1563                  assertSame(f, f.fork());
1564                  f.quietlyJoin();
1565                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1574 | public class CountedCompleterTest extend
1574      public void testCancelledInvokeSingleton() {
1575          ForkJoinTask a = new CheckedRecursiveAction() {
1576              protected void realCompute() {
1577 <                CCF f = new LCCF(null, 8);
1577 >                CCF f = new LCCF(8);
1578                  assertTrue(f.cancel(true));
1579                  try {
1580                      f.invoke();
# Line 1480 | Line 1592 | public class CountedCompleterTest extend
1592      public void testCancelledForkJoinSingleton() {
1593          ForkJoinTask a = new CheckedRecursiveAction() {
1594              protected void realCompute() {
1595 <                CCF f = new LCCF(null, 8);
1595 >                CCF f = new LCCF(8);
1596                  assertTrue(f.cancel(true));
1597                  assertSame(f, f.fork());
1598                  try {
# Line 1499 | Line 1611 | public class CountedCompleterTest extend
1611      public void testCancelledForkGetSingleton() {
1612          ForkJoinTask a = new CheckedRecursiveAction() {
1613              protected void realCompute() throws Exception {
1614 <                CCF f = new LCCF(null, 8);
1614 >                CCF f = new LCCF(8);
1615                  assertTrue(f.cancel(true));
1616                  assertSame(f, f.fork());
1617                  try {
# Line 1518 | Line 1630 | public class CountedCompleterTest extend
1630      public void testCancelledForkTimedGetSingleton() throws Exception {
1631          ForkJoinTask a = new CheckedRecursiveAction() {
1632              protected void realCompute() throws Exception {
1633 <                CCF f = new LCCF(null, 8);
1633 >                CCF f = new LCCF(8);
1634                  assertTrue(f.cancel(true));
1635                  assertSame(f, f.fork());
1636                  try {
# Line 1537 | Line 1649 | public class CountedCompleterTest extend
1649      public void testCancelledForkQuietlyJoinSingleton() {
1650          ForkJoinTask a = new CheckedRecursiveAction() {
1651              protected void realCompute() {
1652 <                CCF f = new LCCF(null, 8);
1652 >                CCF f = new LCCF(8);
1653                  assertTrue(f.cancel(true));
1654                  assertSame(f, f.fork());
1655                  f.quietlyJoin();
# Line 1552 | Line 1664 | public class CountedCompleterTest extend
1664      public void testCompleteExceptionallySingleton() {
1665          ForkJoinTask a = new CheckedRecursiveAction() {
1666              protected void realCompute() {
1667 <                CCF f = new LCCF(null, 8);
1668 <                f.completeExceptionally(new FJException());
1669 <                try {
1670 <                    f.invoke();
1671 <                    shouldThrow();
1672 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1667 >                CCF n = new LCCF(8);
1668 >                CCF f = new LCCF(n, 8);
1669 >                FJException ex = new FJException();
1670 >                f.completeExceptionally(ex);
1671 >                f.checkCompletedExceptionally(ex);
1672 >                n.checkCompletedExceptionally(ex);
1673              }};
1674          testInvokeOnPool(singletonPool(), a);
1675      }
# Line 1570 | Line 1680 | public class CountedCompleterTest extend
1680      public void testInvokeAll2Singleton() {
1681          ForkJoinTask a = new CheckedRecursiveAction() {
1682              protected void realCompute() {
1683 <                CCF f = new LCCF(null, 8);
1684 <                CCF g = new LCCF(null, 9);
1683 >                CCF f = new LCCF(8);
1684 >                CCF g = new LCCF(9);
1685                  invokeAll(f, g);
1686                  assertEquals(21, f.number);
1687                  assertEquals(34, g.number);
# Line 1587 | Line 1697 | public class CountedCompleterTest extend
1697      public void testInvokeAll1Singleton() {
1698          ForkJoinTask a = new CheckedRecursiveAction() {
1699              protected void realCompute() {
1700 <                CCF f = new LCCF(null, 8);
1700 >                CCF f = new LCCF(8);
1701                  invokeAll(f);
1702                  checkCompletedNormally(f);
1703                  assertEquals(21, f.number);
# Line 1601 | Line 1711 | public class CountedCompleterTest extend
1711      public void testInvokeAll3Singleton() {
1712          ForkJoinTask a = new CheckedRecursiveAction() {
1713              protected void realCompute() {
1714 <                CCF f = new LCCF(null, 8);
1715 <                CCF g = new LCCF(null, 9);
1716 <                CCF h = new LCCF(null, 7);
1714 >                CCF f = new LCCF(8);
1715 >                CCF g = new LCCF(9);
1716 >                CCF h = new LCCF(7);
1717                  invokeAll(f, g, h);
1718                  assertEquals(21, f.number);
1719                  assertEquals(34, g.number);
# Line 1621 | Line 1731 | public class CountedCompleterTest extend
1731      public void testInvokeAllCollectionSingleton() {
1732          ForkJoinTask a = new CheckedRecursiveAction() {
1733              protected void realCompute() {
1734 <                CCF f = new LCCF(null, 8);
1735 <                CCF g = new LCCF(null, 9);
1736 <                CCF h = new LCCF(null, 7);
1734 >                CCF f = new LCCF(8);
1735 >                CCF g = new LCCF(9);
1736 >                CCF h = new LCCF(7);
1737                  HashSet set = new HashSet();
1738                  set.add(f);
1739                  set.add(g);
# Line 1645 | Line 1755 | public class CountedCompleterTest extend
1755      public void testInvokeAllNPESingleton() {
1756          ForkJoinTask a = new CheckedRecursiveAction() {
1757              protected void realCompute() {
1758 <                CCF f = new LCCF(null, 8);
1759 <                CCF g = new LCCF(null, 9);
1758 >                CCF f = new LCCF(8);
1759 >                CCF g = new LCCF(9);
1760                  CCF h = null;
1761                  try {
1762                      invokeAll(f, g, h);
# Line 1662 | Line 1772 | public class CountedCompleterTest extend
1772      public void testAbnormalInvokeAll2Singleton() {
1773          ForkJoinTask a = new CheckedRecursiveAction() {
1774              protected void realCompute() {
1775 <                CCF f = new LCCF(null, 8);
1776 <                FailingCCF g = new LFCCF(null, 9);
1775 >                CCF f = new LCCF(8);
1776 >                FailingCCF g = new LFCCF(9);
1777                  try {
1778                      invokeAll(f, g);
1779                      shouldThrow();
# Line 1680 | Line 1790 | public class CountedCompleterTest extend
1790      public void testAbnormalInvokeAll1Singleton() {
1791          ForkJoinTask a = new CheckedRecursiveAction() {
1792              protected void realCompute() {
1793 <                FailingCCF g = new LFCCF(null, 9);
1793 >                FailingCCF g = new LFCCF(9);
1794                  try {
1795                      invokeAll(g);
1796                      shouldThrow();
# Line 1697 | Line 1807 | public class CountedCompleterTest extend
1807      public void testAbnormalInvokeAll3Singleton() {
1808          ForkJoinTask a = new CheckedRecursiveAction() {
1809              protected void realCompute() {
1810 <                CCF f = new LCCF(null, 8);
1811 <                FailingCCF g = new LFCCF(null, 9);
1812 <                CCF h = new LCCF(null, 7);
1810 >                CCF f = new LCCF(8);
1811 >                FailingCCF g = new LFCCF(9);
1812 >                CCF h = new LCCF(7);
1813                  try {
1814                      invokeAll(f, g, h);
1815                      shouldThrow();
# Line 1711 | Line 1821 | public class CountedCompleterTest extend
1821      }
1822  
1823      /**
1824 <     * invokeAll(collection)  throws exception if any task does
1824 >     * invokeAll(collection) throws exception if any task does
1825       */
1826      public void testAbnormalInvokeAllCollectionSingleton() {
1827          ForkJoinTask a = new CheckedRecursiveAction() {
1828              protected void realCompute() {
1829 <                FailingCCF f = new LFCCF(null, 8);
1830 <                CCF g = new LCCF(null, 9);
1831 <                CCF h = new LCCF(null, 7);
1829 >                FailingCCF f = new LFCCF(8);
1830 >                CCF g = new LCCF(9);
1831 >                CCF h = new LCCF(7);
1832                  HashSet set = new HashSet();
1833                  set.add(f);
1834                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines