--- jsr166/src/test/tck/RecursiveTaskTest.java 2010/11/21 08:25:10 1.20 +++ jsr166/src/test/tck/RecursiveTaskTest.java 2021/01/27 01:57:24 1.43 @@ -1,24 +1,26 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +import java.util.HashSet; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; -import java.util.concurrent.ForkJoinWorkerThread; +import java.util.concurrent.ForkJoinTask; import java.util.concurrent.RecursiveTask; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static java.util.concurrent.TimeUnit.SECONDS; -import java.util.HashSet; + +import junit.framework.Test; +import junit.framework.TestSuite; public class RecursiveTaskTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(RecursiveTaskTest.class); @@ -39,19 +41,17 @@ public class RecursiveTaskTest extends J } private T testInvokeOnPool(ForkJoinPool pool, RecursiveTask a) { - try { + try (PoolCleaner cleaner = cleaner(pool)) { checkNotDone(a); T result = pool.invoke(a); checkCompletedNormally(a, result); return result; - } finally { - joinPool(pool); } } - void checkNotDone(RecursiveTask a) { + void checkNotDone(RecursiveTask a) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -59,7 +59,7 @@ public class RecursiveTaskTest extends J assertNull(a.getException()); assertNull(a.getRawResult()); - if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) { + if (! ForkJoinTask.inForkJoinPool()) { Thread.currentThread().interrupt(); try { a.get(); @@ -69,42 +69,46 @@ public class RecursiveTaskTest extends J Thread.currentThread().interrupt(); try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkCompletedNormally(RecursiveTask a, T expected) { + void checkCompletedNormally(RecursiveTask a, T expectedValue) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertTrue(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); assertNull(a.getException()); - assertSame(expected, a.getRawResult()); - assertSame(expected, a.join()); - try { - assertSame(expected, a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } + assertSame(expectedValue, a.getRawResult()); + assertSame(expectedValue, a.join()); + assertFalse(a.cancel(false)); + assertFalse(a.cancel(true)); + + T v1 = null, v2 = null; try { - assertSame(expected, a.get(5L, SECONDS)); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertSame(expectedValue, v1); + assertSame(expectedValue, v2); } /** * Waits for the task to complete, and checks that when it does, * it will have an Integer result equals to the given int. */ - void checkCompletesNormally(RecursiveTask a, int expected) { + void checkCompletesNormally(RecursiveTask a, int expectedValue) { Integer r = a.join(); - assertEquals(expected, (int) r); + assertEquals(expectedValue, (int) r); checkCompletedNormally(a, r); } @@ -112,13 +116,13 @@ public class RecursiveTaskTest extends J * Like checkCompletesNormally, but verifies that the task has * already completed. */ - void checkCompletedNormally(RecursiveTask a, int expected) { + void checkCompletedNormally(RecursiveTask a, int expectedValue) { Integer r = a.getRawResult(); - assertEquals(expected, (int) r); + assertEquals(expectedValue, (int) r); checkCompletedNormally(a, r); } - void checkCancelled(RecursiveTask a) { + void checkCancelled(RecursiveTask a) { assertTrue(a.isDone()); assertTrue(a.isCancelled()); assertFalse(a.isCompletedNormally()); @@ -139,50 +143,52 @@ public class RecursiveTaskTest extends J } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkTaskThrew(RecursiveTask a, Throwable t) { + void checkCompletedAbnormally(RecursiveTask a, Throwable t) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertFalse(a.isCompletedNormally()); assertTrue(a.isCompletedAbnormally()); - assertSame(t, a.getException()); + assertSame(t.getClass(), a.getException().getClass()); assertNull(a.getRawResult()); + assertFalse(a.cancel(false)); + assertFalse(a.cancel(true)); try { a.join(); shouldThrow(); } catch (Throwable expected) { - assertSame(t, expected); + assertSame(t.getClass(), expected.getClass()); } try { a.get(); shouldThrow(); } catch (ExecutionException success) { - assertSame(t, success.getCause()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (ExecutionException success) { - assertSame(t, success.getCause()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } } - static final class FJException extends RuntimeException { - FJException() { super(); } + public static final class FJException extends RuntimeException { + public FJException() { super(); } } - // An invalid return value for Fib + /** An invalid return value for Fib. */ static final Integer NoResult = Integer.valueOf(-17); - // A simple recursive task for testing + /** A simple recursive task for testing. */ final class FibTask extends CheckedRecursiveTask { final int number; FibTask(int n) { number = n; } @@ -192,7 +198,7 @@ public class RecursiveTaskTest extends J return n; FibTask f1 = new FibTask(n - 1); f1.fork(); - return (new FibTask(n - 2)).compute() + f1.join(); + return new FibTask(n - 2).compute() + f1.join(); } public void publicSetRawResult(Integer result) { @@ -200,7 +206,7 @@ public class RecursiveTaskTest extends J } } - // A recursive action failing in base case + /** A recursive action failing in base case. */ final class FailingFibTask extends RecursiveTask { final int number; int result; @@ -211,7 +217,7 @@ public class RecursiveTaskTest extends J throw new FJException(); FailingFibTask f1 = new FailingFibTask(n - 1); f1.fork(); - return (new FibTask(n - 2)).compute() + f1.join(); + return new FibTask(n - 2).compute() + f1.join(); } } @@ -222,7 +228,7 @@ public class RecursiveTaskTest extends J * returns value; */ public void testInvoke() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); Integer r = f.invoke(); @@ -239,7 +245,7 @@ public class RecursiveTaskTest extends J * completed tasks */ public void testQuietlyInvoke() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); f.quietlyInvoke(); @@ -253,7 +259,7 @@ public class RecursiveTaskTest extends J * join of a forked task returns when task completes */ public void testForkJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertSame(f, f.fork()); @@ -269,7 +275,7 @@ public class RecursiveTaskTest extends J * get of a forked task returns when task completes */ public void testForkGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FibTask f = new FibTask(8); assertSame(f, f.fork()); @@ -285,11 +291,11 @@ public class RecursiveTaskTest extends J * timed get of a forked task returns when task completes */ public void testForkTimedGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FibTask f = new FibTask(8); assertSame(f, f.fork()); - Integer r = f.get(5L, SECONDS); + Integer r = f.get(LONG_DELAY_MS, MILLISECONDS); assertEquals(21, (int) r); checkCompletedNormally(f, r); return r; @@ -301,7 +307,7 @@ public class RecursiveTaskTest extends J * quietlyJoin of a forked task returns when task completes */ public void testForkQuietlyJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertSame(f, f.fork()); @@ -314,17 +320,18 @@ public class RecursiveTaskTest extends J assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); } - /** * helpQuiesce returns when tasks are complete. * getQueuedTaskCount returns 0 when quiescent */ public void testForkHelpQuiesce() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertSame(f, f.fork()); - f.helpQuiesce(); + helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f, 21); return NoResult; @@ -332,19 +339,18 @@ public class RecursiveTaskTest extends J assertSame(NoResult, testInvokeOnPool(mainPool(), a)); } - /** * invoke task throws exception when task completes abnormally */ public void testAbnormalInvoke() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); try { f.invoke(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } return NoResult; }}; @@ -355,12 +361,12 @@ public class RecursiveTaskTest extends J * quietlyInvoke task returns when task completes abnormally */ public void testAbnormalQuietlyInvoke() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); - checkTaskThrew(f, f.getException()); + checkCompletedAbnormally(f, f.getException()); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); @@ -370,15 +376,15 @@ public class RecursiveTaskTest extends J * join of a forked task throws exception when task completes abnormally */ public void testAbnormalForkJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); assertSame(f, f.fork()); try { - Integer r = f.join(); + f.join(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } return NoResult; }}; @@ -389,15 +395,17 @@ public class RecursiveTaskTest extends J * get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FailingFibTask f = new FailingFibTask(8); assertSame(f, f.fork()); try { - Integer r = f.get(); + f.get(); shouldThrow(); } catch (ExecutionException success) { - checkTaskThrew(f, success.getCause()); + Throwable cause = success.getCause(); + assertTrue(cause instanceof FJException); + checkCompletedAbnormally(f, cause); } return NoResult; }}; @@ -408,15 +416,17 @@ public class RecursiveTaskTest extends J * timed get of a forked task throws exception when task completes abnormally */ public void testAbnormalForkTimedGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FailingFibTask f = new FailingFibTask(8); assertSame(f, f.fork()); try { - Integer r = f.get(5L, SECONDS); + f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { - checkTaskThrew(f, success.getCause()); + Throwable cause = success.getCause(); + assertTrue(cause instanceof FJException); + checkCompletedAbnormally(f, cause); } return NoResult; }}; @@ -427,13 +437,13 @@ public class RecursiveTaskTest extends J * quietlyJoin of a forked task returns when task completes abnormally */ public void testAbnormalForkQuietlyJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); - checkTaskThrew(f, f.getException()); + checkCompletedAbnormally(f, f.getException()); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); @@ -443,12 +453,12 @@ public class RecursiveTaskTest extends J * invoke task throws exception when task cancelled */ public void testCancelledInvoke() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertTrue(f.cancel(true)); try { - Integer r = f.invoke(); + f.invoke(); shouldThrow(); } catch (CancellationException success) { checkCancelled(f); @@ -462,13 +472,13 @@ public class RecursiveTaskTest extends J * join of a forked task throws exception when task cancelled */ public void testCancelledForkJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { - Integer r = f.join(); + f.join(); shouldThrow(); } catch (CancellationException success) { checkCancelled(f); @@ -482,13 +492,13 @@ public class RecursiveTaskTest extends J * get of a forked task throws exception when task cancelled */ public void testCancelledForkGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FibTask f = new FibTask(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { - Integer r = f.get(); + f.get(); shouldThrow(); } catch (CancellationException success) { checkCancelled(f); @@ -502,13 +512,13 @@ public class RecursiveTaskTest extends J * timed get of a forked task throws exception when task cancelled */ public void testCancelledForkTimedGet() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() throws Exception { FibTask f = new FibTask(8); assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { - Integer r = f.get(5L, SECONDS); + f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (CancellationException success) { checkCancelled(f); @@ -522,7 +532,7 @@ public class RecursiveTaskTest extends J * quietlyJoin of a forked task returns when task cancelled */ public void testCancelledForkQuietlyJoin() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); assertTrue(f.cancel(true)); @@ -539,7 +549,7 @@ public class RecursiveTaskTest extends J */ public void testGetPool() { final ForkJoinPool mainPool = mainPool(); - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { assertSame(mainPool, getPool()); return NoResult; @@ -551,7 +561,7 @@ public class RecursiveTaskTest extends J * getPool of non-FJ task returns null */ public void testGetPool2() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { assertNull(getPool()); return NoResult; @@ -563,7 +573,7 @@ public class RecursiveTaskTest extends J * inForkJoinPool of executing task returns true */ public void testInForkJoinPool() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { assertTrue(inForkJoinPool()); return NoResult; @@ -575,9 +585,9 @@ public class RecursiveTaskTest extends J * inForkJoinPool of non-FJ task returns false */ public void testInForkJoinPool2() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { - assertTrue(!inForkJoinPool()); + assertFalse(inForkJoinPool()); return NoResult; }}; assertSame(NoResult, a.invoke()); @@ -587,21 +597,21 @@ public class RecursiveTaskTest extends J * The value set by setRawResult is returned by getRawResult */ public void testSetRawResult() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { setRawResult(NoResult); assertSame(NoResult, getRawResult()); return NoResult; } }; - a.invoke(); + assertSame(NoResult, a.invoke()); } /** * A reinitialized normally completed task may be re-invoked */ public void testReinitialize() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); checkNotDone(f); @@ -623,7 +633,7 @@ public class RecursiveTaskTest extends J * A reinitialized abnormally completed task may be re-invoked */ public void testReinitializeAbnormal() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); checkNotDone(f); @@ -633,7 +643,7 @@ public class RecursiveTaskTest extends J f.invoke(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } f.reinitialize(); checkNotDone(f); @@ -647,15 +657,15 @@ public class RecursiveTaskTest extends J * invoke task throws exception after invoking completeExceptionally */ public void testCompleteExceptionally() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); f.completeExceptionally(new FJException()); try { - Integer r = f.invoke(); + f.invoke(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } return NoResult; }}; @@ -666,7 +676,7 @@ public class RecursiveTaskTest extends J * invoke task suppresses execution invoking complete */ public void testComplete() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); f.complete(NoResult); @@ -682,13 +692,13 @@ public class RecursiveTaskTest extends J * invokeAll(t1, t2) invokes all task arguments */ public void testInvokeAll2() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FibTask g = new FibTask(9); invokeAll(f, g); - checkCompletesNormally(f, 21); - checkCompletesNormally(g, 34); + checkCompletedNormally(f, 21); + checkCompletedNormally(g, 34); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); @@ -698,11 +708,11 @@ public class RecursiveTaskTest extends J * invokeAll(tasks) with 1 argument invokes task */ public void testInvokeAll1() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); invokeAll(f); - checkCompletesNormally(f, 21); + checkCompletedNormally(f, 21); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); @@ -712,15 +722,18 @@ public class RecursiveTaskTest extends J * invokeAll(tasks) with > 2 argument invokes tasks */ public void testInvokeAll3() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FibTask g = new FibTask(9); FibTask h = new FibTask(7); invokeAll(f, g, h); - checkCompletesNormally(f, 21); - checkCompletesNormally(g, 34); - checkCompletesNormally(h, 13); + assertTrue(f.isDone()); + assertTrue(g.isDone()); + assertTrue(h.isDone()); + checkCompletedNormally(f, 21); + checkCompletedNormally(g, 34); + checkCompletedNormally(h, 13); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); @@ -730,30 +743,32 @@ public class RecursiveTaskTest extends J * invokeAll(collection) invokes all tasks in the collection */ public void testInvokeAllCollection() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FibTask g = new FibTask(9); FibTask h = new FibTask(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet<>(); set.add(f); set.add(g); set.add(h); invokeAll(set); - checkCompletesNormally(f, 21); - checkCompletesNormally(g, 34); - checkCompletesNormally(h, 13); + assertTrue(f.isDone()); + assertTrue(g.isDone()); + assertTrue(h.isDone()); + checkCompletedNormally(f, 21); + checkCompletedNormally(g, 34); + checkCompletedNormally(h, 13); return NoResult; }}; assertSame(NoResult, testInvokeOnPool(mainPool(), a)); } - /** * invokeAll(tasks) with any null task throws NPE */ public void testInvokeAllNPE() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FibTask g = new FibTask(9); @@ -771,7 +786,7 @@ public class RecursiveTaskTest extends J * invokeAll(t1, t2) throw exception if any task does */ public void testAbnormalInvokeAll2() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FailingFibTask g = new FailingFibTask(9); @@ -779,7 +794,7 @@ public class RecursiveTaskTest extends J invokeAll(f, g); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } return NoResult; }}; @@ -790,14 +805,14 @@ public class RecursiveTaskTest extends J * invokeAll(tasks) with 1 argument throws exception if task does */ public void testAbnormalInvokeAll1() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask g = new FailingFibTask(9); try { invokeAll(g); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } return NoResult; }}; @@ -808,7 +823,7 @@ public class RecursiveTaskTest extends J * invokeAll(tasks) with > 2 argument throws exception if any task does */ public void testAbnormalInvokeAll3() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask f = new FibTask(8); FailingFibTask g = new FailingFibTask(9); @@ -817,7 +832,7 @@ public class RecursiveTaskTest extends J invokeAll(f, g, h); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } return NoResult; }}; @@ -828,12 +843,12 @@ public class RecursiveTaskTest extends J * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FailingFibTask f = new FailingFibTask(8); FibTask g = new FibTask(9); FibTask h = new FibTask(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet<>(); set.add(f); set.add(g); set.add(h); @@ -841,7 +856,7 @@ public class RecursiveTaskTest extends J invokeAll(set); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } return NoResult; }}; @@ -853,7 +868,7 @@ public class RecursiveTaskTest extends J * and suppresses execution */ public void testTryUnfork() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -873,7 +888,7 @@ public class RecursiveTaskTest extends J * there are more tasks than threads */ public void testGetSurplusQueuedTaskCount() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask h = new FibTask(7); assertSame(h, h.fork()); @@ -883,6 +898,7 @@ public class RecursiveTaskTest extends J assertSame(f, f.fork()); assertTrue(getSurplusQueuedTaskCount() > 0); helpQuiesce(); + assertEquals(0, getSurplusQueuedTaskCount()); checkCompletedNormally(f, 21); checkCompletedNormally(g, 34); checkCompletedNormally(h, 13); @@ -895,7 +911,7 @@ public class RecursiveTaskTest extends J * peekNextLocalTask returns most recent unexecuted task. */ public void testPeekNextLocalTask() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -915,7 +931,7 @@ public class RecursiveTaskTest extends J * without executing it */ public void testPollNextLocalTask() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -934,7 +950,7 @@ public class RecursiveTaskTest extends J * pollTask returns an unexecuted task without executing it */ public void testPollTask() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -953,7 +969,7 @@ public class RecursiveTaskTest extends J * peekNextLocalTask returns least recent unexecuted task in async mode */ public void testPeekNextLocalTaskAsync() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -974,7 +990,7 @@ public class RecursiveTaskTest extends J * executing it, in async mode */ public void testPollNextLocalTaskAsync() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork()); @@ -994,7 +1010,7 @@ public class RecursiveTaskTest extends J * async mode */ public void testPollTaskAsync() { - RecursiveTask a = new CheckedRecursiveTask() { + RecursiveTask a = new CheckedRecursiveTask<>() { public Integer realCompute() { FibTask g = new FibTask(9); assertSame(g, g.fork());