--- jsr166/src/test/tck/CountedCompleterTest.java 2013/06/05 05:48:26 1.9 +++ jsr166/src/test/tck/CountedCompleterTest.java 2021/01/26 13:33:05 1.38 @@ -3,27 +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.AtomicInteger; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReference; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; -import java.util.HashSet; -import junit.framework.*; + +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() { @@ -48,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()); @@ -65,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()); @@ -79,7 +76,7 @@ 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); } @@ -95,31 +92,33 @@ public class CountedCompleterTest extend { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); assertNull(a.join()); - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + 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 { - assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(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()); @@ -138,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 { @@ -150,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()); @@ -176,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 { @@ -189,7 +188,7 @@ 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()); @@ -198,8 +197,8 @@ public class CountedCompleterTest extend try { a.invoke(); shouldThrow(); - } catch (Throwable ex) { - assertSame(t, ex); + } catch (Throwable success) { + assertSame(t, success); } } @@ -219,19 +218,19 @@ public class CountedCompleterTest extend int setRawResultN() { return setRawResultN.get(); } CheckedCC() { super(); } - CheckedCC(CountedCompleter p) { super(p); } - CheckedCC(CountedCompleter p, int n) { super(p, n); } + 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) { + public void onCompletion(CountedCompleter caller) { onCompletionN.incrementAndGet(); super.onCompletion(caller); } public boolean onExceptionalCompletion(Throwable ex, - CountedCompleter caller) { + CountedCompleter caller) { onExceptionalCompletionN.incrementAndGet(); assertNotNull(ex); assertTrue(isCompletedAbnormally()); @@ -252,7 +251,9 @@ public class CountedCompleterTest extend } void checkCompletes(Object rawResult) { checkIncomplete(); + int pendingCount = getPendingCount(); complete(rawResult); + assertEquals(pendingCount, getPendingCount()); assertEquals(0, computeN()); assertEquals(1, onCompletionN()); assertEquals(0, onExceptionalCompletionN()); @@ -277,22 +278,30 @@ public class CountedCompleterTest extend final class NoopCC extends CheckedCC { NoopCC() { super(); } - NoopCC(CountedCompleter p) { super(p); } + 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() { for (Object x : new Object[] { Boolean.TRUE, null }) { - new NoopCC() - .checkCompletes(x); - new NoopCC(new NoopCC()) - .checkCompletes(x); + 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 @@ -305,14 +314,20 @@ public class CountedCompleterTest extend } /** - * completeExceptionally(null) throws NullPointerException + * completeExceptionally(null) surprisingly has the same effect as + * completeExceptionally(new RuntimeException()) */ public void testCompleteExceptionally_null() { + NoopCC a = new NoopCC(); + a.completeExceptionally(null); try { - new NoopCC() - .checkCompletesExceptionally(null); + a.invoke(); shouldThrow(); - } catch (NullPointerException success) {} + } catch (RuntimeException success) { + assertSame(success.getClass(), RuntimeException.class); + assertNull(success.getCause()); + a.checkCompletedExceptionally(success); + } } /** @@ -321,10 +336,15 @@ public class CountedCompleterTest extend public void testSetPendingCount() { 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()); + } } /** @@ -337,21 +357,26 @@ public class CountedCompleterTest extend 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() { - NoopCC a = new NoopCC(); - 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()); } /** @@ -375,9 +400,9 @@ public class CountedCompleterTest extend public void testGetCompleter() { NoopCC a = new NoopCC(); assertNull(a.getCompleter()); - CountedCompleter b = new NoopCC(a); + NoopCC b = new NoopCC(a); assertSame(a, b.getCompleter()); - CountedCompleter c = new NoopCC(b); + NoopCC c = new NoopCC(b); assertSame(b, c.getCompleter()); } @@ -475,7 +500,7 @@ public class CountedCompleterTest extend } /** - * quietlyCompleteRoot completes root task + * quietlyCompleteRoot completes root task and only root task */ public void testQuietlyCompleteRoot() { NoopCC a = new NoopCC(); @@ -493,13 +518,14 @@ public class CountedCompleterTest extend // Invocation tests use some interdependent task classes // to better test propagation etc - - // Version of Fibonacci with different classes for left vs right forks + /** + * 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; } @@ -517,10 +543,10 @@ public class CountedCompleterTest extend final class LCCF extends CCF { public LCCF(int n) { this(null, n); } - public LCCF(CountedCompleter parent, int 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; @@ -531,10 +557,10 @@ public class CountedCompleterTest extend } } final class RCCF extends CCF { - public RCCF(CountedCompleter parent, int n) { + 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; @@ -550,7 +576,7 @@ public class CountedCompleterTest extend int number; int rnumber; - public FailingCCF(CountedCompleter parent, int n) { + public FailingCCF(CountedCompleter parent, int n) { super(parent, 1); this.number = n; } @@ -568,10 +594,10 @@ public class CountedCompleterTest extend final class LFCCF extends FailingCCF { public LFCCF(int n) { this(null, n); } - public LFCCF(CountedCompleter parent, int 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; @@ -582,10 +608,10 @@ public class CountedCompleterTest extend } } final class RFCCF extends FailingCCF { - public RFCCF(CountedCompleter parent, int n) { + 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()); } @@ -597,7 +623,7 @@ 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(8); assertNull(f.invoke()); @@ -613,7 +639,7 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvoke() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { CCF f = new LCCF(8); f.quietlyInvoke(); @@ -627,7 +653,7 @@ 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(8); assertSame(f, f.fork()); @@ -642,7 +668,7 @@ 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(8); assertSame(f, f.fork()); @@ -657,7 +683,7 @@ 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(8); assertSame(f, f.fork()); @@ -672,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(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -688,7 +714,7 @@ 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(8); assertSame(f, f.fork()); @@ -704,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(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(21, f.number); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -720,7 +748,7 @@ 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(8); try { @@ -737,7 +765,7 @@ 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(8); f.quietlyInvoke(); @@ -751,7 +779,7 @@ 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(8); assertSame(f, f.fork()); @@ -769,7 +797,7 @@ 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(8); assertSame(f, f.fork()); @@ -789,7 +817,7 @@ 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(8); assertSame(f, f.fork()); @@ -809,7 +837,7 @@ 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(8); assertSame(f, f.fork()); @@ -824,7 +852,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -842,7 +870,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -861,7 +889,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -880,7 +908,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -899,7 +927,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -915,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()); }}; @@ -926,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()); }}; @@ -937,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()); }}; @@ -948,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()); }}; @@ -959,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()); @@ -971,7 +999,7 @@ 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 n = new LCCF(8); CCF f = new LCCF(n, 8); @@ -987,7 +1015,7 @@ 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(8); CCF g = new LCCF(9); @@ -1004,7 +1032,7 @@ 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(8); invokeAll(f); @@ -1018,7 +1046,7 @@ 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(8); CCF g = new LCCF(9); @@ -1038,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(8); CCF g = new LCCF(9); CCF h = new LCCF(7); - HashSet set = new HashSet(); + HashSet set = new HashSet(); set.add(f); set.add(g); set.add(h); @@ -1062,7 +1090,7 @@ 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(8); CCF g = new LCCF(9); @@ -1079,7 +1107,7 @@ 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(8); FailingCCF g = new LFCCF(9); @@ -1097,7 +1125,7 @@ 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(9); try { @@ -1114,7 +1142,7 @@ 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(8); FailingCCF g = new LFCCF(9); @@ -1130,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(8); CCF g = new LCCF(9); CCF h = new LCCF(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -1157,7 +1185,7 @@ 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(9); assertSame(g, g.fork()); @@ -1176,7 +1204,7 @@ 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(7); assertSame(h, h.fork()); @@ -1198,7 +1226,7 @@ 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(9); assertSame(g, g.fork()); @@ -1218,7 +1246,7 @@ public class CountedCompleterTest extend * executing it */ public void testPollNextLocalTask() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { CCF g = new LCCF(9); assertSame(g, g.fork()); @@ -1237,7 +1265,7 @@ 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(9); assertSame(g, g.fork()); @@ -1255,7 +1283,7 @@ 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(9); assertSame(g, g.fork()); @@ -1276,7 +1304,7 @@ 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(9); assertSame(g, g.fork()); @@ -1296,7 +1324,7 @@ public class CountedCompleterTest extend * async mode */ public void testPollTaskAsync() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { CCF g = new LCCF(9); assertSame(g, g.fork()); @@ -1319,7 +1347,7 @@ 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(8); assertNull(f.invoke()); @@ -1335,7 +1363,7 @@ public class CountedCompleterTest extend * completed tasks */ public void testQuietlyInvokeSingleton() { - ForkJoinTask a = new CheckedRecursiveAction() { + CheckedRecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { CCF f = new LCCF(8); f.quietlyInvoke(); @@ -1349,7 +1377,7 @@ 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(8); assertSame(f, f.fork()); @@ -1364,7 +1392,7 @@ 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(8); assertSame(f, f.fork()); @@ -1379,7 +1407,7 @@ 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(8); assertSame(f, f.fork()); @@ -1394,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(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -1410,7 +1438,7 @@ 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(8); assertSame(f, f.fork()); @@ -1426,7 +1454,7 @@ 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(8); assertSame(f, f.fork()); @@ -1442,7 +1470,7 @@ 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(8); try { @@ -1459,7 +1487,7 @@ 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(8); f.quietlyInvoke(); @@ -1473,7 +1501,7 @@ 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(8); assertSame(f, f.fork()); @@ -1491,7 +1519,7 @@ 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(8); assertSame(f, f.fork()); @@ -1511,7 +1539,7 @@ 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(8); assertSame(f, f.fork()); @@ -1531,7 +1559,7 @@ 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(8); assertSame(f, f.fork()); @@ -1546,7 +1574,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -1564,7 +1592,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -1583,7 +1611,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -1602,7 +1630,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -1621,7 +1649,7 @@ 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(8); assertTrue(f.cancel(true)); @@ -1636,7 +1664,7 @@ 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 n = new LCCF(8); CCF f = new LCCF(n, 8); @@ -1652,7 +1680,7 @@ 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(8); CCF g = new LCCF(9); @@ -1669,7 +1697,7 @@ 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(8); invokeAll(f); @@ -1683,7 +1711,7 @@ 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(8); CCF g = new LCCF(9); @@ -1703,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(8); CCF g = new LCCF(9); CCF h = new LCCF(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -1727,7 +1755,7 @@ 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(8); CCF g = new LCCF(9); @@ -1744,7 +1772,7 @@ 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(8); FailingCCF g = new LFCCF(9); @@ -1762,7 +1790,7 @@ 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(9); try { @@ -1779,7 +1807,7 @@ 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(8); FailingCCF g = new LFCCF(9); @@ -1795,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(8); CCF g = new LCCF(9); CCF h = new LCCF(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h);