--- jsr166/src/test/tck/RecursiveActionTest.java 2010/11/21 19:06:53 1.21 +++ jsr166/src/test/tck/RecursiveActionTest.java 2010/11/23 06:33:26 1.25 @@ -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); } @@ -132,6 +134,8 @@ public class RecursiveActionTest extends 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 succeeds in the presence of 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()); + 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) { + Thread.interrupted(); + checkCancelled(f); + } + + f.reinitialize(); + f.completeExceptionally(new FJException()); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + try { + f.join(); + shouldThrow(); + } catch (FJException success) { + Thread.interrupted(); + checkCompletedAbnormally(f, success); + } + + // test quietlyJoin() + f.reinitialize(); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + Thread.interrupted(); + assertEquals(21, f.result); + checkCompletedNormally(f); + + f.reinitialize(); + f.cancel(true); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + Thread.interrupted(); + checkCancelled(f); + + f.reinitialize(); + f.completeExceptionally(new FJException()); + assertSame(f, f.fork()); + Thread.currentThread().interrupt(); + f.quietlyJoin(); + 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() { @@ -598,6 +672,7 @@ public class RecursiveActionTest extends RecursiveAction a = new CheckedRecursiveAction() { public void realCompute() { setRawResult(null); + assertNull(getRawResult()); }}; assertNull(a.invoke()); }