--- jsr166/src/test/tck/ForkJoinTaskTest.java 2010/10/24 13:41:17 1.20 +++ jsr166/src/test/tck/ForkJoinTaskTest.java 2010/11/22 22:45:49 1.28 @@ -10,8 +10,10 @@ import java.util.concurrent.ForkJoinTask 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.*; @@ -26,7 +28,7 @@ public class ForkJoinTaskTest extends JS } // Runs with "mainPool" use > 1 thread. singletonPool tests use 1 - static final int mainPoolSize = + static final int mainPoolSize = Math.max(2, Runtime.getRuntime().availableProcessors()); private static ForkJoinPool mainPool() { @@ -50,6 +52,7 @@ public class ForkJoinTaskTest extends JS assertFalse(a.isCompletedAbnormally()); assertFalse(a.isCancelled()); assertNull(a.getException()); + assertNull(a.getRawResult()); assertNull(pool.invoke(a)); @@ -58,11 +61,142 @@ public class ForkJoinTaskTest extends JS assertFalse(a.isCompletedAbnormally()); assertFalse(a.isCancelled()); assertNull(a.getException()); + assertNull(a.getRawResult()); } finally { joinPool(pool); } } + void checkNotDone(ForkJoinTask a) { + assertFalse(a.isDone()); + assertFalse(a.isCompletedNormally()); + assertFalse(a.isCompletedAbnormally()); + assertFalse(a.isCancelled()); + assertNull(a.getException()); + assertNull(a.getRawResult()); + + try { + a.get(0L, SECONDS); + shouldThrow(); + } catch (TimeoutException success) { + } catch (Throwable fail) { threadUnexpectedException(fail); } + } + + void checkCompletedNormally(ForkJoinTask a) { + checkCompletedNormally(a, null); + } + + void checkCompletedNormally(ForkJoinTask a, T expected) { + assertTrue(a.isDone()); + assertFalse(a.isCancelled()); + assertTrue(a.isCompletedNormally()); + assertFalse(a.isCompletedAbnormally()); + assertNull(a.getException()); + assertSame(expected, a.getRawResult()); + + { + Thread.currentThread().interrupt(); + long t0 = System.nanoTime(); + assertSame(expected, a.join()); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(Thread.interrupted()); + } + + { + Thread.currentThread().interrupt(); + long t0 = System.nanoTime(); + a.quietlyJoin(); // should be no-op + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(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); } + } + + void checkCancelled(ForkJoinTask a) { + assertTrue(a.isDone()); + assertTrue(a.isCancelled()); + assertFalse(a.isCompletedNormally()); + assertTrue(a.isCompletedAbnormally()); + assertTrue(a.getException() instanceof CancellationException); + assertNull(a.getRawResult()); + assertTrue(a.cancel(false)); + assertTrue(a.cancel(true)); + + try { + Thread.currentThread().interrupt(); + a.join(); + shouldThrow(); + } catch (CancellationException success) { + assertTrue(Thread.interrupted()); + } catch (Throwable fail) { threadUnexpectedException(fail); } + + { + long t0 = System.nanoTime(); + a.quietlyJoin(); // should be no-op + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + } + + try { + a.get(); + shouldThrow(); + } catch (CancellationException success) { + } catch (Throwable fail) { threadUnexpectedException(fail); } + + try { + a.get(5L, SECONDS); + shouldThrow(); + } catch (CancellationException success) { + } catch (Throwable fail) { threadUnexpectedException(fail); } + } + + void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { + assertTrue(a.isDone()); + assertFalse(a.isCancelled()); + assertFalse(a.isCompletedNormally()); + assertTrue(a.isCompletedAbnormally()); + assertSame(t, a.getException()); + assertNull(a.getRawResult()); + assertFalse(a.cancel(false)); + assertFalse(a.cancel(true)); + + try { + Thread.currentThread().interrupt(); + a.join(); + shouldThrow(); + } catch (Throwable expected) { + assertTrue(Thread.interrupted()); + assertSame(t, expected); + } + + { + long t0 = System.nanoTime(); + a.quietlyJoin(); // should be no-op + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + } + + try { + a.get(); + shouldThrow(); + } catch (ExecutionException success) { + assertSame(t, success.getCause()); + } catch (Throwable fail) { threadUnexpectedException(fail); } + + try { + a.get(5L, SECONDS); + shouldThrow(); + } catch (ExecutionException success) { + assertSame(t, success.getCause()); + } catch (Throwable fail) { threadUnexpectedException(fail); } + } + /* * Testing coverage notes: * @@ -247,7 +381,7 @@ public class ForkJoinTaskTest extends JS /** * invoke returns when task completes normally. * isCompletedAbnormally and isCancelled return false for normally - * completed tasks. getRawResult of a RecursiveAction returns null; + * completed tasks; getRawResult returns null. */ public void testInvoke() { RecursiveAction a = new CheckedRecursiveAction() { @@ -255,10 +389,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); assertNull(f.invoke()); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertFalse(f.isCancelled()); - assertFalse(f.isCompletedAbnormally()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -274,10 +405,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); f.quietlyInvoke(); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertFalse(f.isCancelled()); - assertFalse(f.isCompletedAbnormally()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -292,8 +420,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -308,7 +435,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -323,7 +450,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -354,7 +481,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -371,8 +498,8 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); f.helpQuiesce(); assertEquals(21, f.number); - assertTrue(f.isDone()); assertEquals(0, getQueuedTaskCount()); + checkCompletedNormally(f); }}; testInvokeOnPool(mainPool(), a); } @@ -388,7 +515,9 @@ public class ForkJoinTaskTest extends JS try { f.invoke(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -401,7 +530,8 @@ public class ForkJoinTaskTest extends JS public void realCompute() { FailingAsyncFib f = new FailingAsyncFib(8); f.quietlyInvoke(); - assertTrue(f.isDone()); + assertTrue(f.getException() instanceof FJException); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(mainPool(), a); } @@ -417,7 +547,9 @@ public class ForkJoinTaskTest extends JS try { f.join(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -436,9 +568,7 @@ public class ForkJoinTaskTest extends JS } catch (ExecutionException success) { Throwable cause = success.getCause(); assertTrue(cause instanceof FJException); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertSame(cause, f.getException()); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(mainPool(), a); @@ -458,9 +588,7 @@ public class ForkJoinTaskTest extends JS } catch (ExecutionException success) { Throwable cause = success.getCause(); assertTrue(cause instanceof FJException); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertSame(cause, f.getException()); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(mainPool(), a); @@ -475,9 +603,8 @@ public class ForkJoinTaskTest extends JS FailingAsyncFib f = new FailingAsyncFib(8); assertSame(f, f.fork()); f.quietlyJoin(); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); assertTrue(f.getException() instanceof FJException); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(mainPool(), a); } @@ -494,10 +621,7 @@ public class ForkJoinTaskTest extends JS f.invoke(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(mainPool(), a); @@ -516,10 +640,7 @@ public class ForkJoinTaskTest extends JS f.join(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(mainPool(), a); @@ -538,10 +659,7 @@ public class ForkJoinTaskTest extends JS f.get(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(mainPool(), a); @@ -560,10 +678,7 @@ public class ForkJoinTaskTest extends JS f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(mainPool(), a); @@ -579,10 +694,7 @@ public class ForkJoinTaskTest extends JS assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.isCancelled()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); }}; testInvokeOnPool(mainPool(), a); } @@ -627,7 +739,7 @@ public class ForkJoinTaskTest extends JS public void testInForkJoinPool2() { RecursiveAction a = new CheckedRecursiveAction() { public void realCompute() { - assertTrue(!inForkJoinPool()); + assertFalse(inForkJoinPool()); }}; assertNull(a.invoke()); } @@ -639,6 +751,7 @@ public class ForkJoinTaskTest extends JS RecursiveAction a = new CheckedRecursiveAction() { public void realCompute() { setRawResult(null); + assertNull(getRawResult()); }}; assertNull(a.invoke()); } @@ -654,7 +767,9 @@ public class ForkJoinTaskTest extends JS try { f.invoke(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -668,10 +783,10 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); AsyncFib g = new AsyncFib(9); invokeAll(f, g); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); + checkCompletedNormally(f); + checkCompletedNormally(g); }}; testInvokeOnPool(mainPool(), a); } @@ -684,7 +799,7 @@ public class ForkJoinTaskTest extends JS public void realCompute() { AsyncFib f = new AsyncFib(8); invokeAll(f); - assertTrue(f.isDone()); + checkCompletedNormally(f); assertEquals(21, f.number); }}; testInvokeOnPool(mainPool(), a); @@ -700,12 +815,12 @@ public class ForkJoinTaskTest extends JS AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); invokeAll(f, g, h); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); - assertTrue(h.isDone()); assertEquals(13, h.number); + checkCompletedNormally(f); + checkCompletedNormally(g); + checkCompletedNormally(h); }}; testInvokeOnPool(mainPool(), a); } @@ -724,12 +839,12 @@ public class ForkJoinTaskTest extends JS set.add(g); set.add(h); invokeAll(set); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); - assertTrue(h.isDone()); assertEquals(13, h.number); + checkCompletedNormally(f); + checkCompletedNormally(g); + checkCompletedNormally(h); }}; testInvokeOnPool(mainPool(), a); } @@ -763,7 +878,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(f, g); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -778,7 +895,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(g); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -795,7 +914,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(f, g, h); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -816,7 +937,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(set); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(mainPool(), a); } @@ -834,8 +957,8 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertTrue(f.tryUnfork()); helpQuiesce(); - assertFalse(f.isDone()); - assertTrue(g.isDone()); + checkNotDone(f); + checkCompletedNormally(g); }}; testInvokeOnPool(singletonPool(), a); } @@ -855,6 +978,10 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertTrue(getSurplusQueuedTaskCount() > 0); helpQuiesce(); + assertEquals(0, getSurplusQueuedTaskCount()); + checkCompletedNormally(f); + checkCompletedNormally(g); + checkCompletedNormally(h); }}; testInvokeOnPool(singletonPool(), a); } @@ -871,15 +998,16 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertSame(f, peekNextLocalTask()); assertNull(f.join()); - assertTrue(f.isDone()); + checkCompletedNormally(f); helpQuiesce(); + checkCompletedNormally(g); }}; testInvokeOnPool(singletonPool(), a); } /** - * pollNextLocalTask returns most recent unexecuted task - * without executing it + * pollNextLocalTask returns most recent unexecuted task without + * executing it */ public void testPollNextLocalTask() { RecursiveAction a = new CheckedRecursiveAction() { @@ -890,14 +1018,15 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertSame(f, pollNextLocalTask()); helpQuiesce(); - assertFalse(f.isDone()); + checkNotDone(f); + assertEquals(34, g.number); + checkCompletedNormally(g); }}; testInvokeOnPool(singletonPool(), a); } /** - * pollTask returns an unexecuted task - * without executing it + * pollTask returns an unexecuted task without executing it */ public void testPollTask() { RecursiveAction a = new CheckedRecursiveAction() { @@ -908,8 +1037,8 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertSame(f, pollTask()); helpQuiesce(); - assertFalse(f.isDone()); - assertTrue(g.isDone()); + checkNotDone(f); + checkCompletedNormally(g); }}; testInvokeOnPool(singletonPool(), a); } @@ -927,14 +1056,16 @@ public class ForkJoinTaskTest extends JS assertSame(g, peekNextLocalTask()); assertNull(f.join()); helpQuiesce(); - assertTrue(f.isDone()); + checkCompletedNormally(f); + assertEquals(34, g.number); + checkCompletedNormally(g); }}; testInvokeOnPool(asyncSingletonPool(), a); } /** - * pollNextLocalTask returns least recent unexecuted task - * without executing it, in async mode + * pollNextLocalTask returns least recent unexecuted task without + * executing it, in async mode */ public void testPollNextLocalTaskAsync() { RecursiveAction a = new CheckedRecursiveAction() { @@ -945,15 +1076,16 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertSame(g, pollNextLocalTask()); helpQuiesce(); - assertTrue(f.isDone()); - assertFalse(g.isDone()); + assertEquals(21, f.number); + checkCompletedNormally(f); + checkNotDone(g); }}; testInvokeOnPool(asyncSingletonPool(), a); } /** - * pollTask returns an unexecuted task - * without executing it, in async mode + * pollTask returns an unexecuted task without executing it, in + * async mode */ public void testPollTaskAsync() { RecursiveAction a = new CheckedRecursiveAction() { @@ -964,8 +1096,9 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertSame(g, pollTask()); helpQuiesce(); - assertTrue(f.isDone()); - assertFalse(g.isDone()); + assertEquals(21, f.number); + checkCompletedNormally(f); + checkNotDone(g); }}; testInvokeOnPool(asyncSingletonPool(), a); } @@ -975,7 +1108,7 @@ public class ForkJoinTaskTest extends JS /** * invoke returns when task completes normally. * isCompletedAbnormally and isCancelled return false for normally - * completed tasks. getRawResult of a RecursiveAction returns null; + * completed tasks; getRawResult returns null. */ public void testInvokeSingleton() { RecursiveAction a = new CheckedRecursiveAction() { @@ -983,10 +1116,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); assertNull(f.invoke()); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertFalse(f.isCancelled()); - assertFalse(f.isCompletedAbnormally()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1002,10 +1132,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); f.quietlyInvoke(); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertFalse(f.isCancelled()); - assertFalse(f.isCompletedAbnormally()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1020,8 +1147,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.join()); assertEquals(21, f.number); - assertTrue(f.isDone()); - assertNull(f.getRawResult()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1036,7 +1162,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.get()); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1051,7 +1177,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1082,7 +1208,7 @@ public class ForkJoinTaskTest extends JS assertSame(f, f.fork()); f.quietlyJoin(); assertEquals(21, f.number); - assertTrue(f.isDone()); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1098,9 +1224,9 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); f.helpQuiesce(); - assertEquals(21, f.number); - assertTrue(f.isDone()); assertEquals(0, getQueuedTaskCount()); + assertEquals(21, f.number); + checkCompletedNormally(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1116,7 +1242,9 @@ public class ForkJoinTaskTest extends JS try { f.invoke(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1129,7 +1257,8 @@ public class ForkJoinTaskTest extends JS public void realCompute() { FailingAsyncFib f = new FailingAsyncFib(8); f.quietlyInvoke(); - assertTrue(f.isDone()); + assertTrue(f.getException() instanceof FJException); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(singletonPool(), a); } @@ -1145,7 +1274,9 @@ public class ForkJoinTaskTest extends JS try { f.join(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1164,9 +1295,7 @@ public class ForkJoinTaskTest extends JS } catch (ExecutionException success) { Throwable cause = success.getCause(); assertTrue(cause instanceof FJException); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertSame(cause, f.getException()); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(singletonPool(), a); @@ -1186,9 +1315,7 @@ public class ForkJoinTaskTest extends JS } catch (ExecutionException success) { Throwable cause = success.getCause(); assertTrue(cause instanceof FJException); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertSame(cause, f.getException()); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(singletonPool(), a); @@ -1203,9 +1330,8 @@ public class ForkJoinTaskTest extends JS FailingAsyncFib f = new FailingAsyncFib(8); assertSame(f, f.fork()); f.quietlyJoin(); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); assertTrue(f.getException() instanceof FJException); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(singletonPool(), a); } @@ -1222,10 +1348,7 @@ public class ForkJoinTaskTest extends JS f.invoke(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(singletonPool(), a); @@ -1244,10 +1367,7 @@ public class ForkJoinTaskTest extends JS f.join(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(singletonPool(), a); @@ -1266,10 +1386,7 @@ public class ForkJoinTaskTest extends JS f.get(); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(singletonPool(), a); @@ -1288,10 +1405,7 @@ public class ForkJoinTaskTest extends JS f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (CancellationException success) { - assertTrue(f.isDone()); - assertTrue(f.isCancelled()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); } }}; testInvokeOnPool(singletonPool(), a); @@ -1307,10 +1421,7 @@ public class ForkJoinTaskTest extends JS assertTrue(f.cancel(true)); assertSame(f, f.fork()); f.quietlyJoin(); - assertTrue(f.isDone()); - assertTrue(f.isCompletedAbnormally()); - assertTrue(f.isCancelled()); - assertTrue(f.getException() instanceof CancellationException); + checkCancelled(f); }}; testInvokeOnPool(singletonPool(), a); } @@ -1326,7 +1437,9 @@ public class ForkJoinTaskTest extends JS try { f.invoke(); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1340,10 +1453,10 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); AsyncFib g = new AsyncFib(9); invokeAll(f, g); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); + checkCompletedNormally(f); + checkCompletedNormally(g); }}; testInvokeOnPool(singletonPool(), a); } @@ -1356,7 +1469,7 @@ public class ForkJoinTaskTest extends JS public void realCompute() { AsyncFib f = new AsyncFib(8); invokeAll(f); - assertTrue(f.isDone()); + checkCompletedNormally(f); assertEquals(21, f.number); }}; testInvokeOnPool(singletonPool(), a); @@ -1372,12 +1485,12 @@ public class ForkJoinTaskTest extends JS AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); invokeAll(f, g, h); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); - assertTrue(h.isDone()); assertEquals(13, h.number); + checkCompletedNormally(f); + checkCompletedNormally(g); + checkCompletedNormally(h); }}; testInvokeOnPool(singletonPool(), a); } @@ -1396,12 +1509,12 @@ public class ForkJoinTaskTest extends JS set.add(g); set.add(h); invokeAll(set); - assertTrue(f.isDone()); assertEquals(21, f.number); - assertTrue(g.isDone()); assertEquals(34, g.number); - assertTrue(h.isDone()); assertEquals(13, h.number); + checkCompletedNormally(f); + checkCompletedNormally(g); + checkCompletedNormally(h); }}; testInvokeOnPool(singletonPool(), a); } @@ -1435,7 +1548,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(f, g); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1450,7 +1565,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(g); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1467,7 +1584,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(f, g, h); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(g, success); + } }}; testInvokeOnPool(singletonPool(), a); } @@ -1488,7 +1607,9 @@ public class ForkJoinTaskTest extends JS try { invokeAll(set); shouldThrow(); - } catch (FJException success) {} + } catch (FJException success) { + checkCompletedAbnormally(f, success); + } }}; testInvokeOnPool(singletonPool(), a); }