--- jsr166/src/test/tck/CountedCompleterTest.java 2013/06/03 18:20:05 1.7 +++ jsr166/src/test/tck/CountedCompleterTest.java 2021/01/26 13:33:05 1.38 @@ -3,25 +3,26 @@ * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ -import java.util.concurrent.ExecutionException; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +import java.util.HashSet; import java.util.concurrent.CancellationException; +import java.util.concurrent.CountedCompleter; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; -import java.util.concurrent.CountedCompleter; -import java.util.concurrent.ForkJoinWorkerThread; -import java.util.concurrent.RecursiveAction; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; -import java.util.HashSet; -import junit.framework.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import junit.framework.Test; +import junit.framework.TestSuite; public class CountedCompleterTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { @@ -46,8 +47,8 @@ public class CountedCompleterTest extend null, true); } - private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { - try { + private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { + try (PoolCleaner cleaner = cleaner(pool)) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -63,12 +64,10 @@ public class CountedCompleterTest extend assertFalse(a.isCancelled()); assertNull(a.getException()); assertNull(a.getRawResult()); - } finally { - joinPool(pool); } } - void checkNotDone(CountedCompleter a) { + void checkNotDone(CountedCompleter a) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -77,51 +76,49 @@ public class CountedCompleterTest extend assertNull(a.getRawResult()); try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkCompletedNormally(CountedCompleter a) { - checkCompletedNormally(a, null); - } - - void checkCompletedNormally(CountedCompleter a, T expected) { + void checkCompletedNormally(CountedCompleter a) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertTrue(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); assertNull(a.getException()); - assertSame(expected, a.getRawResult()); + assertNull(a.getRawResult()); { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); - assertSame(expected, a.join()); - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + long startTime = System.nanoTime(); + assertNull(a.join()); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); + + Object v1 = null, v2 = null; try { - assertSame(expected, a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertSame(expected, a.get(5L, SECONDS)); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(v1); + assertNull(v2); } - void checkCancelled(CountedCompleter a) { + void checkCancelled(CountedCompleter a) { assertTrue(a.isDone()); assertTrue(a.isCancelled()); assertFalse(a.isCompletedNormally()); @@ -140,9 +137,9 @@ public class CountedCompleterTest extend Thread.interrupted(); { - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } try { @@ -152,13 +149,13 @@ public class CountedCompleterTest extend } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkCompletedAbnormally(CountedCompleter a, Throwable t) { + void checkCompletedAbnormally(CountedCompleter a, Throwable t) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertFalse(a.isCompletedNormally()); @@ -178,9 +175,9 @@ public class CountedCompleterTest extend Thread.interrupted(); { - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } try { @@ -191,178 +188,292 @@ public class CountedCompleterTest extend } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (ExecutionException success) { assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } + + try { + a.invoke(); + shouldThrow(); + } catch (Throwable success) { + assertSame(t, success); + } } public static final class FJException extends RuntimeException { FJException() { super(); } } - static final class NoopCountedCompleter extends CountedCompleter { - boolean post; // set true if onCompletion called - NoopCountedCompleter() { super(); } - NoopCountedCompleter(CountedCompleter p) { super(p); } - public void compute() {} - public final void onCompletion(CountedCompleter caller) { - post = true; + abstract class CheckedCC extends CountedCompleter { + final AtomicInteger computeN = new AtomicInteger(0); + final AtomicInteger onCompletionN = new AtomicInteger(0); + final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); + final AtomicInteger setRawResultN = new AtomicInteger(0); + final AtomicReference rawResult = new AtomicReference<>(null); + int computeN() { return computeN.get(); } + int onCompletionN() { return onCompletionN.get(); } + int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } + int setRawResultN() { return setRawResultN.get(); } + + CheckedCC() { super(); } + CheckedCC(CountedCompleter p) { super(p); } + CheckedCC(CountedCompleter p, int n) { super(p, n); } + abstract void realCompute(); + public final void compute() { + computeN.incrementAndGet(); + realCompute(); + } + public void onCompletion(CountedCompleter caller) { + onCompletionN.incrementAndGet(); + super.onCompletion(caller); + } + public boolean onExceptionalCompletion(Throwable ex, + CountedCompleter caller) { + onExceptionalCompletionN.incrementAndGet(); + assertNotNull(ex); + assertTrue(isCompletedAbnormally()); + assertTrue(super.onExceptionalCompletion(ex, caller)); + return true; + } + protected void setRawResult(Object t) { + setRawResultN.incrementAndGet(); + rawResult.set(t); + super.setRawResult(t); + } + void checkIncomplete() { + assertEquals(0, computeN()); + assertEquals(0, onCompletionN()); + assertEquals(0, onExceptionalCompletionN()); + assertEquals(0, setRawResultN()); + checkNotDone(this); + } + void checkCompletes(Object rawResult) { + checkIncomplete(); + int pendingCount = getPendingCount(); + complete(rawResult); + assertEquals(pendingCount, getPendingCount()); + assertEquals(0, computeN()); + assertEquals(1, onCompletionN()); + assertEquals(0, onExceptionalCompletionN()); + assertEquals(1, setRawResultN()); + assertSame(rawResult, this.rawResult.get()); + checkCompletedNormally(this); + } + void checkCompletesExceptionally(Throwable ex) { + checkIncomplete(); + completeExceptionally(ex); + checkCompletedExceptionally(ex); + } + void checkCompletedExceptionally(Throwable ex) { + assertEquals(0, computeN()); + assertEquals(0, onCompletionN()); + assertEquals(1, onExceptionalCompletionN()); + assertEquals(0, setRawResultN()); + assertNull(this.rawResult.get()); + checkCompletedAbnormally(this, ex); + } + } + + final class NoopCC extends CheckedCC { + NoopCC() { super(); } + NoopCC(CountedCompleter p) { super(p); } + NoopCC(CountedCompleter p, int initialPendingCount) { + super(p, initialPendingCount); } + protected void realCompute() {} } /** * A newly constructed CountedCompleter is not completed; - * complete() causes completion. + * complete() causes completion. pendingCount is ignored. */ public void testComplete() { - NoopCountedCompleter a = new NoopCountedCompleter(); - assertFalse(a.isDone()); - assertFalse(a.isCompletedNormally()); - assertFalse(a.isCompletedAbnormally()); - assertFalse(a.isCancelled()); - assertNull(a.getException()); - assertNull(a.getRawResult()); - assertFalse(a.post); - a.complete(null); - assertTrue(a.post); - assertTrue(a.isDone()); - assertTrue(a.isCompletedNormally()); - assertFalse(a.isCompletedAbnormally()); - assertFalse(a.isCancelled()); - assertNull(a.getException()); - assertNull(a.getRawResult()); + for (Object x : new Object[] { Boolean.TRUE, null }) { + for (int pendingCount : new int[] { 0, 42 }) { + testComplete(new NoopCC(), x, pendingCount); + testComplete(new NoopCC(new NoopCC()), x, pendingCount); + } + } + } + void testComplete(NoopCC cc, Object x, int pendingCount) { + cc.setPendingCount(pendingCount); + cc.checkCompletes(x); + assertEquals(pendingCount, cc.getPendingCount()); } /** * completeExceptionally completes exceptionally */ public void testCompleteExceptionally() { - NoopCountedCompleter a = new NoopCountedCompleter(); - assertFalse(a.isDone()); - assertFalse(a.isCompletedNormally()); - assertFalse(a.isCompletedAbnormally()); - assertFalse(a.isCancelled()); - assertNull(a.getException()); - assertNull(a.getRawResult()); - assertFalse(a.post); - a.completeExceptionally(new FJException()); - assertFalse(a.post); - assertTrue(a.isDone()); - assertFalse(a.isCompletedNormally()); - assertTrue(a.isCompletedAbnormally()); - assertFalse(a.isCancelled()); - assertTrue(a.getException() instanceof FJException); - assertNull(a.getRawResult()); + new NoopCC() + .checkCompletesExceptionally(new FJException()); + new NoopCC(new NoopCC()) + .checkCompletesExceptionally(new FJException()); + } + + /** + * completeExceptionally(null) surprisingly has the same effect as + * completeExceptionally(new RuntimeException()) + */ + public void testCompleteExceptionally_null() { + NoopCC a = new NoopCC(); + a.completeExceptionally(null); + try { + a.invoke(); + shouldThrow(); + } catch (RuntimeException success) { + assertSame(success.getClass(), RuntimeException.class); + assertNull(success.getCause()); + a.checkCompletedExceptionally(success); + } } /** * setPendingCount sets the reported pending count */ public void testSetPendingCount() { - NoopCountedCompleter a = new NoopCountedCompleter(); + NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); - a.setPendingCount(1); - assertEquals(1, a.getPendingCount()); - a.setPendingCount(27); - assertEquals(27, a.getPendingCount()); + int[] vals = { + -1, 0, 1, + Integer.MIN_VALUE, + Integer.MAX_VALUE, + }; + for (int val : vals) { + a.setPendingCount(val); + assertEquals(val, a.getPendingCount()); + } } /** * addToPendingCount adds to the reported pending count */ public void testAddToPendingCount() { - NoopCountedCompleter a = new NoopCountedCompleter(); + NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); a.addToPendingCount(1); assertEquals(1, a.getPendingCount()); a.addToPendingCount(27); assertEquals(28, a.getPendingCount()); + a.addToPendingCount(-28); + assertEquals(0, a.getPendingCount()); } /** * decrementPendingCountUnlessZero decrements reported pending * count unless zero */ - public void testDecrementPendingCount() { - NoopCountedCompleter a = new NoopCountedCompleter(); - assertEquals(0, a.getPendingCount()); - a.addToPendingCount(1); + public void testDecrementPendingCountUnlessZero() { + NoopCC a = new NoopCC(null, 2); + assertEquals(2, a.getPendingCount()); + assertEquals(2, a.decrementPendingCountUnlessZero()); assertEquals(1, a.getPendingCount()); - a.decrementPendingCountUnlessZero(); + assertEquals(1, a.decrementPendingCountUnlessZero()); assertEquals(0, a.getPendingCount()); - a.decrementPendingCountUnlessZero(); + assertEquals(0, a.decrementPendingCountUnlessZero()); + assertEquals(0, a.getPendingCount()); + a.setPendingCount(-1); + assertEquals(-1, a.decrementPendingCountUnlessZero()); + assertEquals(-2, a.getPendingCount()); + } + + /** + * compareAndSetPendingCount compares and sets the reported + * pending count + */ + public void testCompareAndSetPendingCount() { + NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); + assertTrue(a.compareAndSetPendingCount(0, 1)); + assertEquals(1, a.getPendingCount()); + assertTrue(a.compareAndSetPendingCount(1, 2)); + assertEquals(2, a.getPendingCount()); + assertFalse(a.compareAndSetPendingCount(1, 3)); + assertEquals(2, a.getPendingCount()); } /** * getCompleter returns parent or null if at root */ public void testGetCompleter() { - NoopCountedCompleter a = new NoopCountedCompleter(); + NoopCC a = new NoopCC(); assertNull(a.getCompleter()); - CountedCompleter b = new NoopCountedCompleter(a); - assertEquals(a, b.getCompleter()); + NoopCC b = new NoopCC(a); + assertSame(a, b.getCompleter()); + NoopCC c = new NoopCC(b); + assertSame(b, c.getCompleter()); } /** * getRoot returns self if no parent, else parent's root */ public void testGetRoot() { - NoopCountedCompleter a = new NoopCountedCompleter(); - NoopCountedCompleter b = new NoopCountedCompleter(a); - assertEquals(a, a.getRoot()); - assertEquals(a, b.getRoot()); + NoopCC a = new NoopCC(); + NoopCC b = new NoopCC(a); + NoopCC c = new NoopCC(b); + assertSame(a, a.getRoot()); + assertSame(a, b.getRoot()); + assertSame(a, c.getRoot()); } /** - * tryComplete causes completion if pending count is zero + * tryComplete decrements pending count unless zero, in which case + * causes completion */ - public void testTryComplete1() { - NoopCountedCompleter a = new NoopCountedCompleter(); + public void testTryComplete() { + NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); + int n = 3; + a.setPendingCount(n); + for (; n > 0; n--) { + assertEquals(n, a.getPendingCount()); + a.tryComplete(); + a.checkIncomplete(); + assertEquals(n - 1, a.getPendingCount()); + } a.tryComplete(); - assertTrue(a.post); - assertTrue(a.isDone()); + assertEquals(0, a.computeN()); + assertEquals(1, a.onCompletionN()); + assertEquals(0, a.onExceptionalCompletionN()); + assertEquals(0, a.setRawResultN()); + checkCompletedNormally(a); } /** - * propagateCompletion causes completion without invoking - * onCompletion if pending count is zero + * propagateCompletion decrements pending count unless zero, in + * which case causes completion, without invoking onCompletion */ public void testPropagateCompletion() { - NoopCountedCompleter a = new NoopCountedCompleter(); + NoopCC a = new NoopCC(); assertEquals(0, a.getPendingCount()); + int n = 3; + a.setPendingCount(n); + for (; n > 0; n--) { + assertEquals(n, a.getPendingCount()); + a.propagateCompletion(); + a.checkIncomplete(); + assertEquals(n - 1, a.getPendingCount()); + } a.propagateCompletion(); - assertFalse(a.post); - assertTrue(a.isDone()); - } - - /** - * tryComplete decrements pending count unless zero - */ - public void testTryComplete2() { - NoopCountedCompleter a = new NoopCountedCompleter(); - assertEquals(0, a.getPendingCount()); - a.setPendingCount(1); - a.tryComplete(); - assertFalse(a.post); - assertFalse(a.isDone()); - assertEquals(0, a.getPendingCount()); - a.tryComplete(); - assertTrue(a.post); - assertTrue(a.isDone()); + assertEquals(0, a.computeN()); + assertEquals(0, a.onCompletionN()); + assertEquals(0, a.onExceptionalCompletionN()); + assertEquals(0, a.setRawResultN()); + checkCompletedNormally(a); } /** * firstComplete returns this if pending count is zero else null */ public void testFirstComplete() { - NoopCountedCompleter a = new NoopCountedCompleter(); + NoopCC a = new NoopCC(); a.setPendingCount(1); assertNull(a.firstComplete()); - assertEquals(a, a.firstComplete()); + a.checkIncomplete(); + assertSame(a, a.firstComplete()); + a.checkIncomplete(); } /** @@ -370,68 +481,73 @@ public class CountedCompleterTest extend * zero else null */ public void testNextComplete() { - NoopCountedCompleter a = new NoopCountedCompleter(); - NoopCountedCompleter b = new NoopCountedCompleter(a); + NoopCC a = new NoopCC(); + NoopCC b = new NoopCC(a); a.setPendingCount(1); b.setPendingCount(1); assertNull(b.firstComplete()); - CountedCompleter c = b.firstComplete(); - assertEquals(b, c); - CountedCompleter d = c.nextComplete(); - assertNull(d); - CountedCompleter e = c.nextComplete(); - assertEquals(a, e); + assertSame(b, b.firstComplete()); + assertNull(b.nextComplete()); + a.checkIncomplete(); + b.checkIncomplete(); + assertSame(a, b.nextComplete()); + assertSame(a, b.nextComplete()); + a.checkIncomplete(); + b.checkIncomplete(); + assertNull(a.nextComplete()); + b.checkIncomplete(); + checkCompletedNormally(a); } /** - * quietlyCompleteRoot completes root task + * quietlyCompleteRoot completes root task and only root task */ public void testQuietlyCompleteRoot() { - NoopCountedCompleter a = new NoopCountedCompleter(); - NoopCountedCompleter b = new NoopCountedCompleter(a); + NoopCC a = new NoopCC(); + NoopCC b = new NoopCC(a); + NoopCC c = new NoopCC(b); a.setPendingCount(1); b.setPendingCount(1); - b.quietlyCompleteRoot(); + c.setPendingCount(1); + c.quietlyCompleteRoot(); assertTrue(a.isDone()); assertFalse(b.isDone()); + assertFalse(c.isDone()); } // Invocation tests use some interdependent task classes // to better test propagation etc - - // Version of Fibonacci with different classes for left vs right forks - abstract static class CCF extends CountedCompleter { + /** + * Version of Fibonacci with different classes for left vs right forks + */ + abstract class CCF extends CheckedCC { int number; int rnumber; - public CCF(CountedCompleter parent, int n) { + public CCF(CountedCompleter parent, int n) { super(parent, 1); this.number = n; } - public final void compute() { - CountedCompleter p; + protected final void realCompute() { CCF f = this; int n = number; while (n >= 2) { new RCCF(f, n - 2).fork(); f = new LCCF(f, --n); } - f.number = n; - f.onCompletion(f); - if ((p = f.getCompleter()) != null) - p.tryComplete(); - else - f.quietlyComplete(); + f.complete(null); } } - static final class LCCF extends CCF { - public LCCF(CountedCompleter parent, int n) { + final class LCCF extends CCF { + public LCCF(int n) { this(null, n); } + public LCCF(CountedCompleter parent, int n) { super(parent, n); } - public final void onCompletion(CountedCompleter caller) { + public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); CCF p = (CCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -440,11 +556,12 @@ public class CountedCompleterTest extend number = n; } } - static final class RCCF extends CCF { - public RCCF(CountedCompleter parent, int n) { + final class RCCF extends CCF { + public RCCF(CountedCompleter parent, int n) { super(parent, n); } - public final void onCompletion(CountedCompleter caller) { + public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); CCF p = (CCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -455,37 +572,33 @@ public class CountedCompleterTest extend } // Version of CCF with forced failure in left completions - abstract static class FailingCCF extends CountedCompleter { + abstract class FailingCCF extends CheckedCC { int number; int rnumber; - public FailingCCF(CountedCompleter parent, int n) { + public FailingCCF(CountedCompleter parent, int n) { super(parent, 1); this.number = n; } - public final void compute() { - CountedCompleter p; + protected final void realCompute() { FailingCCF f = this; int n = number; while (n >= 2) { new RFCCF(f, n - 2).fork(); f = new LFCCF(f, --n); } - f.number = n; - f.onCompletion(f); - if ((p = f.getCompleter()) != null) - p.tryComplete(); - else - f.quietlyComplete(); + f.complete(null); } } - static final class LFCCF extends FailingCCF { - public LFCCF(CountedCompleter parent, int n) { + final class LFCCF extends FailingCCF { + public LFCCF(int n) { this(null, n); } + public LFCCF(CountedCompleter parent, int n) { super(parent, n); } - public final void onCompletion(CountedCompleter caller) { + public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); FailingCCF p = (FailingCCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -494,11 +607,12 @@ public class CountedCompleterTest extend number = n; } } - static final class RFCCF extends FailingCCF { - public RFCCF(CountedCompleter parent, int n) { + final class RFCCF extends FailingCCF { + public RFCCF(CountedCompleter parent, int n) { super(parent, n); } - public final void onCompletion(CountedCompleter caller) { + public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); completeExceptionally(new FJException()); } } @@ -509,9 +623,9 @@ public class CountedCompleterTest extend * completed tasks; getRawResult returns null. */ public void testInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertNull(f.invoke()); assertEquals(21, f.number); checkCompletedNormally(f); @@ -525,9 +639,9 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); f.quietlyInvoke(); assertEquals(21, f.number); checkCompletedNormally(f); @@ -539,9 +653,9 @@ public class CountedCompleterTest extend * join of a forked task returns when task completes */ public void testForkJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); @@ -554,9 +668,9 @@ public class CountedCompleterTest extend * get of a forked task returns when task completes */ public void testForkGet() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); @@ -569,9 +683,9 @@ public class CountedCompleterTest extend * timed get of a forked task returns when task completes */ public void testForkTimedGet() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); @@ -584,12 +698,12 @@ public class CountedCompleterTest extend * timed get with null time unit throws NPE */ public void testForkTimedGetNPE() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -600,9 +714,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); @@ -616,11 +730,13 @@ public class CountedCompleterTest extend * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesce() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(21, f.number); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -632,9 +748,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task completes abnormally */ public void testAbnormalInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); try { f.invoke(); shouldThrow(); @@ -649,9 +765,9 @@ public class CountedCompleterTest extend * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); checkCompletedAbnormally(f, f.getException()); @@ -663,9 +779,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.join(); @@ -681,9 +797,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGet() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(); @@ -701,9 +817,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGet() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(LONG_DELAY_MS, MILLISECONDS); @@ -721,9 +837,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); @@ -736,9 +852,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task cancelled */ public void testCancelledInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); try { f.invoke(); @@ -754,9 +870,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -773,9 +889,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task cancelled */ public void testCancelledForkGet() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -792,9 +908,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGet() throws Exception { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -811,9 +927,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoin() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); @@ -827,7 +943,7 @@ public class CountedCompleterTest extend */ public void testGetPool() { final ForkJoinPool mainPool = mainPool(); - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { assertSame(mainPool, getPool()); }}; @@ -838,7 +954,7 @@ public class CountedCompleterTest extend * getPool of non-FJ task returns null */ public void testGetPool2() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { assertNull(getPool()); }}; @@ -849,7 +965,7 @@ public class CountedCompleterTest extend * inForkJoinPool of executing task returns true */ public void testInForkJoinPool() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { assertTrue(inForkJoinPool()); }}; @@ -860,7 +976,7 @@ public class CountedCompleterTest extend * inForkJoinPool of non-FJ task returns false */ public void testInForkJoinPool2() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { assertFalse(inForkJoinPool()); }}; @@ -871,7 +987,7 @@ public class CountedCompleterTest extend * setRawResult(null) succeeds */ public void testSetRawResult() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { setRawResult(null); assertNull(getRawResult()); @@ -883,16 +999,14 @@ public class CountedCompleterTest extend * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionally2() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - f.completeExceptionally(new FJException()); - try { - f.invoke(); - shouldThrow(); - } catch (FJException success) { - checkCompletedAbnormally(f, success); - } + CCF n = new LCCF(8); + CCF f = new LCCF(n, 8); + FJException ex = new FJException(); + f.completeExceptionally(ex); + f.checkCompletedExceptionally(ex); + n.checkCompletedExceptionally(ex); }}; testInvokeOnPool(mainPool(), a); } @@ -901,10 +1015,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + CCF f = new LCCF(8); + CCF g = new LCCF(9); invokeAll(f, g); assertEquals(21, f.number); assertEquals(34, g.number); @@ -918,9 +1032,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); invokeAll(f); checkCompletedNormally(f); assertEquals(21, f.number); @@ -932,11 +1046,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + CCF f = new LCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); invokeAll(f, g, h); assertEquals(21, f.number); assertEquals(34, g.number); @@ -952,12 +1066,12 @@ public class CountedCompleterTest extend * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollection() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); - HashSet set = new HashSet(); + CCF f = new LCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); + HashSet set = new HashSet(); set.add(f); set.add(g); set.add(h); @@ -976,10 +1090,10 @@ public class CountedCompleterTest extend * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPE() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + CCF f = new LCCF(8); + CCF g = new LCCF(9); CCF h = null; try { invokeAll(f, g, h); @@ -993,10 +1107,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); try { invokeAll(f, g); shouldThrow(); @@ -1011,9 +1125,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF g = new LFCCF(null, 9); + FailingCCF g = new LFCCF(9); try { invokeAll(g); shouldThrow(); @@ -1028,11 +1142,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); - CCF h = new LCCF(null, 7); + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); + CCF h = new LCCF(7); try { invokeAll(f, g, h); shouldThrow(); @@ -1044,15 +1158,15 @@ public class CountedCompleterTest extend } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); - HashSet set = new HashSet(); + FailingCCF f = new LFCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -1071,11 +1185,11 @@ public class CountedCompleterTest extend * and suppresses execution */ public void testTryUnfork() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertTrue(f.tryUnfork()); helpQuiesce(); @@ -1090,13 +1204,13 @@ public class CountedCompleterTest extend * there are more tasks than threads */ public void testGetSurplusQueuedTaskCount() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF h = new LCCF(null, 7); + CCF h = new LCCF(7); assertSame(h, h.fork()); - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertTrue(getSurplusQueuedTaskCount() > 0); helpQuiesce(); @@ -1112,11 +1226,11 @@ public class CountedCompleterTest extend * peekNextLocalTask returns most recent unexecuted task. */ public void testPeekNextLocalTask() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(f, peekNextLocalTask()); assertNull(f.join()); @@ -1132,11 +1246,11 @@ public class CountedCompleterTest extend * executing it */ public void testPollNextLocalTask() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(f, pollNextLocalTask()); helpQuiesce(); @@ -1151,11 +1265,11 @@ public class CountedCompleterTest extend * pollTask returns an unexecuted task without executing it */ public void testPollTask() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(f, pollTask()); helpQuiesce(); @@ -1169,11 +1283,11 @@ public class CountedCompleterTest extend * peekNextLocalTask returns least recent unexecuted task in async mode */ public void testPeekNextLocalTaskAsync() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(g, peekNextLocalTask()); assertNull(f.join()); @@ -1190,11 +1304,11 @@ public class CountedCompleterTest extend * executing it, in async mode */ public void testPollNextLocalTaskAsync() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(g, pollNextLocalTask()); helpQuiesce(); @@ -1210,11 +1324,11 @@ public class CountedCompleterTest extend * async mode */ public void testPollTaskAsync() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF g = new LCCF(null, 9); + CCF g = new LCCF(9); assertSame(g, g.fork()); - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertSame(g, pollTask()); helpQuiesce(); @@ -1233,9 +1347,9 @@ public class CountedCompleterTest extend * completed tasks; getRawResult returns null. */ public void testInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertNull(f.invoke()); assertEquals(21, f.number); checkCompletedNormally(f); @@ -1249,9 +1363,9 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); f.quietlyInvoke(); assertEquals(21, f.number); checkCompletedNormally(f); @@ -1263,9 +1377,9 @@ public class CountedCompleterTest extend * join of a forked task returns when task completes */ public void testForkJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); @@ -1278,9 +1392,9 @@ public class CountedCompleterTest extend * get of a forked task returns when task completes */ public void testForkGetSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); @@ -1293,9 +1407,9 @@ public class CountedCompleterTest extend * timed get of a forked task returns when task completes */ public void testForkTimedGetSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); @@ -1308,12 +1422,12 @@ public class CountedCompleterTest extend * timed get with null time unit throws NPE */ public void testForkTimedGetNPESingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -1324,9 +1438,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); @@ -1340,9 +1454,9 @@ public class CountedCompleterTest extend * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesceSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertSame(f, f.fork()); helpQuiesce(); assertEquals(0, getQueuedTaskCount()); @@ -1356,9 +1470,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task completes abnormally */ public void testAbnormalInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); try { f.invoke(); shouldThrow(); @@ -1373,9 +1487,9 @@ public class CountedCompleterTest extend * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); checkCompletedAbnormally(f, f.getException()); @@ -1387,9 +1501,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.join(); @@ -1405,9 +1519,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGetSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(); @@ -1425,9 +1539,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGetSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(LONG_DELAY_MS, MILLISECONDS); @@ -1445,9 +1559,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); @@ -1460,9 +1574,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task cancelled */ public void testCancelledInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); try { f.invoke(); @@ -1478,9 +1592,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1497,9 +1611,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task cancelled */ public void testCancelledForkGetSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1516,9 +1630,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGetSingleton() throws Exception { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1535,9 +1649,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); @@ -1550,16 +1664,14 @@ public class CountedCompleterTest extend * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionallySingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - f.completeExceptionally(new FJException()); - try { - f.invoke(); - shouldThrow(); - } catch (FJException success) { - checkCompletedAbnormally(f, success); - } + CCF n = new LCCF(8); + CCF f = new LCCF(n, 8); + FJException ex = new FJException(); + f.completeExceptionally(ex); + f.checkCompletedExceptionally(ex); + n.checkCompletedExceptionally(ex); }}; testInvokeOnPool(singletonPool(), a); } @@ -1568,10 +1680,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + CCF f = new LCCF(8); + CCF g = new LCCF(9); invokeAll(f, g); assertEquals(21, f.number); assertEquals(34, g.number); @@ -1585,9 +1697,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); + CCF f = new LCCF(8); invokeAll(f); checkCompletedNormally(f); assertEquals(21, f.number); @@ -1599,11 +1711,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + CCF f = new LCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); invokeAll(f, g, h); assertEquals(21, f.number); assertEquals(34, g.number); @@ -1619,12 +1731,12 @@ public class CountedCompleterTest extend * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollectionSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); - HashSet set = new HashSet(); + CCF f = new LCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -1643,10 +1755,10 @@ public class CountedCompleterTest extend * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPESingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + CCF f = new LCCF(8); + CCF g = new LCCF(9); CCF h = null; try { invokeAll(f, g, h); @@ -1660,10 +1772,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); try { invokeAll(f, g); shouldThrow(); @@ -1678,9 +1790,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF g = new LFCCF(null, 9); + FailingCCF g = new LFCCF(9); try { invokeAll(g); shouldThrow(); @@ -1695,11 +1807,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3Singleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); - CCF h = new LCCF(null, 7); + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); + CCF h = new LCCF(7); try { invokeAll(f, g, h); shouldThrow(); @@ -1711,15 +1823,15 @@ public class CountedCompleterTest extend } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollectionSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { - FailingCCF f = new LFCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); - HashSet set = new HashSet(); + FailingCCF f = new LFCCF(8); + CCF g = new LCCF(9); + CCF h = new LCCF(7); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h);