--- jsr166/src/test/tck/ForkJoinTaskTest.java 2010/11/22 07:40:24 1.26 +++ jsr166/src/test/tck/ForkJoinTaskTest.java 2011/05/27 19:42:42 1.33 @@ -1,7 +1,7 @@ /* * 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 java.util.concurrent.ExecutionException; import java.util.concurrent.CancellationException; @@ -93,7 +93,23 @@ public class ForkJoinTaskTest extends JS assertFalse(a.isCompletedAbnormally()); assertNull(a.getException()); assertSame(expected, a.getRawResult()); - assertSame(expected, a.join()); + + { + Thread.currentThread().interrupt(); + long t0 = System.nanoTime(); + assertSame(expected, a.join()); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + Thread.interrupted(); + } + + { + Thread.currentThread().interrupt(); + long t0 = System.nanoTime(); + a.quietlyJoin(); // should be no-op + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + Thread.interrupted(); + } + assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); try { @@ -115,10 +131,18 @@ public class ForkJoinTaskTest extends JS assertTrue(a.cancel(true)); try { + Thread.currentThread().interrupt(); a.join(); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } + Thread.interrupted(); + + { + long t0 = System.nanoTime(); + a.quietlyJoin(); // should be no-op + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + } try { a.get(); @@ -138,30 +162,38 @@ public class ForkJoinTaskTest extends JS 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 { + Thread.currentThread().interrupt(); a.join(); shouldThrow(); } catch (Throwable expected) { - assertSame(t, expected); + assertSame(t.getClass(), expected.getClass()); + } + Thread.interrupted(); + + { + 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()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } try { a.get(5L, SECONDS); shouldThrow(); } catch (ExecutionException success) { - assertSame(t, success.getCause()); + assertSame(t.getClass(), success.getCause().getClass()); } catch (Throwable fail) { threadUnexpectedException(fail); } } @@ -173,7 +205,7 @@ public class ForkJoinTaskTest extends JS * differently than supplied Recursive forms. */ - static final class FJException extends RuntimeException { + public static final class FJException extends RuntimeException { FJException() { super(); } } @@ -317,7 +349,6 @@ public class ForkJoinTaskTest extends JS } } - static final class FailingAsyncFib extends BinaryAsyncAction { int number; public FailingAsyncFib(int n) { @@ -454,7 +485,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(mainPool(), a); } - /** * helpQuiesce returns when tasks are complete. * getQueuedTaskCount returns 0 when quiescent @@ -464,7 +494,7 @@ public class ForkJoinTaskTest extends JS public void realCompute() { AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); - f.helpQuiesce(); + helpQuiesce(); assertEquals(21, f.number); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -472,7 +502,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(mainPool(), a); } - /** * invoke task throws exception when task completes abnormally */ @@ -719,6 +748,7 @@ public class ForkJoinTaskTest extends JS RecursiveAction a = new CheckedRecursiveAction() { public void realCompute() { setRawResult(null); + assertNull(getRawResult()); }}; assertNull(a.invoke()); } @@ -816,7 +846,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(mainPool(), a); } - /** * invokeAll(tasks) with any null task throws NPE */ @@ -1180,7 +1209,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(singletonPool(), a); } - /** * helpQuiesce returns when tasks are complete. * getQueuedTaskCount returns 0 when quiescent @@ -1190,7 +1218,7 @@ public class ForkJoinTaskTest extends JS public void realCompute() { AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); - f.helpQuiesce(); + helpQuiesce(); assertEquals(0, getQueuedTaskCount()); assertEquals(21, f.number); checkCompletedNormally(f); @@ -1198,7 +1226,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(singletonPool(), a); } - /** * invoke task throws exception when task completes abnormally */ @@ -1486,7 +1513,6 @@ public class ForkJoinTaskTest extends JS testInvokeOnPool(singletonPool(), a); } - /** * invokeAll(tasks) with any null task throws NPE */