From 5583f64b1f98d48dbb4b0d12a1dec873c471a990 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 6 May 2020 16:30:13 -0700 Subject: [PATCH] Add tests to verify Jetty's thread pool defaults match server defaults Closes gh-21213 --- .../web/ServerPropertiesTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index c62c0e81f7..bfaae032b7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -40,6 +40,8 @@ import org.apache.catalina.valves.RemoteIpValve; import org.apache.coyote.AbstractProtocol; import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.thread.ThreadPool; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.web.ServerProperties.Tomcat.Accesslog; @@ -55,6 +57,7 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.unit.DataSize; @@ -354,6 +357,20 @@ class ServerPropertiesTests { assertThat(this.properties.getTomcat().getUseRelativeRedirects()).isFalse(); } + @Test + void jettyThreadPoolPropertyDefaultsShouldMatchServerDefault() { + JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0); + JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer(); + Server server = (Server) ReflectionTestUtils.getField(jetty, "server"); + ThreadPool threadPool = (ThreadPool) ReflectionTestUtils.getField(server, "_threadPool"); + int idleTimeout = (int) ReflectionTestUtils.getField(threadPool, "_idleTimeout"); + int maxThreads = (int) ReflectionTestUtils.getField(threadPool, "_maxThreads"); + int minThreads = (int) ReflectionTestUtils.getField(threadPool, "_minThreads"); + assertThat(this.properties.getJetty().getThreadIdleTimeout().toMillis()).isEqualTo(idleTimeout); + assertThat(this.properties.getJetty().getMaxThreads()).isEqualTo(maxThreads); + assertThat(this.properties.getJetty().getMinThreads()).isEqualTo(minThreads); + } + @Test void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception { JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);