--- jsr166/src/test/tck/ForkJoinPoolTest.java 2016/09/15 01:18:01 1.71 +++ jsr166/src/test/tck/ForkJoinPoolTest.java 2018/11/21 23:42:12 1.77 @@ -11,6 +11,7 @@ import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -27,7 +28,6 @@ import java.util.concurrent.atomic.Atomi import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; -import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestSuite; @@ -109,7 +109,7 @@ public class ForkJoinPoolTest extends JS return n; FibTask f1 = new FibTask(n - 1); f1.fork(); - return (new FibTask(n - 2)).compute() + f1.join(); + return new FibTask(n - 2).compute() + f1.join(); } } @@ -217,7 +217,7 @@ public class ForkJoinPoolTest extends JS taskStarted.countDown(); assertEquals(1, p.getPoolSize()); assertEquals(1, p.getActiveThreadCount()); - done.await(); + await(done); }}; Future future = p.submit(task); await(taskStarted); @@ -240,8 +240,8 @@ public class ForkJoinPoolTest extends JS assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); assertFalse(p.awaitTermination(-1L, NANOSECONDS)); assertFalse(p.awaitTermination(-1L, MILLISECONDS)); - assertFalse(p.awaitTermination(0L, NANOSECONDS)); - assertFalse(p.awaitTermination(0L, MILLISECONDS)); + assertFalse(p.awaitTermination(randomExpiredTimeout(), + randomTimeUnit())); long timeoutNanos = 999999L; long startTime = System.nanoTime(); assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); @@ -303,7 +303,7 @@ public class ForkJoinPoolTest extends JS p.getFactory()); while (! p.isQuiescent()) { if (millisElapsedSince(startTime) > LONG_DELAY_MS) - throw new AssertionFailedError("timed out"); + throw new AssertionError("timed out"); assertFalse(p.getAsyncMode()); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); @@ -422,7 +422,7 @@ public class ForkJoinPoolTest extends JS done.set(true); }}); assertNull(future.get()); - assertNull(future.get(0, MILLISECONDS)); + assertNull(future.get(randomExpiredTimeout(), randomTimeUnit())); assertTrue(done.get()); assertTrue(future.isDone()); assertFalse(future.isCancelled()); @@ -631,7 +631,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAny3() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(null); try { e.invokeAny(l); @@ -647,7 +647,7 @@ public class ForkJoinPoolTest extends JS CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(latchAwaitingStringTask(latch)); l.add(null); try { @@ -664,7 +664,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAny5() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new NPETask()); try { e.invokeAny(l); @@ -681,7 +681,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAny6() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l); @@ -703,13 +703,14 @@ public class ForkJoinPoolTest extends JS } /** - * invokeAll(empty collection) returns empty collection + * invokeAll(empty collection) returns empty list */ public void testInvokeAll2() throws InterruptedException { ExecutorService e = new ForkJoinPool(1); + final Collection> emptyCollection + = Collections.emptyList(); try (PoolCleaner cleaner = cleaner(e)) { - List> r - = e.invokeAll(new ArrayList>()); + List> r = e.invokeAll(emptyCollection); assertTrue(r.isEmpty()); } } @@ -720,7 +721,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAll3() throws InterruptedException { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(null); try { @@ -737,7 +738,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAll4() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new NPETask()); List> futures = e.invokeAll(l); assertEquals(1, futures.size()); @@ -756,7 +757,7 @@ public class ForkJoinPoolTest extends JS public void testInvokeAll5() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); List> futures = e.invokeAll(l); @@ -773,7 +774,7 @@ public class ForkJoinPoolTest extends JS ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { try { - e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAny(null, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} } @@ -785,10 +786,10 @@ public class ForkJoinPoolTest extends JS public void testTimedInvokeAnyNullTimeUnit() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); try { - e.invokeAny(l, MEDIUM_DELAY_MS, null); + e.invokeAny(l, randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} } @@ -802,7 +803,7 @@ public class ForkJoinPoolTest extends JS try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(new ArrayList>(), - MEDIUM_DELAY_MS, MILLISECONDS); + randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (IllegalArgumentException success) {} } @@ -815,11 +816,11 @@ public class ForkJoinPoolTest extends JS CountDownLatch latch = new CountDownLatch(1); ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(latchAwaitingStringTask(latch)); l.add(null); try { - e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAny(l, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} latch.countDown(); @@ -833,7 +834,7 @@ public class ForkJoinPoolTest extends JS ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { long startTime = System.nanoTime(); - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new NPETask()); try { e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); @@ -852,7 +853,7 @@ public class ForkJoinPoolTest extends JS ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { long startTime = System.nanoTime(); - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); @@ -868,7 +869,7 @@ public class ForkJoinPoolTest extends JS ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { try { - e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAll(null, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} } @@ -880,24 +881,26 @@ public class ForkJoinPoolTest extends JS public void testTimedInvokeAllNullTimeUnit() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); try { - e.invokeAll(l, MEDIUM_DELAY_MS, null); + e.invokeAll(l, randomTimeout(), null); shouldThrow(); } catch (NullPointerException success) {} } } /** - * timed invokeAll(empty collection) returns empty collection + * timed invokeAll(empty collection) returns empty list */ public void testTimedInvokeAll2() throws InterruptedException { ExecutorService e = new ForkJoinPool(1); + final Collection> emptyCollection + = Collections.emptyList(); try (PoolCleaner cleaner = cleaner(e)) { List> r - = e.invokeAll(new ArrayList>(), - MEDIUM_DELAY_MS, MILLISECONDS); + = e.invokeAll(emptyCollection, + randomTimeout(), randomTimeUnit()); assertTrue(r.isEmpty()); } } @@ -908,11 +911,11 @@ public class ForkJoinPoolTest extends JS public void testTimedInvokeAll3() throws InterruptedException { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(null); try { - e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAll(l, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} } @@ -924,7 +927,7 @@ public class ForkJoinPoolTest extends JS public void testTimedInvokeAll4() throws Throwable { ExecutorService e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new NPETask()); List> futures = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); @@ -944,7 +947,7 @@ public class ForkJoinPoolTest extends JS public void testTimedInvokeAll5() throws Throwable { ForkJoinPool e = new ForkJoinPool(1); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); List> futures