--- jsr166/src/test/tck/RecursiveActionTest.java 2010/11/21 08:25:10 1.19 +++ jsr166/src/test/tck/RecursiveActionTest.java 2010/11/22 20:19:47 1.24 @@ -90,6 +90,8 @@ public class RecursiveActionTest extends assertNull(a.getException()); assertNull(a.getRawResult()); assertNull(a.join()); + assertFalse(a.cancel(false)); + assertFalse(a.cancel(true)); try { assertNull(a.get()); } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -125,13 +127,15 @@ public class RecursiveActionTest extends } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkTaskThrew(RecursiveAction a, Throwable t) { + void checkCompletedAbnormally(RecursiveAction 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 { a.join(); @@ -243,6 +247,76 @@ public class RecursiveActionTest extends } /** + * join/quietlyJoin of a forked task ignores interrupts + */ + public void testJoinIgnoresInterrupts() { + RecursiveAction a = new CheckedRecursiveAction() { + public void realCompute() { + FibAction f = new FibAction(8); + + // test join() + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + assertNull(f.join()); + assertTrue(Thread.interrupted()); + assertEquals(21, f.result); + checkCompletedNormally(f); + + f.reinitialize(); + f.cancel(true); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + try { + f.join(); + shouldThrow(); + } catch (CancellationException success) { + assertTrue(Thread.interrupted()); + checkCancelled(f); + } + + f.reinitialize(); + f.completeExceptionally(new FJException()); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + try { + f.join(); + shouldThrow(); + } catch (FJException success) { + assertTrue(Thread.interrupted()); + checkCompletedAbnormally(f, success); + } + + // test quietlyJoin() + f.reinitialize(); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + assertTrue(Thread.interrupted()); + assertEquals(21, f.result); + checkCompletedNormally(f); + + f.reinitialize(); + f.cancel(true); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + assertTrue(Thread.interrupted()); + checkCancelled(f); + + f.reinitialize(); + f.completeExceptionally(new FJException()); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + assertTrue(Thread.interrupted()); + checkCompletedAbnormally(f, f.getException()); + }}; + testInvokeOnPool(mainPool(), a); + a.reinitialize(); + testInvokeOnPool(singletonPool(), a); + } + + /** * get of a forked task returns when task completes */ public void testForkGet() { @@ -333,7 +407,7 @@ public class RecursiveActionTest extends f.invoke(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } }}; testInvokeOnPool(mainPool(), a); @@ -348,7 +422,7 @@ public class RecursiveActionTest extends FailingFibAction f = new FailingFibAction(8); f.quietlyInvoke(); assertTrue(f.getException() instanceof FJException); - checkTaskThrew(f, f.getException()); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(mainPool(), a); } @@ -365,7 +439,7 @@ public class RecursiveActionTest extends f.join(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } }}; testInvokeOnPool(mainPool(), a); @@ -383,7 +457,9 @@ public class RecursiveActionTest extends f.get(); shouldThrow(); } catch (ExecutionException success) { - checkTaskThrew(f, success.getCause()); + Throwable cause = success.getCause(); + assertTrue(cause instanceof FJException); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(mainPool(), a); @@ -401,7 +477,9 @@ public class RecursiveActionTest extends f.get(5L, TimeUnit.SECONDS); shouldThrow(); } catch (ExecutionException success) { - checkTaskThrew(f, success.getCause()); + Throwable cause = success.getCause(); + assertTrue(cause instanceof FJException); + checkCompletedAbnormally(f, cause); } }}; testInvokeOnPool(mainPool(), a); @@ -417,7 +495,7 @@ public class RecursiveActionTest extends assertSame(f, f.fork()); f.quietlyJoin(); assertTrue(f.getException() instanceof FJException); - checkTaskThrew(f, f.getException()); + checkCompletedAbnormally(f, f.getException()); }}; testInvokeOnPool(mainPool(), a); } @@ -594,6 +672,7 @@ public class RecursiveActionTest extends RecursiveAction a = new CheckedRecursiveAction() { public void realCompute() { setRawResult(null); + assertNull(getRawResult()); }}; assertNull(a.invoke()); } @@ -630,7 +709,7 @@ public class RecursiveActionTest extends f.invoke(); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } }}; testInvokeOnPool(mainPool(), a); @@ -692,6 +771,9 @@ public class RecursiveActionTest extends FibAction g = new FibAction(9); FibAction h = new FibAction(7); invokeAll(f, g, h); + assertTrue(f.isDone()); + assertTrue(g.isDone()); + assertTrue(h.isDone()); checkCompletedNormally(f); assertEquals(21, f.result); checkCompletedNormally(g); @@ -716,6 +798,9 @@ public class RecursiveActionTest extends set.add(g); set.add(h); invokeAll(set); + assertTrue(f.isDone()); + assertTrue(g.isDone()); + assertTrue(h.isDone()); checkCompletedNormally(f); assertEquals(21, f.result); checkCompletedNormally(g); @@ -756,7 +841,7 @@ public class RecursiveActionTest extends invokeAll(f, g); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } }}; testInvokeOnPool(mainPool(), a); @@ -773,7 +858,7 @@ public class RecursiveActionTest extends invokeAll(g); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } }}; testInvokeOnPool(mainPool(), a); @@ -792,7 +877,7 @@ public class RecursiveActionTest extends invokeAll(f, g, h); shouldThrow(); } catch (FJException success) { - checkTaskThrew(g, success); + checkCompletedAbnormally(g, success); } }}; testInvokeOnPool(mainPool(), a); @@ -815,7 +900,7 @@ public class RecursiveActionTest extends invokeAll(set); shouldThrow(); } catch (FJException success) { - checkTaskThrew(f, success); + checkCompletedAbnormally(f, success); } }}; testInvokeOnPool(mainPool(), a); @@ -855,6 +940,7 @@ public class RecursiveActionTest extends assertSame(f, f.fork()); assertTrue(getSurplusQueuedTaskCount() > 0); helpQuiesce(); + assertEquals(0, getSurplusQueuedTaskCount()); checkCompletedNormally(f); checkCompletedNormally(g); checkCompletedNormally(h);