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.37 by jsr166, Sun Jul 22 20:23:28 2018 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 >
9 > import java.util.HashSet;
10   import java.util.concurrent.CancellationException;
11 + import java.util.concurrent.CountedCompleter;
12 + import java.util.concurrent.ExecutionException;
13   import java.util.concurrent.ForkJoinPool;
14   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;
15   import java.util.concurrent.TimeoutException;
16 < import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
17 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
18 < import static java.util.concurrent.TimeUnit.SECONDS;
19 < import java.util.HashSet;
20 < import junit.framework.*;
16 > import java.util.concurrent.atomic.AtomicInteger;
17 > import java.util.concurrent.atomic.AtomicReference;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class CountedCompleterTest extends JSR166TestCase {
23  
24      public static void main(String[] args) {
25 <        junit.textui.TestRunner.run(suite());
25 >        main(suite(), args);
26      }
27  
28      public static Test suite() {
# Line 47 | Line 48 | public class CountedCompleterTest extend
48      }
49  
50      private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) {
51 <        try {
51 >        try (PoolCleaner cleaner = cleaner(pool)) {
52              assertFalse(a.isDone());
53              assertFalse(a.isCompletedNormally());
54              assertFalse(a.isCompletedAbnormally());
# Line 63 | Line 64 | public class CountedCompleterTest extend
64              assertFalse(a.isCancelled());
65              assertNull(a.getException());
66              assertNull(a.getRawResult());
66        } finally {
67            joinPool(pool);
67          }
68      }
69  
# Line 77 | Line 76 | public class CountedCompleterTest extend
76          assertNull(a.getRawResult());
77  
78          try {
79 <            a.get(0L, SECONDS);
79 >            a.get(randomExpiredTimeout(), randomTimeUnit());
80              shouldThrow();
81          } catch (TimeoutException success) {
82          } catch (Throwable fail) { threadUnexpectedException(fail); }
83      }
84  
85 <    <T> void checkCompletedNormally(CountedCompleter<T> a) {
87 <        checkCompletedNormally(a, null);
88 <    }
89 <
90 <    <T> void checkCompletedNormally(CountedCompleter<T> a, T expected) {
85 >    void checkCompletedNormally(CountedCompleter<?> a) {
86          assertTrue(a.isDone());
87          assertFalse(a.isCancelled());
88          assertTrue(a.isCompletedNormally());
89          assertFalse(a.isCompletedAbnormally());
90          assertNull(a.getException());
91 <        assertSame(expected, a.getRawResult());
91 >        assertNull(a.getRawResult());
92  
93          {
94              Thread.currentThread().interrupt();
95 <            long t0 = System.nanoTime();
96 <            assertSame(expected, a.join());
97 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
95 >            long startTime = System.nanoTime();
96 >            assertNull(a.join());
97 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
98              Thread.interrupted();
99          }
100  
101          {
102              Thread.currentThread().interrupt();
103 <            long t0 = System.nanoTime();
103 >            long startTime = System.nanoTime();
104              a.quietlyJoin();        // should be no-op
105 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
105 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
106              Thread.interrupted();
107          }
108  
109          assertFalse(a.cancel(false));
110          assertFalse(a.cancel(true));
111 +
112 +        Object v1 = null, v2 = null;
113          try {
114 <            assertSame(expected, a.get());
115 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
119 <        try {
120 <            assertSame(expected, a.get(5L, SECONDS));
114 >            v1 = a.get();
115 >            v2 = a.get(randomTimeout(), randomTimeUnit());
116          } catch (Throwable fail) { threadUnexpectedException(fail); }
117 +        assertNull(v1);
118 +        assertNull(v2);
119      }
120  
121      void checkCancelled(CountedCompleter a) {
# 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) < LONG_DELAY_MS);
143          }
144  
145          try {
# Line 152 | Line 149 | public class CountedCompleterTest extend
149          } catch (Throwable fail) { threadUnexpectedException(fail); }
150  
151          try {
152 <            a.get(5L, SECONDS);
152 >            a.get(randomTimeout(), randomTimeUnit());
153              shouldThrow();
154          } catch (CancellationException success) {
155          } catch (Throwable fail) { threadUnexpectedException(fail); }
# 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) < LONG_DELAY_MS);
181          }
182  
183          try {
# Line 191 | Line 188 | public class CountedCompleterTest extend
188          } catch (Throwable fail) { threadUnexpectedException(fail); }
189  
190          try {
191 <            a.get(5L, SECONDS);
191 >            a.get(randomTimeout(), randomTimeUnit());
192              shouldThrow();
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);
706 >                    f.get(randomTimeout(), null);
707                      shouldThrow();
708                  } catch (NullPointerException success) {}
709              }};
# 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 +                while (!f.isDone()) // wait out race
739 +                    ;
740                  assertEquals(21, f.number);
741                  assertEquals(0, getQueuedTaskCount());
742                  checkCompletedNormally(f);
# Line 634 | Line 750 | public class CountedCompleterTest extend
750      public void testAbnormalInvoke() {
751          ForkJoinTask a = new CheckedRecursiveAction() {
752              protected void realCompute() {
753 <                FailingCCF f = new LFCCF(null, 8);
753 >                FailingCCF f = new LFCCF(8);
754                  try {
755                      f.invoke();
756                      shouldThrow();
# Line 651 | Line 767 | public class CountedCompleterTest extend
767      public void testAbnormalQuietlyInvoke() {
768          ForkJoinTask a = new CheckedRecursiveAction() {
769              protected void realCompute() {
770 <                FailingCCF f = new LFCCF(null, 8);
770 >                FailingCCF f = new LFCCF(8);
771                  f.quietlyInvoke();
772                  assertTrue(f.getException() instanceof FJException);
773                  checkCompletedAbnormally(f, f.getException());
# Line 665 | Line 781 | public class CountedCompleterTest extend
781      public void testAbnormalForkJoin() {
782          ForkJoinTask a = new CheckedRecursiveAction() {
783              protected void realCompute() {
784 <                FailingCCF f = new LFCCF(null, 8);
784 >                FailingCCF f = new LFCCF(8);
785                  assertSame(f, f.fork());
786                  try {
787                      f.join();
# Line 683 | Line 799 | public class CountedCompleterTest extend
799      public void testAbnormalForkGet() {
800          ForkJoinTask a = new CheckedRecursiveAction() {
801              protected void realCompute() throws Exception {
802 <                FailingCCF f = new LFCCF(null, 8);
802 >                FailingCCF f = new LFCCF(8);
803                  assertSame(f, f.fork());
804                  try {
805                      f.get();
# Line 703 | Line 819 | public class CountedCompleterTest extend
819      public void testAbnormalForkTimedGet() {
820          ForkJoinTask a = new CheckedRecursiveAction() {
821              protected void realCompute() throws Exception {
822 <                FailingCCF f = new LFCCF(null, 8);
822 >                FailingCCF f = new LFCCF(8);
823                  assertSame(f, f.fork());
824                  try {
825                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 723 | Line 839 | public class CountedCompleterTest extend
839      public void testAbnormalForkQuietlyJoin() {
840          ForkJoinTask a = new CheckedRecursiveAction() {
841              protected void realCompute() {
842 <                FailingCCF f = new LFCCF(null, 8);
842 >                FailingCCF f = new LFCCF(8);
843                  assertSame(f, f.fork());
844                  f.quietlyJoin();
845                  assertTrue(f.getException() instanceof FJException);
# Line 738 | Line 854 | public class CountedCompleterTest extend
854      public void testCancelledInvoke() {
855          ForkJoinTask a = new CheckedRecursiveAction() {
856              protected void realCompute() {
857 <                CCF f = new LCCF(null, 8);
857 >                CCF f = new LCCF(8);
858                  assertTrue(f.cancel(true));
859                  try {
860                      f.invoke();
# Line 756 | Line 872 | public class CountedCompleterTest extend
872      public void testCancelledForkJoin() {
873          ForkJoinTask a = new CheckedRecursiveAction() {
874              protected void realCompute() {
875 <                CCF f = new LCCF(null, 8);
875 >                CCF f = new LCCF(8);
876                  assertTrue(f.cancel(true));
877                  assertSame(f, f.fork());
878                  try {
# Line 775 | Line 891 | public class CountedCompleterTest extend
891      public void testCancelledForkGet() {
892          ForkJoinTask a = new CheckedRecursiveAction() {
893              protected void realCompute() throws Exception {
894 <                CCF f = new LCCF(null, 8);
894 >                CCF f = new LCCF(8);
895                  assertTrue(f.cancel(true));
896                  assertSame(f, f.fork());
897                  try {
# Line 794 | Line 910 | public class CountedCompleterTest extend
910      public void testCancelledForkTimedGet() throws Exception {
911          ForkJoinTask a = new CheckedRecursiveAction() {
912              protected void realCompute() throws Exception {
913 <                CCF f = new LCCF(null, 8);
913 >                CCF f = new LCCF(8);
914                  assertTrue(f.cancel(true));
915                  assertSame(f, f.fork());
916                  try {
# Line 813 | Line 929 | public class CountedCompleterTest extend
929      public void testCancelledForkQuietlyJoin() {
930          ForkJoinTask a = new CheckedRecursiveAction() {
931              protected void realCompute() {
932 <                CCF f = new LCCF(null, 8);
932 >                CCF f = new LCCF(8);
933                  assertTrue(f.cancel(true));
934                  assertSame(f, f.fork());
935                  f.quietlyJoin();
# Line 885 | Line 1001 | public class CountedCompleterTest extend
1001      public void testCompleteExceptionally2() {
1002          ForkJoinTask a = new CheckedRecursiveAction() {
1003              protected void realCompute() {
1004 <                CCF f = new LCCF(null, 8);
1005 <                f.completeExceptionally(new FJException());
1006 <                try {
1007 <                    f.invoke();
1008 <                    shouldThrow();
1009 <                } catch (FJException success) {
894 <                    checkCompletedAbnormally(f, success);
895 <                }
1004 >                CCF n = new LCCF(8);
1005 >                CCF f = new LCCF(n, 8);
1006 >                FJException ex = new FJException();
1007 >                f.completeExceptionally(ex);
1008 >                f.checkCompletedExceptionally(ex);
1009 >                n.checkCompletedExceptionally(ex);
1010              }};
1011          testInvokeOnPool(mainPool(), a);
1012      }
# Line 903 | Line 1017 | public class CountedCompleterTest extend
1017      public void testInvokeAll2() {
1018          ForkJoinTask a = new CheckedRecursiveAction() {
1019              protected void realCompute() {
1020 <                CCF f = new LCCF(null, 8);
1021 <                CCF g = new LCCF(null, 9);
1020 >                CCF f = new LCCF(8);
1021 >                CCF g = new LCCF(9);
1022                  invokeAll(f, g);
1023                  assertEquals(21, f.number);
1024                  assertEquals(34, g.number);
# Line 920 | Line 1034 | public class CountedCompleterTest extend
1034      public void testInvokeAll1() {
1035          ForkJoinTask a = new CheckedRecursiveAction() {
1036              protected void realCompute() {
1037 <                CCF f = new LCCF(null, 8);
1037 >                CCF f = new LCCF(8);
1038                  invokeAll(f);
1039                  checkCompletedNormally(f);
1040                  assertEquals(21, f.number);
# Line 934 | Line 1048 | public class CountedCompleterTest extend
1048      public void testInvokeAll3() {
1049          ForkJoinTask a = new CheckedRecursiveAction() {
1050              protected void realCompute() {
1051 <                CCF f = new LCCF(null, 8);
1052 <                CCF g = new LCCF(null, 9);
1053 <                CCF h = new LCCF(null, 7);
1051 >                CCF f = new LCCF(8);
1052 >                CCF g = new LCCF(9);
1053 >                CCF h = new LCCF(7);
1054                  invokeAll(f, g, h);
1055                  assertEquals(21, f.number);
1056                  assertEquals(34, g.number);
# Line 954 | Line 1068 | public class CountedCompleterTest extend
1068      public void testInvokeAllCollection() {
1069          ForkJoinTask a = new CheckedRecursiveAction() {
1070              protected void realCompute() {
1071 <                CCF f = new LCCF(null, 8);
1072 <                CCF g = new LCCF(null, 9);
1073 <                CCF h = new LCCF(null, 7);
1071 >                CCF f = new LCCF(8);
1072 >                CCF g = new LCCF(9);
1073 >                CCF h = new LCCF(7);
1074                  HashSet set = new HashSet();
1075                  set.add(f);
1076                  set.add(g);
# Line 978 | Line 1092 | public class CountedCompleterTest extend
1092      public void testInvokeAllNPE() {
1093          ForkJoinTask a = new CheckedRecursiveAction() {
1094              protected void realCompute() {
1095 <                CCF f = new LCCF(null, 8);
1096 <                CCF g = new LCCF(null, 9);
1095 >                CCF f = new LCCF(8);
1096 >                CCF g = new LCCF(9);
1097                  CCF h = null;
1098                  try {
1099                      invokeAll(f, g, h);
# Line 995 | Line 1109 | public class CountedCompleterTest extend
1109      public void testAbnormalInvokeAll2() {
1110          ForkJoinTask a = new CheckedRecursiveAction() {
1111              protected void realCompute() {
1112 <                CCF f = new LCCF(null, 8);
1113 <                FailingCCF g = new LFCCF(null, 9);
1112 >                CCF f = new LCCF(8);
1113 >                FailingCCF g = new LFCCF(9);
1114                  try {
1115                      invokeAll(f, g);
1116                      shouldThrow();
# Line 1013 | Line 1127 | public class CountedCompleterTest extend
1127      public void testAbnormalInvokeAll1() {
1128          ForkJoinTask a = new CheckedRecursiveAction() {
1129              protected void realCompute() {
1130 <                FailingCCF g = new LFCCF(null, 9);
1130 >                FailingCCF g = new LFCCF(9);
1131                  try {
1132                      invokeAll(g);
1133                      shouldThrow();
# Line 1030 | Line 1144 | public class CountedCompleterTest extend
1144      public void testAbnormalInvokeAll3() {
1145          ForkJoinTask a = new CheckedRecursiveAction() {
1146              protected void realCompute() {
1147 <                CCF f = new LCCF(null, 8);
1148 <                FailingCCF g = new LFCCF(null, 9);
1149 <                CCF h = new LCCF(null, 7);
1147 >                CCF f = new LCCF(8);
1148 >                FailingCCF g = new LFCCF(9);
1149 >                CCF h = new LCCF(7);
1150                  try {
1151                      invokeAll(f, g, h);
1152                      shouldThrow();
# Line 1044 | Line 1158 | public class CountedCompleterTest extend
1158      }
1159  
1160      /**
1161 <     * invokeAll(collection)  throws exception if any task does
1161 >     * invokeAll(collection) throws exception if any task does
1162       */
1163      public void testAbnormalInvokeAllCollection() {
1164          ForkJoinTask a = new CheckedRecursiveAction() {
1165              protected void realCompute() {
1166 <                FailingCCF f = new LFCCF(null, 8);
1167 <                CCF g = new LCCF(null, 9);
1168 <                CCF h = new LCCF(null, 7);
1166 >                FailingCCF f = new LFCCF(8);
1167 >                CCF g = new LCCF(9);
1168 >                CCF h = new LCCF(7);
1169                  HashSet set = new HashSet();
1170                  set.add(f);
1171                  set.add(g);
# Line 1073 | Line 1187 | public class CountedCompleterTest extend
1187      public void testTryUnfork() {
1188          ForkJoinTask a = new CheckedRecursiveAction() {
1189              protected void realCompute() {
1190 <                CCF g = new LCCF(null, 9);
1190 >                CCF g = new LCCF(9);
1191                  assertSame(g, g.fork());
1192 <                CCF f = new LCCF(null, 8);
1192 >                CCF f = new LCCF(8);
1193                  assertSame(f, f.fork());
1194                  assertTrue(f.tryUnfork());
1195                  helpQuiesce();
# Line 1092 | Line 1206 | public class CountedCompleterTest extend
1206      public void testGetSurplusQueuedTaskCount() {
1207          ForkJoinTask a = new CheckedRecursiveAction() {
1208              protected void realCompute() {
1209 <                CCF h = new LCCF(null, 7);
1209 >                CCF h = new LCCF(7);
1210                  assertSame(h, h.fork());
1211 <                CCF g = new LCCF(null, 9);
1211 >                CCF g = new LCCF(9);
1212                  assertSame(g, g.fork());
1213 <                CCF f = new LCCF(null, 8);
1213 >                CCF f = new LCCF(8);
1214                  assertSame(f, f.fork());
1215                  assertTrue(getSurplusQueuedTaskCount() > 0);
1216                  helpQuiesce();
# Line 1114 | Line 1228 | public class CountedCompleterTest extend
1228      public void testPeekNextLocalTask() {
1229          ForkJoinTask a = new CheckedRecursiveAction() {
1230              protected void realCompute() {
1231 <                CCF g = new LCCF(null, 9);
1231 >                CCF g = new LCCF(9);
1232                  assertSame(g, g.fork());
1233 <                CCF f = new LCCF(null, 8);
1233 >                CCF f = new LCCF(8);
1234                  assertSame(f, f.fork());
1235                  assertSame(f, peekNextLocalTask());
1236                  assertNull(f.join());
# Line 1134 | Line 1248 | public class CountedCompleterTest extend
1248      public void testPollNextLocalTask() {
1249          ForkJoinTask a = new CheckedRecursiveAction() {
1250              protected void realCompute() {
1251 <                CCF g = new LCCF(null, 9);
1251 >                CCF g = new LCCF(9);
1252                  assertSame(g, g.fork());
1253 <                CCF f = new LCCF(null, 8);
1253 >                CCF f = new LCCF(8);
1254                  assertSame(f, f.fork());
1255                  assertSame(f, pollNextLocalTask());
1256                  helpQuiesce();
# Line 1153 | Line 1267 | public class CountedCompleterTest extend
1267      public void testPollTask() {
1268          ForkJoinTask a = new CheckedRecursiveAction() {
1269              protected void realCompute() {
1270 <                CCF g = new LCCF(null, 9);
1270 >                CCF g = new LCCF(9);
1271                  assertSame(g, g.fork());
1272 <                CCF f = new LCCF(null, 8);
1272 >                CCF f = new LCCF(8);
1273                  assertSame(f, f.fork());
1274                  assertSame(f, pollTask());
1275                  helpQuiesce();
# Line 1171 | Line 1285 | public class CountedCompleterTest extend
1285      public void testPeekNextLocalTaskAsync() {
1286          ForkJoinTask a = new CheckedRecursiveAction() {
1287              protected void realCompute() {
1288 <                CCF g = new LCCF(null, 9);
1288 >                CCF g = new LCCF(9);
1289                  assertSame(g, g.fork());
1290 <                CCF f = new LCCF(null, 8);
1290 >                CCF f = new LCCF(8);
1291                  assertSame(f, f.fork());
1292                  assertSame(g, peekNextLocalTask());
1293                  assertNull(f.join());
# Line 1192 | Line 1306 | public class CountedCompleterTest extend
1306      public void testPollNextLocalTaskAsync() {
1307          ForkJoinTask a = new CheckedRecursiveAction() {
1308              protected void realCompute() {
1309 <                CCF g = new LCCF(null, 9);
1309 >                CCF g = new LCCF(9);
1310                  assertSame(g, g.fork());
1311 <                CCF f = new LCCF(null, 8);
1311 >                CCF f = new LCCF(8);
1312                  assertSame(f, f.fork());
1313                  assertSame(g, pollNextLocalTask());
1314                  helpQuiesce();
# Line 1212 | Line 1326 | public class CountedCompleterTest extend
1326      public void testPollTaskAsync() {
1327          ForkJoinTask a = new CheckedRecursiveAction() {
1328              protected void realCompute() {
1329 <                CCF g = new LCCF(null, 9);
1329 >                CCF g = new LCCF(9);
1330                  assertSame(g, g.fork());
1331 <                CCF f = new LCCF(null, 8);
1331 >                CCF f = new LCCF(8);
1332                  assertSame(f, f.fork());
1333                  assertSame(g, pollTask());
1334                  helpQuiesce();
# Line 1235 | Line 1349 | public class CountedCompleterTest extend
1349      public void testInvokeSingleton() {
1350          ForkJoinTask a = new CheckedRecursiveAction() {
1351              protected void realCompute() {
1352 <                CCF f = new LCCF(null, 8);
1352 >                CCF f = new LCCF(8);
1353                  assertNull(f.invoke());
1354                  assertEquals(21, f.number);
1355                  checkCompletedNormally(f);
# Line 1251 | Line 1365 | public class CountedCompleterTest extend
1365      public void testQuietlyInvokeSingleton() {
1366          ForkJoinTask a = new CheckedRecursiveAction() {
1367              protected void realCompute() {
1368 <                CCF f = new LCCF(null, 8);
1368 >                CCF f = new LCCF(8);
1369                  f.quietlyInvoke();
1370                  assertEquals(21, f.number);
1371                  checkCompletedNormally(f);
# Line 1265 | Line 1379 | public class CountedCompleterTest extend
1379      public void testForkJoinSingleton() {
1380          ForkJoinTask a = new CheckedRecursiveAction() {
1381              protected void realCompute() {
1382 <                CCF f = new LCCF(null, 8);
1382 >                CCF f = new LCCF(8);
1383                  assertSame(f, f.fork());
1384                  assertNull(f.join());
1385                  assertEquals(21, f.number);
# Line 1280 | Line 1394 | public class CountedCompleterTest extend
1394      public void testForkGetSingleton() {
1395          ForkJoinTask a = new CheckedRecursiveAction() {
1396              protected void realCompute() throws Exception {
1397 <                CCF f = new LCCF(null, 8);
1397 >                CCF f = new LCCF(8);
1398                  assertSame(f, f.fork());
1399                  assertNull(f.get());
1400                  assertEquals(21, f.number);
# Line 1295 | Line 1409 | public class CountedCompleterTest extend
1409      public void testForkTimedGetSingleton() {
1410          ForkJoinTask a = new CheckedRecursiveAction() {
1411              protected void realCompute() throws Exception {
1412 <                CCF f = new LCCF(null, 8);
1412 >                CCF f = new LCCF(8);
1413                  assertSame(f, f.fork());
1414                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1415                  assertEquals(21, f.number);
# Line 1310 | Line 1424 | public class CountedCompleterTest extend
1424      public void testForkTimedGetNPESingleton() {
1425          ForkJoinTask a = new CheckedRecursiveAction() {
1426              protected void realCompute() throws Exception {
1427 <                CCF f = new LCCF(null, 8);
1427 >                CCF f = new LCCF(8);
1428                  assertSame(f, f.fork());
1429                  try {
1430 <                    f.get(5L, null);
1430 >                    f.get(randomTimeout(), null);
1431                      shouldThrow();
1432                  } catch (NullPointerException success) {}
1433              }};
# Line 1326 | Line 1440 | public class CountedCompleterTest extend
1440      public void testForkQuietlyJoinSingleton() {
1441          ForkJoinTask a = new CheckedRecursiveAction() {
1442              protected void realCompute() {
1443 <                CCF f = new LCCF(null, 8);
1443 >                CCF f = new LCCF(8);
1444                  assertSame(f, f.fork());
1445                  f.quietlyJoin();
1446                  assertEquals(21, f.number);
# Line 1342 | Line 1456 | public class CountedCompleterTest extend
1456      public void testForkHelpQuiesceSingleton() {
1457          ForkJoinTask a = new CheckedRecursiveAction() {
1458              protected void realCompute() {
1459 <                CCF f = new LCCF(null, 8);
1459 >                CCF f = new LCCF(8);
1460                  assertSame(f, f.fork());
1461                  helpQuiesce();
1462                  assertEquals(0, getQueuedTaskCount());
# Line 1358 | Line 1472 | public class CountedCompleterTest extend
1472      public void testAbnormalInvokeSingleton() {
1473          ForkJoinTask a = new CheckedRecursiveAction() {
1474              protected void realCompute() {
1475 <                FailingCCF f = new LFCCF(null, 8);
1475 >                FailingCCF f = new LFCCF(8);
1476                  try {
1477                      f.invoke();
1478                      shouldThrow();
# Line 1375 | Line 1489 | public class CountedCompleterTest extend
1489      public void testAbnormalQuietlyInvokeSingleton() {
1490          ForkJoinTask a = new CheckedRecursiveAction() {
1491              protected void realCompute() {
1492 <                FailingCCF f = new LFCCF(null, 8);
1492 >                FailingCCF f = new LFCCF(8);
1493                  f.quietlyInvoke();
1494                  assertTrue(f.getException() instanceof FJException);
1495                  checkCompletedAbnormally(f, f.getException());
# Line 1389 | Line 1503 | public class CountedCompleterTest extend
1503      public void testAbnormalForkJoinSingleton() {
1504          ForkJoinTask a = new CheckedRecursiveAction() {
1505              protected void realCompute() {
1506 <                FailingCCF f = new LFCCF(null, 8);
1506 >                FailingCCF f = new LFCCF(8);
1507                  assertSame(f, f.fork());
1508                  try {
1509                      f.join();
# Line 1407 | Line 1521 | public class CountedCompleterTest extend
1521      public void testAbnormalForkGetSingleton() {
1522          ForkJoinTask a = new CheckedRecursiveAction() {
1523              protected void realCompute() throws Exception {
1524 <                FailingCCF f = new LFCCF(null, 8);
1524 >                FailingCCF f = new LFCCF(8);
1525                  assertSame(f, f.fork());
1526                  try {
1527                      f.get();
# Line 1427 | Line 1541 | public class CountedCompleterTest extend
1541      public void testAbnormalForkTimedGetSingleton() {
1542          ForkJoinTask a = new CheckedRecursiveAction() {
1543              protected void realCompute() throws Exception {
1544 <                FailingCCF f = new LFCCF(null, 8);
1544 >                FailingCCF f = new LFCCF(8);
1545                  assertSame(f, f.fork());
1546                  try {
1547                      f.get(LONG_DELAY_MS, MILLISECONDS);
# Line 1447 | Line 1561 | public class CountedCompleterTest extend
1561      public void testAbnormalForkQuietlyJoinSingleton() {
1562          ForkJoinTask a = new CheckedRecursiveAction() {
1563              protected void realCompute() {
1564 <                FailingCCF f = new LFCCF(null, 8);
1564 >                FailingCCF f = new LFCCF(8);
1565                  assertSame(f, f.fork());
1566                  f.quietlyJoin();
1567                  assertTrue(f.getException() instanceof FJException);
# Line 1462 | Line 1576 | public class CountedCompleterTest extend
1576      public void testCancelledInvokeSingleton() {
1577          ForkJoinTask a = new CheckedRecursiveAction() {
1578              protected void realCompute() {
1579 <                CCF f = new LCCF(null, 8);
1579 >                CCF f = new LCCF(8);
1580                  assertTrue(f.cancel(true));
1581                  try {
1582                      f.invoke();
# Line 1480 | Line 1594 | public class CountedCompleterTest extend
1594      public void testCancelledForkJoinSingleton() {
1595          ForkJoinTask a = new CheckedRecursiveAction() {
1596              protected void realCompute() {
1597 <                CCF f = new LCCF(null, 8);
1597 >                CCF f = new LCCF(8);
1598                  assertTrue(f.cancel(true));
1599                  assertSame(f, f.fork());
1600                  try {
# Line 1499 | Line 1613 | public class CountedCompleterTest extend
1613      public void testCancelledForkGetSingleton() {
1614          ForkJoinTask a = new CheckedRecursiveAction() {
1615              protected void realCompute() throws Exception {
1616 <                CCF f = new LCCF(null, 8);
1616 >                CCF f = new LCCF(8);
1617                  assertTrue(f.cancel(true));
1618                  assertSame(f, f.fork());
1619                  try {
# Line 1518 | Line 1632 | public class CountedCompleterTest extend
1632      public void testCancelledForkTimedGetSingleton() throws Exception {
1633          ForkJoinTask a = new CheckedRecursiveAction() {
1634              protected void realCompute() throws Exception {
1635 <                CCF f = new LCCF(null, 8);
1635 >                CCF f = new LCCF(8);
1636                  assertTrue(f.cancel(true));
1637                  assertSame(f, f.fork());
1638                  try {
# Line 1537 | Line 1651 | public class CountedCompleterTest extend
1651      public void testCancelledForkQuietlyJoinSingleton() {
1652          ForkJoinTask a = new CheckedRecursiveAction() {
1653              protected void realCompute() {
1654 <                CCF f = new LCCF(null, 8);
1654 >                CCF f = new LCCF(8);
1655                  assertTrue(f.cancel(true));
1656                  assertSame(f, f.fork());
1657                  f.quietlyJoin();
# Line 1552 | Line 1666 | public class CountedCompleterTest extend
1666      public void testCompleteExceptionallySingleton() {
1667          ForkJoinTask a = new CheckedRecursiveAction() {
1668              protected void realCompute() {
1669 <                CCF f = new LCCF(null, 8);
1670 <                f.completeExceptionally(new FJException());
1671 <                try {
1672 <                    f.invoke();
1673 <                    shouldThrow();
1674 <                } catch (FJException success) {
1561 <                    checkCompletedAbnormally(f, success);
1562 <                }
1669 >                CCF n = new LCCF(8);
1670 >                CCF f = new LCCF(n, 8);
1671 >                FJException ex = new FJException();
1672 >                f.completeExceptionally(ex);
1673 >                f.checkCompletedExceptionally(ex);
1674 >                n.checkCompletedExceptionally(ex);
1675              }};
1676          testInvokeOnPool(singletonPool(), a);
1677      }
# Line 1570 | Line 1682 | public class CountedCompleterTest extend
1682      public void testInvokeAll2Singleton() {
1683          ForkJoinTask a = new CheckedRecursiveAction() {
1684              protected void realCompute() {
1685 <                CCF f = new LCCF(null, 8);
1686 <                CCF g = new LCCF(null, 9);
1685 >                CCF f = new LCCF(8);
1686 >                CCF g = new LCCF(9);
1687                  invokeAll(f, g);
1688                  assertEquals(21, f.number);
1689                  assertEquals(34, g.number);
# Line 1587 | Line 1699 | public class CountedCompleterTest extend
1699      public void testInvokeAll1Singleton() {
1700          ForkJoinTask a = new CheckedRecursiveAction() {
1701              protected void realCompute() {
1702 <                CCF f = new LCCF(null, 8);
1702 >                CCF f = new LCCF(8);
1703                  invokeAll(f);
1704                  checkCompletedNormally(f);
1705                  assertEquals(21, f.number);
# Line 1601 | Line 1713 | public class CountedCompleterTest extend
1713      public void testInvokeAll3Singleton() {
1714          ForkJoinTask a = new CheckedRecursiveAction() {
1715              protected void realCompute() {
1716 <                CCF f = new LCCF(null, 8);
1717 <                CCF g = new LCCF(null, 9);
1718 <                CCF h = new LCCF(null, 7);
1716 >                CCF f = new LCCF(8);
1717 >                CCF g = new LCCF(9);
1718 >                CCF h = new LCCF(7);
1719                  invokeAll(f, g, h);
1720                  assertEquals(21, f.number);
1721                  assertEquals(34, g.number);
# Line 1621 | Line 1733 | public class CountedCompleterTest extend
1733      public void testInvokeAllCollectionSingleton() {
1734          ForkJoinTask a = new CheckedRecursiveAction() {
1735              protected void realCompute() {
1736 <                CCF f = new LCCF(null, 8);
1737 <                CCF g = new LCCF(null, 9);
1738 <                CCF h = new LCCF(null, 7);
1736 >                CCF f = new LCCF(8);
1737 >                CCF g = new LCCF(9);
1738 >                CCF h = new LCCF(7);
1739                  HashSet set = new HashSet();
1740                  set.add(f);
1741                  set.add(g);
# Line 1645 | Line 1757 | public class CountedCompleterTest extend
1757      public void testInvokeAllNPESingleton() {
1758          ForkJoinTask a = new CheckedRecursiveAction() {
1759              protected void realCompute() {
1760 <                CCF f = new LCCF(null, 8);
1761 <                CCF g = new LCCF(null, 9);
1760 >                CCF f = new LCCF(8);
1761 >                CCF g = new LCCF(9);
1762                  CCF h = null;
1763                  try {
1764                      invokeAll(f, g, h);
# Line 1662 | Line 1774 | public class CountedCompleterTest extend
1774      public void testAbnormalInvokeAll2Singleton() {
1775          ForkJoinTask a = new CheckedRecursiveAction() {
1776              protected void realCompute() {
1777 <                CCF f = new LCCF(null, 8);
1778 <                FailingCCF g = new LFCCF(null, 9);
1777 >                CCF f = new LCCF(8);
1778 >                FailingCCF g = new LFCCF(9);
1779                  try {
1780                      invokeAll(f, g);
1781                      shouldThrow();
# Line 1680 | Line 1792 | public class CountedCompleterTest extend
1792      public void testAbnormalInvokeAll1Singleton() {
1793          ForkJoinTask a = new CheckedRecursiveAction() {
1794              protected void realCompute() {
1795 <                FailingCCF g = new LFCCF(null, 9);
1795 >                FailingCCF g = new LFCCF(9);
1796                  try {
1797                      invokeAll(g);
1798                      shouldThrow();
# Line 1697 | Line 1809 | public class CountedCompleterTest extend
1809      public void testAbnormalInvokeAll3Singleton() {
1810          ForkJoinTask a = new CheckedRecursiveAction() {
1811              protected void realCompute() {
1812 <                CCF f = new LCCF(null, 8);
1813 <                FailingCCF g = new LFCCF(null, 9);
1814 <                CCF h = new LCCF(null, 7);
1812 >                CCF f = new LCCF(8);
1813 >                FailingCCF g = new LFCCF(9);
1814 >                CCF h = new LCCF(7);
1815                  try {
1816                      invokeAll(f, g, h);
1817                      shouldThrow();
# Line 1711 | Line 1823 | public class CountedCompleterTest extend
1823      }
1824  
1825      /**
1826 <     * invokeAll(collection)  throws exception if any task does
1826 >     * invokeAll(collection) throws exception if any task does
1827       */
1828      public void testAbnormalInvokeAllCollectionSingleton() {
1829          ForkJoinTask a = new CheckedRecursiveAction() {
1830              protected void realCompute() {
1831 <                FailingCCF f = new LFCCF(null, 8);
1832 <                CCF g = new LCCF(null, 9);
1833 <                CCF h = new LCCF(null, 7);
1831 >                FailingCCF f = new LFCCF(8);
1832 >                CCF g = new LCCF(9);
1833 >                CCF h = new LCCF(7);
1834                  HashSet set = new HashSet();
1835                  set.add(f);
1836                  set.add(g);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines