--- jsr166/src/test/tck/CountedCompleterTest.java 2013/03/22 16:10:19 1.3 +++ jsr166/src/test/tck/CountedCompleterTest.java 2017/10/21 06:53:36 1.34 @@ -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() { @@ -32,21 +33,6 @@ public class CountedCompleterTest extend static final int mainPoolSize = Math.max(2, Runtime.getRuntime().availableProcessors()); - /** - * Analog of CheckedRunnable for ForkJoinTasks - */ - public abstract class CheckedFJTask extends RecursiveAction { - protected abstract void realCompute() throws Throwable; - - public final void compute() { - try { - realCompute(); - } catch (Throwable t) { - threadUnexpectedException(t); - } - } - } - private static ForkJoinPool mainPool() { return new ForkJoinPool(mainPoolSize); } @@ -62,7 +48,7 @@ public class CountedCompleterTest extend } private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { - try { + try (PoolCleaner cleaner = cleaner(pool)) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -78,8 +64,6 @@ public class CountedCompleterTest extend assertFalse(a.isCancelled()); assertNull(a.getException()); assertNull(a.getRawResult()); - } finally { - joinPool(pool); } } @@ -92,48 +76,42 @@ 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)); try { - assertSame(expected, a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertSame(expected, a.get(5L, SECONDS)); - } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(a.get()); + assertNull(a.get(randomTimeout(), randomTimeUnit())); + } catch (Exception fail) { threadUnexpectedException(fail); } } void checkCancelled(CountedCompleter a) { @@ -155,9 +133,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 { @@ -167,7 +145,7 @@ 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); } @@ -193,9 +171,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 { @@ -206,178 +184,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()); + CountedCompleter b = new NoopCC(a); + assertSame(a, b.getCompleter()); + CountedCompleter 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 invokein - * 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 decrments 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(); } /** @@ -385,38 +477,47 @@ 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; @@ -425,28 +526,24 @@ public class CountedCompleterTest extend 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 { + 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) { + super.onCompletion(caller); CCF p = (CCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -455,11 +552,12 @@ public class CountedCompleterTest extend number = n; } } - static final class RCCF extends CCF { + final class RCCF extends CCF { public RCCF(CountedCompleter parent, int n) { super(parent, n); } public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); CCF p = (CCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -470,7 +568,7 @@ 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; @@ -479,28 +577,24 @@ public class CountedCompleterTest extend 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 { + 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) { + super.onCompletion(caller); FailingCCF p = (FailingCCF)getCompleter(); int n = number + rnumber; if (p != null) @@ -509,11 +603,12 @@ public class CountedCompleterTest extend number = n; } } - static final class RFCCF extends FailingCCF { + final class RFCCF extends FailingCCF { public RFCCF(CountedCompleter parent, int n) { super(parent, n); } public final void onCompletion(CountedCompleter caller) { + super.onCompletion(caller); completeExceptionally(new FJException()); } } @@ -524,9 +619,9 @@ public class CountedCompleterTest extend * completed tasks; getRawResult returns null. */ public void testInvoke() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertNull(f.invoke()); assertEquals(21, f.number); checkCompletedNormally(f); @@ -540,9 +635,9 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvoke() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); f.quietlyInvoke(); assertEquals(21, f.number); checkCompletedNormally(f); @@ -554,9 +649,9 @@ public class CountedCompleterTest extend * join of a forked task returns when task completes */ public void testForkJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); @@ -569,9 +664,9 @@ public class CountedCompleterTest extend * get of a forked task returns when task completes */ public void testForkGet() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); @@ -584,9 +679,9 @@ public class CountedCompleterTest extend * timed get of a forked task returns when task completes */ public void testForkTimedGet() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); @@ -599,12 +694,12 @@ public class CountedCompleterTest extend * timed get with null time unit throws NPE */ public void testForkTimedGetNPE() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -615,9 +710,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); @@ -631,9 +726,9 @@ public class CountedCompleterTest extend * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesce() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); helpQuiesce(); assertEquals(21, f.number); @@ -647,9 +742,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task completes abnormally */ public void testAbnormalInvoke() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); try { f.invoke(); shouldThrow(); @@ -664,9 +759,9 @@ public class CountedCompleterTest extend * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvoke() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); checkCompletedAbnormally(f, f.getException()); @@ -678,9 +773,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.join(); @@ -696,9 +791,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGet() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(); @@ -716,9 +811,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGet() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(LONG_DELAY_MS, MILLISECONDS); @@ -736,9 +831,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); @@ -751,9 +846,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task cancelled */ public void testCancelledInvoke() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); try { f.invoke(); @@ -769,9 +864,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -788,9 +883,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task cancelled */ public void testCancelledForkGet() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -807,9 +902,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGet() throws Exception { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -826,9 +921,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoin() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); @@ -842,8 +937,8 @@ public class CountedCompleterTest extend */ public void testGetPool() { final ForkJoinPool mainPool = mainPool(); - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { assertSame(mainPool, getPool()); }}; testInvokeOnPool(mainPool, a); @@ -853,8 +948,8 @@ public class CountedCompleterTest extend * getPool of non-FJ task returns null */ public void testGetPool2() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { assertNull(getPool()); }}; assertNull(a.invoke()); @@ -864,8 +959,8 @@ public class CountedCompleterTest extend * inForkJoinPool of executing task returns true */ public void testInForkJoinPool() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { assertTrue(inForkJoinPool()); }}; testInvokeOnPool(mainPool(), a); @@ -875,8 +970,8 @@ public class CountedCompleterTest extend * inForkJoinPool of non-FJ task returns false */ public void testInForkJoinPool2() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { assertFalse(inForkJoinPool()); }}; assertNull(a.invoke()); @@ -886,8 +981,8 @@ public class CountedCompleterTest extend * setRawResult(null) succeeds */ public void testSetRawResult() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { setRawResult(null); assertNull(getRawResult()); }}; @@ -898,16 +993,14 @@ public class CountedCompleterTest extend * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionally2() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - f.completeExceptionally(new FJException()); - try { - f.invoke(); - shouldThrow(); - } catch (FJException success) { - checkCompletedAbnormally(f, success); - } + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); } @@ -916,10 +1009,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + CCF g = new LCCF(9); invokeAll(f, g); assertEquals(21, f.number); assertEquals(34, g.number); @@ -933,9 +1026,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); invokeAll(f); checkCompletedNormally(f); assertEquals(21, f.number); @@ -947,11 +1040,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); @@ -967,11 +1060,11 @@ public class CountedCompleterTest extend * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollection() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); @@ -991,10 +1084,10 @@ public class CountedCompleterTest extend * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPE() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + CCF g = new LCCF(9); CCF h = null; try { invokeAll(f, g, h); @@ -1008,10 +1101,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); try { invokeAll(f, g); shouldThrow(); @@ -1026,9 +1119,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF g = new LFCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF g = new LFCCF(9); try { invokeAll(g); shouldThrow(); @@ -1043,11 +1136,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); + CCF h = new LCCF(7); try { invokeAll(f, g, h); shouldThrow(); @@ -1059,14 +1152,14 @@ 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 CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); @@ -1086,11 +1179,11 @@ public class CountedCompleterTest extend * and suppresses execution */ public void testTryUnfork() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1105,13 +1198,13 @@ public class CountedCompleterTest extend * there are more tasks than threads */ public void testGetSurplusQueuedTaskCount() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1127,11 +1220,11 @@ public class CountedCompleterTest extend * peekNextLocalTask returns most recent unexecuted task. */ public void testPeekNextLocalTask() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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()); @@ -1147,11 +1240,11 @@ public class CountedCompleterTest extend * executing it */ public void testPollNextLocalTask() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1166,11 +1259,11 @@ public class CountedCompleterTest extend * pollTask returns an unexecuted task without executing it */ public void testPollTask() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1184,11 +1277,11 @@ public class CountedCompleterTest extend * peekNextLocalTask returns least recent unexecuted task in async mode */ public void testPeekNextLocalTaskAsync() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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()); @@ -1205,11 +1298,11 @@ public class CountedCompleterTest extend * executing it, in async mode */ public void testPollNextLocalTaskAsync() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1225,11 +1318,11 @@ public class CountedCompleterTest extend * async mode */ public void testPollTaskAsync() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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(); @@ -1248,9 +1341,9 @@ public class CountedCompleterTest extend * completed tasks; getRawResult returns null. */ public void testInvokeSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertNull(f.invoke()); assertEquals(21, f.number); checkCompletedNormally(f); @@ -1264,9 +1357,9 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvokeSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); f.quietlyInvoke(); assertEquals(21, f.number); checkCompletedNormally(f); @@ -1278,9 +1371,9 @@ public class CountedCompleterTest extend * join of a forked task returns when task completes */ public void testForkJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); @@ -1293,9 +1386,9 @@ public class CountedCompleterTest extend * get of a forked task returns when task completes */ public void testForkGetSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); @@ -1308,9 +1401,9 @@ public class CountedCompleterTest extend * timed get of a forked task returns when task completes */ public void testForkTimedGetSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); @@ -1323,12 +1416,12 @@ public class CountedCompleterTest extend * timed get with null time unit throws NPE */ public void testForkTimedGetNPESingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -1339,9 +1432,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); @@ -1355,9 +1448,9 @@ public class CountedCompleterTest extend * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesceSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertSame(f, f.fork()); helpQuiesce(); assertEquals(0, getQueuedTaskCount()); @@ -1371,9 +1464,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task completes abnormally */ public void testAbnormalInvokeSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); try { f.invoke(); shouldThrow(); @@ -1388,9 +1481,9 @@ public class CountedCompleterTest extend * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvokeSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); checkCompletedAbnormally(f, f.getException()); @@ -1402,9 +1495,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.join(); @@ -1420,9 +1513,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGetSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(); @@ -1440,9 +1533,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGetSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); try { f.get(LONG_DELAY_MS, MILLISECONDS); @@ -1460,9 +1553,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF f = new LFCCF(8); assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); @@ -1475,9 +1568,9 @@ public class CountedCompleterTest extend * invoke task throws exception when task cancelled */ public void testCancelledInvokeSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); try { f.invoke(); @@ -1493,9 +1586,9 @@ public class CountedCompleterTest extend * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1512,9 +1605,9 @@ public class CountedCompleterTest extend * get of a forked task throws exception when task cancelled */ public void testCancelledForkGetSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1531,9 +1624,9 @@ public class CountedCompleterTest extend * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGetSingleton() throws Exception { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() throws Exception { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() throws Exception { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { @@ -1550,9 +1643,9 @@ public class CountedCompleterTest extend * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoinSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); @@ -1565,16 +1658,14 @@ public class CountedCompleterTest extend * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionallySingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - f.completeExceptionally(new FJException()); - try { - f.invoke(); - shouldThrow(); - } catch (FJException success) { - checkCompletedAbnormally(f, success); - } + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); } @@ -1583,10 +1674,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + CCF g = new LCCF(9); invokeAll(f, g); assertEquals(21, f.number); assertEquals(34, g.number); @@ -1600,9 +1691,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); invokeAll(f); checkCompletedNormally(f); assertEquals(21, f.number); @@ -1614,11 +1705,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); @@ -1634,11 +1725,11 @@ public class CountedCompleterTest extend * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollectionSingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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); @@ -1658,10 +1749,10 @@ public class CountedCompleterTest extend * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPESingleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - CCF g = new LCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + CCF g = new LCCF(9); CCF h = null; try { invokeAll(f, g, h); @@ -1675,10 +1766,10 @@ public class CountedCompleterTest extend * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); try { invokeAll(f, g); shouldThrow(); @@ -1693,9 +1784,9 @@ public class CountedCompleterTest extend * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - FailingCCF g = new LFCCF(null, 9); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + FailingCCF g = new LFCCF(9); try { invokeAll(g); shouldThrow(); @@ -1710,11 +1801,11 @@ public class CountedCompleterTest extend * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3Singleton() { - ForkJoinTask a = new CheckedFJTask() { - public void realCompute() { - CCF f = new LCCF(null, 8); - FailingCCF g = new LFCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + CCF f = new LCCF(8); + FailingCCF g = new LFCCF(9); + CCF h = new LCCF(7); try { invokeAll(f, g, h); shouldThrow(); @@ -1726,14 +1817,14 @@ 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 CheckedFJTask() { - public void realCompute() { - FailingCCF f = new LFCCF(null, 8); - CCF g = new LCCF(null, 9); - CCF h = new LCCF(null, 7); + ForkJoinTask a = new CheckedRecursiveAction() { + protected void realCompute() { + 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);