--- jsr166/src/test/tck/RecursiveActionTest.java 2015/10/04 18:18:48 1.45 +++ jsr166/src/test/tck/RecursiveActionTest.java 2017/05/29 19:15:02 1.50 @@ -4,7 +4,7 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.Arrays; import java.util.HashSet; @@ -73,14 +73,14 @@ public class RecursiveActionTest extends Thread.currentThread().interrupt(); try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } } try { - a.get(0L, SECONDS); + a.get(randomExpiredTimeout(), randomTimeUnit()); shouldThrow(); } catch (TimeoutException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -98,9 +98,7 @@ public class RecursiveActionTest extends assertFalse(a.cancel(true)); try { assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(a.get(5L, SECONDS)); + assertNull(a.get(randomTimeout(), randomTimeUnit())); } catch (Throwable fail) { threadUnexpectedException(fail); } } @@ -125,7 +123,7 @@ public class RecursiveActionTest extends } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (CancellationException success) { } catch (Throwable fail) { threadUnexpectedException(fail); } @@ -156,7 +154,7 @@ public class RecursiveActionTest extends } catch (Throwable fail) { threadUnexpectedException(fail); } try { - a.get(5L, SECONDS); + a.get(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (ExecutionException success) { assertSame(t.getClass(), success.getCause().getClass()); @@ -168,7 +166,7 @@ public class RecursiveActionTest extends public FJException(Throwable cause) { super(cause); } } - // A simple recursive action for testing + /** A simple recursive action for testing. */ final class FibAction extends CheckedRecursiveAction { final int number; int result; @@ -186,7 +184,7 @@ public class RecursiveActionTest extends } } - // A recursive action failing in base case + /** A recursive action failing in base case. */ static final class FailingFibAction extends RecursiveAction { final int number; int result; @@ -258,12 +256,11 @@ public class RecursiveActionTest extends RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { FibAction f = new FibAction(8); - final Thread myself = Thread.currentThread(); + final Thread currentThread = Thread.currentThread(); // test join() assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); assertNull(f.join()); Thread.interrupted(); assertEquals(21, f.result); @@ -272,8 +269,7 @@ public class RecursiveActionTest extends f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); try { f.join(); shouldThrow(); @@ -285,8 +281,7 @@ public class RecursiveActionTest extends f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); try { f.join(); shouldThrow(); @@ -298,8 +293,7 @@ public class RecursiveActionTest extends // test quietlyJoin() f = new FibAction(8); assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); Thread.interrupted(); assertEquals(21, f.result); @@ -308,8 +302,7 @@ public class RecursiveActionTest extends f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); Thread.interrupted(); checkCancelled(f); @@ -317,8 +310,7 @@ public class RecursiveActionTest extends f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); Thread.interrupted(); checkCompletedAbnormally(f, f.getException()); @@ -358,22 +350,20 @@ public class RecursiveActionTest extends public void realRun() throws InterruptedException { FibAction[] fibActions = sq.take(); FibAction f; - final Thread myself = Thread.currentThread(); + final Thread currentThread = Thread.currentThread(); // test join() ------------ f = fibActions[0]; assertFalse(ForkJoinTask.inForkJoinPool()); - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); assertNull(f.join()); assertTrue(Thread.interrupted()); assertEquals(21, f.result); checkCompletedNormally(f); f = fibActions[1]; - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); try { f.join(); shouldThrow(); @@ -383,8 +373,7 @@ public class RecursiveActionTest extends } f = fibActions[2]; - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); try { f.join(); shouldThrow(); @@ -396,23 +385,20 @@ public class RecursiveActionTest extends // test quietlyJoin() --------- f = fibActions[3]; - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); assertTrue(Thread.interrupted()); assertEquals(21, f.result); checkCompletedNormally(f); f = fibActions[4]; - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); assertTrue(Thread.interrupted()); checkCancelled(f); f = fibActions[5]; - myself.interrupt(); - assertTrue(myself.isInterrupted()); + currentThread.interrupt(); f.quietlyJoin(); assertTrue(Thread.interrupted()); assertTrue(f.getException() instanceof FJException); @@ -423,12 +409,12 @@ public class RecursiveActionTest extends t = newStartedThread(r); testInvokeOnPool(mainPool(), a); - awaitTermination(t, LONG_DELAY_MS); + awaitTermination(t); a.reinitialize(); t = newStartedThread(r); testInvokeOnPool(singletonPool(), a); - awaitTermination(t, LONG_DELAY_MS); + awaitTermination(t); } /** @@ -454,7 +440,7 @@ public class RecursiveActionTest extends protected void realCompute() throws Exception { FibAction f = new FibAction(8); assertSame(f, f.fork()); - assertNull(f.get(5L, SECONDS)); + assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertEquals(21, f.result); checkCompletedNormally(f); }}; @@ -470,7 +456,7 @@ public class RecursiveActionTest extends FibAction f = new FibAction(8); assertSame(f, f.fork()); try { - f.get(5L, null); + f.get(randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} }}; @@ -589,7 +575,7 @@ public class RecursiveActionTest extends FailingFibAction f = new FailingFibAction(8); assertSame(f, f.fork()); try { - f.get(5L, SECONDS); + f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { Throwable cause = success.getCause(); @@ -681,7 +667,7 @@ public class RecursiveActionTest extends assertTrue(f.cancel(true)); assertSame(f, f.fork()); try { - f.get(5L, SECONDS); + f.get(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (CancellationException success) { checkCancelled(f);