diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java index b46ef15b6bd..8ee09014ae9 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java @@ -18,11 +18,7 @@ package org.eclipse.jetty.util.thread; -import java.time.Duration; - import org.eclipse.jetty.util.ProcessorUtils; -import org.eclipse.jetty.util.component.ContainerLifeCycle; -import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterAll; @@ -30,8 +26,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.fail; public abstract class AbstractThreadPoolTest @@ -93,26 +87,4 @@ public abstract class AbstractThreadPoolTest assertThat(pool.getMaxThreads(), Matchers.is(3)); } - - @Test - public void testJoinWithStopTimeout() - { - // ThreadPool must be an implement ContainerLifeCycle for this test to be valid. - SizedThreadPool threadPool = newPool(3); - if (!(threadPool instanceof ContainerLifeCycle)) - return; - - final long stopTimeout = 100; - ((ContainerLifeCycle)threadPool).setStopTimeout(100); - LifeCycle.start(threadPool); - - // Verify that join does not timeout after waiting twice the stopTimeout. - assertThrows(Throwable.class, () -> - assertTimeoutPreemptively(Duration.ofMillis(stopTimeout * 2), threadPool::join) - ); - - // After stopping the ThreadPool join should unblock. - LifeCycle.stop(threadPool); - assertTimeoutPreemptively(Duration.ofMillis(stopTimeout), threadPool::join); - } } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index 770a481b675..ef6b13efc66 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -19,11 +19,13 @@ package org.eclipse.jetty.util.thread; import java.io.Closeable; +import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jetty.logging.StacklessLogging; +import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -36,6 +38,7 @@ import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.StringContains.containsString; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.assertTrue; public class QueuedThreadPoolTest extends AbstractThreadPoolTest @@ -753,6 +756,24 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest assertThrows(IllegalArgumentException.class, () -> new QueuedThreadPool(4, 8)); } + @Test + public void testJoinWithStopTimeout() throws Exception + { + final long stopTimeout = 100; + QueuedThreadPool threadPool = new QueuedThreadPool(); + threadPool.setStopTimeout(100); + threadPool.start(); + + // Verify that join does not timeout after waiting twice the stopTimeout. + assertThrows(Throwable.class, () -> + assertTimeoutPreemptively(Duration.ofMillis(stopTimeout * 2), threadPool::join) + ); + + // After stopping the ThreadPool join should unblock. + LifeCycle.stop(threadPool); + assertTimeoutPreemptively(Duration.ofMillis(stopTimeout), threadPool::join); + } + @Test public void testDump() throws Exception {