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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines