--- jsr166/src/test/tck/ForkJoinTaskTest.java 2017/08/16 17:18:34 1.53 +++ jsr166/src/test/tck/ForkJoinTaskTest.java 2021/01/26 13:33:06 1.60 @@ -68,7 +68,7 @@ public class ForkJoinTaskTest extends JS } } - void checkNotDone(ForkJoinTask a) { + void checkNotDone(ForkJoinTask a) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -87,18 +87,18 @@ public class ForkJoinTaskTest extends JS checkCompletedNormally(a, null); } - void checkCompletedNormally(ForkJoinTask a, T expected) { + void checkCompletedNormally(ForkJoinTask a, T expectedValue) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertTrue(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); assertNull(a.getException()); - assertSame(expected, a.getRawResult()); + assertSame(expectedValue, a.getRawResult()); { Thread.currentThread().interrupt(); long startTime = System.nanoTime(); - assertSame(expected, a.join()); + assertSame(expectedValue, a.join()); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); Thread.interrupted(); } @@ -113,13 +113,17 @@ public class ForkJoinTaskTest extends JS assertFalse(a.cancel(false)); assertFalse(a.cancel(true)); + + T v1 = null, v2 = null; try { - assertSame(expected, a.get()); - assertSame(expected, a.get(randomTimeout(), randomTimeUnit())); + v1 = a.get(); + v2 = a.get(randomTimeout(), randomTimeUnit()); } catch (Throwable fail) { threadUnexpectedException(fail); } + assertSame(expectedValue, v1); + assertSame(expectedValue, v2); } - void checkCancelled(ForkJoinTask a) { + void checkCancelled(ForkJoinTask a) { assertTrue(a.isDone()); assertTrue(a.isCancelled()); assertFalse(a.isCompletedNormally()); @@ -156,7 +160,7 @@ public class ForkJoinTaskTest extends JS } catch (Throwable fail) { threadUnexpectedException(fail); } } - void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { + void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { assertTrue(a.isDone()); assertFalse(a.isCancelled()); assertFalse(a.isCompletedNormally()); @@ -495,6 +499,8 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); assertSame(f, f.fork()); helpQuiesce(); + while (!f.isDone()) // wait out race + ; assertEquals(21, f.number); assertEquals(0, getQueuedTaskCount()); checkCompletedNormally(f); @@ -852,7 +858,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -892,7 +898,7 @@ public class ForkJoinTaskTest extends JS protected void realCompute() { AsyncFib f = new AsyncFib(8); FailingAsyncFib g = new FailingAsyncFib(9); - ForkJoinTask[] tasks = { f, g }; + ForkJoinTask[] tasks = { f, g }; shuffle(tasks); try { invokeAll(tasks); @@ -930,7 +936,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); FailingAsyncFib g = new FailingAsyncFib(9); AsyncFib h = new AsyncFib(7); - ForkJoinTask[] tasks = { f, g, h }; + ForkJoinTask[] tasks = { f, g, h }; shuffle(tasks); try { invokeAll(tasks); @@ -951,7 +957,7 @@ public class ForkJoinTaskTest extends JS FailingAsyncFib f = new FailingAsyncFib(8); AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); - ForkJoinTask[] tasks = { f, g, h }; + ForkJoinTask[] tasks = { f, g, h }; shuffle(tasks); try { invokeAll(Arrays.asList(tasks)); @@ -1521,7 +1527,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); - HashSet set = new HashSet(); + HashSet> set = new HashSet>(); set.add(f); set.add(g); set.add(h); @@ -1561,7 +1567,7 @@ public class ForkJoinTaskTest extends JS protected void realCompute() { AsyncFib f = new AsyncFib(8); FailingAsyncFib g = new FailingAsyncFib(9); - ForkJoinTask[] tasks = { f, g }; + ForkJoinTask[] tasks = { f, g }; shuffle(tasks); try { invokeAll(tasks); @@ -1599,7 +1605,7 @@ public class ForkJoinTaskTest extends JS AsyncFib f = new AsyncFib(8); FailingAsyncFib g = new FailingAsyncFib(9); AsyncFib h = new AsyncFib(7); - ForkJoinTask[] tasks = { f, g, h }; + ForkJoinTask[] tasks = { f, g, h }; shuffle(tasks); try { invokeAll(tasks); @@ -1620,7 +1626,7 @@ public class ForkJoinTaskTest extends JS FailingAsyncFib f = new FailingAsyncFib(8); AsyncFib g = new AsyncFib(9); AsyncFib h = new AsyncFib(7); - ForkJoinTask[] tasks = { f, g, h }; + ForkJoinTask[] tasks = { f, g, h }; shuffle(tasks); try { invokeAll(Arrays.asList(tasks)); @@ -1687,4 +1693,20 @@ public class ForkJoinTaskTest extends JS task.toString()); } } + + // adaptInterruptible deferred to its own independent change + // https://bugs.openjdk.java.net/browse/JDK-8246587 + +// /** +// * adaptInterruptible(callable).toString() contains toString of wrapped task +// */ +// public void testAdaptInterruptible_Callable_toString() { +// if (testImplementationDetails) { +// Callable c = () -> ""; +// ForkJoinTask task = ForkJoinTask.adaptInterruptible(c); +// assertEquals( +// identityString(task) + "[Wrapped task = " + c.toString() + "]", +// task.toString()); +// } +// } }