--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2015/10/06 16:39:06 1.93 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2021/01/27 01:57:24 1.106 @@ -10,6 +10,8 @@ import static java.util.concurrent.TimeU import static java.util.concurrent.TimeUnit.SECONDS; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -17,16 +19,15 @@ import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RunnableFuture; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeUnit; @@ -239,7 +240,7 @@ public class ThreadPoolExecutorSubclassT final Runnable task = new CheckedRunnable() { public void realRun() { done.countDown(); }}; p.execute(task); - assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); + await(done); } } @@ -333,13 +334,13 @@ public class ThreadPoolExecutorSubclassT public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(0, p.getCompletedTaskCount()); - threadProceed.await(); + await(threadProceed); threadDone.countDown(); }}); await(threadStarted); assertEquals(0, p.getCompletedTaskCount()); threadProceed.countDown(); - threadDone.await(); + await(threadDone); long startTime = System.nanoTime(); while (p.getCompletedTaskCount() != 1) { if (millisElapsedSince(startTime) > LONG_DELAY_MS) @@ -652,23 +653,25 @@ public class ThreadPoolExecutorSubclassT */ public void testGetQueue() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); - final BlockingQueue q = new ArrayBlockingQueue(10); + final BlockingQueue q = new ArrayBlockingQueue<>(10); final ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q); try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); - FutureTask[] tasks = new FutureTask[5]; + FutureTask[] rtasks = new FutureTask[5]; + @SuppressWarnings("unchecked") + FutureTask[] tasks = (FutureTask[])rtasks; for (int i = 0; i < tasks.length; i++) { - Callable task = new CheckedCallable() { + Callable task = new CheckedCallable<>() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); assertSame(q, p.getQueue()); await(done); return Boolean.TRUE; }}; - tasks[i] = new FutureTask(task); + tasks[i] = new FutureTask<>(task); p.execute(tasks[i]); } await(threadStarted); @@ -684,7 +687,7 @@ public class ThreadPoolExecutorSubclassT */ public void testRemove() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); - BlockingQueue q = new ArrayBlockingQueue(10); + BlockingQueue q = new ArrayBlockingQueue<>(10); final ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, @@ -719,21 +722,23 @@ public class ThreadPoolExecutorSubclassT public void testPurge() throws InterruptedException { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); - final BlockingQueue q = new ArrayBlockingQueue(10); + final BlockingQueue q = new ArrayBlockingQueue<>(10); final ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, q); try (PoolCleaner cleaner = cleaner(p, done)) { - FutureTask[] tasks = new FutureTask[5]; + FutureTask[] rtasks = new FutureTask[5]; + @SuppressWarnings("unchecked") + FutureTask[] tasks = (FutureTask[])rtasks; for (int i = 0; i < tasks.length; i++) { - Callable task = new CheckedCallable() { + Callable task = new CheckedCallable<>() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); await(done); return Boolean.TRUE; }}; - tasks[i] = new FutureTask(task); + tasks[i] = new FutureTask<>(task); p.execute(tasks[i]); } await(threadStarted); @@ -768,7 +773,7 @@ public class ThreadPoolExecutorSubclassT Runnable waiter = new CheckedRunnable() { public void realRun() { threadsStarted.countDown(); try { - MILLISECONDS.sleep(2 * LONG_DELAY_MS); + MILLISECONDS.sleep(LONGER_DELAY_MS); } catch (InterruptedException success) {} ran.getAndIncrement(); }}; @@ -1130,88 +1135,71 @@ public class ThreadPoolExecutorSubclassT } /** - * execute throws RejectedExecutionException if saturated. + * Submitted tasks are rejected when saturated or shutdown */ - public void testSaturatedExecute() { - final CountDownLatch done = new CountDownLatch(1); + public void testSubmittedTasksRejectedWhenSaturatedOrShutdown() throws InterruptedException { final ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1)); - try (PoolCleaner cleaner = cleaner(p, done)) { - Runnable task = new CheckedRunnable() { - public void realRun() throws InterruptedException { - await(done); - }}; - for (int i = 0; i < 2; ++i) - p.execute(task); - for (int i = 0; i < 2; ++i) { + final int saturatedSize = saturatedSize(p); + final ThreadLocalRandom rnd = ThreadLocalRandom.current(); + final CountDownLatch threadsStarted = new CountDownLatch(p.getMaximumPoolSize()); + final CountDownLatch done = new CountDownLatch(1); + final Runnable r = () -> { + threadsStarted.countDown(); + for (;;) { try { - p.execute(task); - shouldThrow(); - } catch (RejectedExecutionException success) {} - assertTrue(p.getTaskCount() <= 2); - } - } - } + done.await(); + return; + } catch (InterruptedException shutdownNowDeliberatelyIgnored) {} + }}; + final Callable c = () -> { + threadsStarted.countDown(); + for (;;) { + try { + done.await(); + return Boolean.TRUE; + } catch (InterruptedException shutdownNowDeliberatelyIgnored) {} + }}; + final boolean shutdownNow = rnd.nextBoolean(); - /** - * executor using CallerRunsPolicy runs task if saturated. - */ - public void testSaturatedExecute2() { - final CountDownLatch done = new CountDownLatch(1); - final ThreadPoolExecutor p = - new CustomTPE(1, 1, - LONG_DELAY_MS, MILLISECONDS, - new ArrayBlockingQueue(1), - new CustomTPE.CallerRunsPolicy()); try (PoolCleaner cleaner = cleaner(p, done)) { - Runnable blocker = new CheckedRunnable() { - public void realRun() throws InterruptedException { - await(done); - }}; - p.execute(blocker); - TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; - for (int i = 0; i < tasks.length; i++) - tasks[i] = new TrackedNoOpRunnable(); - for (int i = 0; i < tasks.length; i++) - p.execute(tasks[i]); - for (int i = 1; i < tasks.length; i++) - assertTrue(tasks[i].done); - assertFalse(tasks[0].done); // waiting in queue - } - } + // saturate + for (int i = saturatedSize; i--> 0; ) { + switch (rnd.nextInt(4)) { + case 0: p.execute(r); break; + case 1: assertFalse(p.submit(r).isDone()); break; + case 2: assertFalse(p.submit(r, Boolean.TRUE).isDone()); break; + case 3: assertFalse(p.submit(c).isDone()); break; + } + } - /** - * executor using DiscardPolicy drops task if saturated. - */ - public void testSaturatedExecute3() { - final TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; - for (int i = 0; i < tasks.length; ++i) - tasks[i] = new TrackedNoOpRunnable(); - final CountDownLatch done = new CountDownLatch(1); - final ThreadPoolExecutor p = - new CustomTPE(1, 1, - LONG_DELAY_MS, MILLISECONDS, - new ArrayBlockingQueue(1), - new CustomTPE.DiscardPolicy()); - try (PoolCleaner cleaner = cleaner(p, done)) { - p.execute(awaiter(done)); + await(threadsStarted); + assertTaskSubmissionsAreRejected(p); + + if (shutdownNow) + p.shutdownNow(); + else + p.shutdown(); + // Pool is shutdown, but not yet terminated + assertTaskSubmissionsAreRejected(p); + assertFalse(p.isTerminated()); - for (TrackedNoOpRunnable task : tasks) - p.execute(task); - for (int i = 1; i < tasks.length; i++) - assertFalse(tasks[i].done); - } - for (int i = 1; i < tasks.length; i++) - assertFalse(tasks[i].done); - assertTrue(tasks[0].done); // was waiting in queue + done.countDown(); // release blocking tasks + assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); + + assertTaskSubmissionsAreRejected(p); + } + assertEquals(saturatedSize(p) + - (shutdownNow ? p.getQueue().remainingCapacity() : 0), + p.getCompletedTaskCount()); } /** * executor using DiscardOldestPolicy drops oldest task if saturated. */ - public void testSaturatedExecute4() { + public void testSaturatedExecute_DiscardOldestPolicy() { final CountDownLatch done = new CountDownLatch(1); LatchAwaiter r1 = awaiter(done); LatchAwaiter r2 = awaiter(done); @@ -1220,7 +1208,7 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), - new CustomTPE.DiscardOldestPolicy()); + new ThreadPoolExecutor.DiscardOldestPolicy()); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(LatchAwaiter.NEW, r1.state); assertEquals(LatchAwaiter.NEW, r2.state); @@ -1238,57 +1226,6 @@ public class ThreadPoolExecutorSubclassT } /** - * execute throws RejectedExecutionException if shutdown - */ - public void testRejectedExecutionExceptionOnShutdown() { - final ThreadPoolExecutor p = - new CustomTPE(1, 1, - LONG_DELAY_MS, MILLISECONDS, - new ArrayBlockingQueue(1)); - try { p.shutdown(); } catch (SecurityException ok) { return; } - try (PoolCleaner cleaner = cleaner(p)) { - try { - p.execute(new NoOpRunnable()); - shouldThrow(); - } catch (RejectedExecutionException success) {} - } - } - - /** - * execute using CallerRunsPolicy drops task on shutdown - */ - public void testCallerRunsOnShutdown() { - final ThreadPoolExecutor p = - new CustomTPE(1, 1, - LONG_DELAY_MS, MILLISECONDS, - new ArrayBlockingQueue(1), - new CustomTPE.CallerRunsPolicy()); - try { p.shutdown(); } catch (SecurityException ok) { return; } - try (PoolCleaner cleaner = cleaner(p)) { - TrackedNoOpRunnable r = new TrackedNoOpRunnable(); - p.execute(r); - assertFalse(r.done); - } - } - - /** - * execute using DiscardPolicy drops task on shutdown - */ - public void testDiscardOnShutdown() { - final ThreadPoolExecutor p = - new CustomTPE(1, 1, - LONG_DELAY_MS, MILLISECONDS, - new ArrayBlockingQueue(1), - new CustomTPE.DiscardPolicy()); - try { p.shutdown(); } catch (SecurityException ok) { return; } - try (PoolCleaner cleaner = cleaner(p)) { - TrackedNoOpRunnable r = new TrackedNoOpRunnable(); - p.execute(r); - assertFalse(r.done); - } - } - - /** * execute using DiscardOldestPolicy drops task on shutdown */ public void testDiscardOldestOnShutdown() { @@ -1296,7 +1233,7 @@ public class ThreadPoolExecutorSubclassT new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(1), - new CustomTPE.DiscardOldestPolicy()); + new ThreadPoolExecutor.DiscardOldestPolicy()); try { p.shutdown(); } catch (SecurityException ok) { return; } try (PoolCleaner cleaner = cleaner(p)) { @@ -1307,18 +1244,15 @@ public class ThreadPoolExecutorSubclassT } /** - * execute(null) throws NPE + * Submitting null tasks throws NullPointerException */ - public void testExecuteNull() { + public void testNullTaskSubmission() { final ThreadPoolExecutor p = new CustomTPE(1, 2, 1L, SECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(p)) { - try { - p.execute(null); - shouldThrow(); - } catch (NullPointerException success) {} + assertNullTaskSubmissionThrowsNullPointerException(p); } } @@ -1362,8 +1296,8 @@ public class ThreadPoolExecutorSubclassT public void testMaximumPoolSizeIllegalArgumentException2() { final ThreadPoolExecutor p = new CustomTPE(2, 3, - LONG_DELAY_MS, - MILLISECONDS,new ArrayBlockingQueue(10)); + LONG_DELAY_MS, MILLISECONDS, + new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setMaximumPoolSize(-1); @@ -1465,7 +1399,7 @@ public class ThreadPoolExecutorSubclassT } /** - * invokeAny(null) throws NPE + * invokeAny(null) throws NullPointerException */ public void testInvokeAny1() throws Exception { final ExecutorService e = @@ -1481,7 +1415,7 @@ public class ThreadPoolExecutorSubclassT } /** - * invokeAny(empty collection) throws IAE + * invokeAny(empty collection) throws IllegalArgumentException */ public void testInvokeAny2() throws Exception { final ExecutorService e = @@ -1506,7 +1440,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(latchAwaitingStringTask(latch)); l.add(null); try { @@ -1526,7 +1460,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new NPETask()); try { e.invokeAny(l); @@ -1546,7 +1480,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1571,15 +1505,17 @@ public class ThreadPoolExecutorSubclassT } /** - * invokeAll(empty collection) returns empty collection + * invokeAll(empty collection) returns empty list */ public void testInvokeAll2() throws Exception { final ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + final Collection> emptyCollection + = Collections.emptyList(); try (PoolCleaner cleaner = cleaner(e)) { - List> r = e.invokeAll(new ArrayList>()); + List> r = e.invokeAll(emptyCollection); assertTrue(r.isEmpty()); } } @@ -1593,7 +1529,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(null); try { @@ -1612,7 +1548,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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()); @@ -1634,7 +1570,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1654,7 +1590,7 @@ public class ThreadPoolExecutorSubclassT new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { try { - e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAny(null, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} } @@ -1669,27 +1605,28 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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) {} } } /** - * timed invokeAny(empty collection) throws IAE + * timed invokeAny(empty collection) throws IllegalArgumentException */ public void testTimedInvokeAny2() throws Exception { final ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + final Collection> emptyCollection + = Collections.emptyList(); try (PoolCleaner cleaner = cleaner(e)) { try { - e.invokeAny(new ArrayList>(), - MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAny(emptyCollection, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (IllegalArgumentException success) {} } @@ -1705,11 +1642,11 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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(); @@ -1725,14 +1662,16 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + long startTime = System.nanoTime(); + List> l = new ArrayList<>(); l.add(new NPETask()); try { - e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); } + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } } @@ -1745,11 +1684,13 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + long startTime = System.nanoTime(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); - String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); + String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); assertSame(TEST_STRING, result); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } } @@ -1763,7 +1704,7 @@ public class ThreadPoolExecutorSubclassT new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { try { - e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAll(null, randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (NullPointerException success) {} } @@ -1778,26 +1719,28 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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 Exception { final ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); + final Collection> emptyCollection + = Collections.emptyList(); try (PoolCleaner cleaner = cleaner(e)) { - List> r = e.invokeAll(new ArrayList>(), - MEDIUM_DELAY_MS, MILLISECONDS); + List> r = + e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit()); assertTrue(r.isEmpty()); } } @@ -1811,11 +1754,11 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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) {} } @@ -1830,7 +1773,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); 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); @@ -1853,7 +1796,7 @@ public class ThreadPoolExecutorSubclassT LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); try (PoolCleaner cleaner = cleaner(e)) { - List> l = new ArrayList>(); + List> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); List> futures = @@ -1870,7 +1813,7 @@ public class ThreadPoolExecutorSubclassT public void testTimedInvokeAll6() throws Exception { for (long timeout = timeoutMillis();;) { final CountDownLatch done = new CountDownLatch(1); - final Callable waiter = new CheckedCallable() { + final Callable waiter = new CheckedCallable<>() { public String realCall() { try { done.await(LONG_DELAY_MS, MILLISECONDS); } catch (InterruptedException ok) {} @@ -1889,7 +1832,7 @@ public class ThreadPoolExecutorSubclassT p.invokeAll(tasks, timeout, MILLISECONDS); assertEquals(tasks.size(), futures.size()); assertTrue(millisElapsedSince(startTime) >= timeout); - for (Future future : futures) + for (Future future : futures) assertTrue(future.isDone()); assertTrue(futures.get(1).isCancelled()); try { @@ -1923,7 +1866,7 @@ public class ThreadPoolExecutorSubclassT public void realRun() { done.countDown(); }}); - assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); + await(done); } } @@ -2027,5 +1970,20 @@ public class ThreadPoolExecutorSubclassT } } } + @SuppressWarnings("deprecation") + public void testFinalizeMethodCallsSuperFinalize() { + new CustomTPE(1, 1, + LONG_DELAY_MS, MILLISECONDS, + new LinkedBlockingQueue()) { + + /** + * A finalize method without "throws Throwable", that + * calls super.finalize(). + */ + protected void finalize() { + super.finalize(); + } + }.shutdown(); + } }