--- jsr166/src/test/tck/RecursiveActionTest.java 2016/08/16 23:17:13 1.48 +++ jsr166/src/test/tck/RecursiveActionTest.java 2021/01/27 01:57:24 1.57 @@ -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); } @@ -96,12 +96,14 @@ public class RecursiveActionTest extends assertNull(a.join()); assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); + + Object v1 = null, v2 = null; try { - assertNull(a.get()); - } catch (Throwable fail) { threadUnexpectedException(fail); } - try { - assertNull(a.get(5L, SECONDS)); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertNull(v1); + assertNull(v2); } void checkCancelled(RecursiveAction a) { @@ -125,7 +127,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 +158,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 +170,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 +188,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; @@ -327,8 +329,7 @@ public class RecursiveActionTest extends * succeeds in the presence of interrupts */ public void testJoinIgnoresInterruptsOutsideForkJoinPool() { - final SynchronousQueue sq = - new SynchronousQueue(); + final SynchronousQueue sq = new SynchronousQueue<>(); RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws InterruptedException { FibAction[] fibActions = new FibAction[6]; @@ -340,8 +341,8 @@ public class RecursiveActionTest extends fibActions[4].cancel(true); fibActions[5].completeExceptionally(new FJException()); - for (int i = 0; i < fibActions.length; i++) - fibActions[i].fork(); + for (FibAction fibAction : fibActions) + fibAction.fork(); sq.put(fibActions); @@ -442,7 +443,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); }}; @@ -458,7 +459,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) {} }}; @@ -577,7 +578,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(); @@ -669,7 +670,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); @@ -919,7 +920,7 @@ public class RecursiveActionTest extends FibAction f = new FibAction(8); FibAction g = new FibAction(9); FibAction h = new FibAction(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet<>(); set.add(f); set.add(g); set.add(h); @@ -1017,7 +1018,7 @@ public class RecursiveActionTest extends FailingFibAction f = new FailingFibAction(8); FibAction g = new FibAction(9); FibAction h = new FibAction(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet<>(); set.add(f); set.add(g); set.add(h);