--- jsr166/src/test/tck/ForkJoinTask8Test.java 2013/07/21 22:24:18 1.1 +++ jsr166/src/test/tck/ForkJoinTask8Test.java 2015/02/07 17:43:38 1.9 @@ -3,19 +3,19 @@ * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ + +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; + +import java.util.HashSet; import java.util.concurrent.ExecutionException; -import java.util.concurrent.CancellationException; import java.util.concurrent.ForkJoinPool; 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.*; + +import junit.framework.Test; +import junit.framework.TestSuite; public class ForkJoinTask8Test extends JSR166TestCase { @@ -32,7 +32,6 @@ public class ForkJoinTask8Test extends J static final short INITIAL_STATE = -1; static final short COMPLETE_STATE = 0; static final short EXCEPTION_STATE = 1; - public static void main(String[] args) { junit.textui.TestRunner.run(suite()); @@ -181,7 +180,6 @@ public class ForkJoinTask8Test extends J } catch (Throwable fail) { threadUnexpectedException(fail); } } - public static final class FJException extends RuntimeException { FJException() { super(); } } @@ -206,8 +204,8 @@ public class ForkJoinTask8Test extends J } protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) { - if (this.getForkJoinTaskTag() != COMPLETE_STATE || - x.getForkJoinTaskTag() != COMPLETE_STATE || + if (this.getForkJoinTaskTag() != COMPLETE_STATE || + x.getForkJoinTaskTag() != COMPLETE_STATE || y.getForkJoinTaskTag() != COMPLETE_STATE) { completeThisExceptionally(new FJException()); } @@ -241,7 +239,7 @@ public class ForkJoinTask8Test extends J a.sibling = null; a.parent = null; a.completeThis(); - if (p == null || + if (p == null || p.compareAndSetForkJoinTaskTag(INITIAL_STATE, COMPLETE_STATE)) break; try { @@ -279,7 +277,6 @@ public class ForkJoinTask8Test extends J super.reinitialize(); } - } static final class AsyncFib extends BinaryAsyncAction { @@ -304,7 +301,7 @@ public class ForkJoinTask8Test extends J } f.complete(); } - catch(Throwable ex) { + catch (Throwable ex) { compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE); } return false; @@ -573,7 +570,6 @@ public class ForkJoinTask8Test extends J testInvokeOnPool(mainPool(), a); } - /** * getPool of executing task returns its pool */ @@ -733,10 +729,13 @@ public class ForkJoinTask8Test extends J AsyncFib f = new AsyncFib(8); AsyncFib g = new AsyncFib(9); AsyncFib h = null; - try { - invokeAll(f, g, h); - shouldThrow(); - } catch (NullPointerException success) {} + Runnable[] throwingActions = { + () -> invokeAll(h), + () -> invokeAll(f, g, h), + () -> invokeAll(f, h, g), + () -> invokeAll(h, f, g), + }; + assertThrows(NullPointerException.class, throwingActions); }}; testInvokeOnPool(mainPool(), a); } @@ -796,7 +795,7 @@ public class ForkJoinTask8Test extends J } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { RecursiveAction a = new CheckedRecursiveAction() { @@ -1373,7 +1372,7 @@ public class ForkJoinTask8Test extends J } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollectionSingleton() { RecursiveAction a = new CheckedRecursiveAction() { @@ -1395,7 +1394,6 @@ public class ForkJoinTask8Test extends J testInvokeOnPool(singletonPool(), a); } - /** * ForkJoinTask.quietlyComplete returns when task completes * normally without setting a value. The most recent value