--- jsr166/src/test/tck/CountedCompleterTest.java 2013/07/14 21:43:56 1.12 +++ jsr166/src/test/tck/CountedCompleterTest.java 2015/10/06 00:36:55 1.20 @@ -3,27 +3,27 @@ * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ -import java.util.concurrent.ExecutionException; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; + +import java.util.HashSet; import java.util.concurrent.CancellationException; +import java.util.concurrent.CountedCompleter; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; -import java.util.concurrent.CountedCompleter; -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.AtomicInteger; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReference; -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 CountedCompleterTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { @@ -49,7 +49,7 @@ public class CountedCompleterTest extend } private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { - try { + try (PoolCleaner cleaner = cleaner(pool)) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -65,8 +65,6 @@ public class CountedCompleterTest extend assertFalse(a.isCancelled()); assertNull(a.getException()); assertNull(a.getRawResult()); - } finally { - joinPool(pool); } } @@ -95,17 +93,17 @@ public class CountedCompleterTest extend { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); assertNull(a.join()); - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); Thread.interrupted(); } { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); Thread.interrupted(); } @@ -138,9 +136,9 @@ public class CountedCompleterTest extend Thread.interrupted(); { - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); } try { @@ -176,9 +174,9 @@ public class CountedCompleterTest extend Thread.interrupted(); { - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); } try { @@ -198,8 +196,8 @@ public class CountedCompleterTest extend try { a.invoke(); shouldThrow(); - } catch (Throwable ex) { - assertSame(t, ex); + } catch (Throwable success) { + assertSame(t, success); } } @@ -1137,7 +1135,7 @@ public class CountedCompleterTest extend } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollection() { ForkJoinTask a = new CheckedRecursiveAction() { @@ -1802,7 +1800,7 @@ public class CountedCompleterTest extend } /** - * invokeAll(collection) throws exception if any task does + * invokeAll(collection) throws exception if any task does */ public void testAbnormalInvokeAllCollectionSingleton() { ForkJoinTask a = new CheckedRecursiveAction() {