From 96019362f767c593588cd15b221c11fc3b594686 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 11 Sep 2019 19:03:13 +0900 Subject: [PATCH] Use Duration for ServerProperties.Jetty.idleTimeout See gh-18206 --- .../boot/autoconfigure/web/ServerProperties.java | 6 +++--- .../web/embedded/JettyWebServerFactoryCustomizer.java | 5 +++-- .../boot/autoconfigure/web/ServerPropertiesTests.java | 4 ++-- .../web/embedded/JettyWebServerFactoryCustomizerTests.java | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 0e2eb8daf9..555d1b78a7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -919,7 +919,7 @@ public class ServerProperties { /** * Maximum thread idle time. */ - private Integer idleTimeout = 60000; + private Duration idleTimeout = Duration.ofMillis(60000); public Accesslog getAccesslog() { return this.accesslog; @@ -965,11 +965,11 @@ public class ServerProperties { return this.maxThreads; } - public void setIdleTimeout(Integer idleTimeout) { + public void setIdleTimeout(Duration idleTimeout) { this.idleTimeout = idleTimeout; } - public Integer getIdleTimeout() { + public Duration getIdleTimeout() { return this.idleTimeout; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index fab6ae591d..2c06ee5cc5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -86,8 +86,9 @@ public class JettyWebServerFactoryCustomizer .to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads))); propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive) .to((minThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMinThreads(minThreads))); - propertyMapper.from(jettyProperties::getIdleTimeout).when(this::isPositive).to( - (idleTimeout) -> customizeThreadPool(factory, (threadPool) -> threadPool.setIdleTimeout(idleTimeout))); + propertyMapper.from(jettyProperties::getIdleTimeout).whenNonNull() + .to((idleTimeout) -> customizeThreadPool(factory, + (threadPool) -> threadPool.setIdleTimeout((int) idleTimeout.toMillis()))); propertyMapper.from(properties::getConnectionTimeout).whenNonNull() .to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled) 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 bebde8228c..db8260ff8a 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 @@ -233,8 +233,8 @@ class ServerPropertiesTests { @Test void testCustomizeJettyIdleTimeout() { - bind("server.jetty.idle-timeout", "10"); - assertThat(this.properties.getJetty().getIdleTimeout()).isEqualTo(10); + bind("server.jetty.idle-timeout", "10s"); + assertThat(this.properties.getJetty().getIdleTimeout()).isEqualTo(Duration.ofSeconds(10)); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java index 76557d8579..1a9d97964d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java @@ -132,10 +132,10 @@ class JettyWebServerFactoryCustomizerTests { @Test void idleTimeoutCanBeCustomized() { - bind("server.jetty.idle-timeout=100"); + bind("server.jetty.idle-timeout=100s"); JettyWebServer server = customizeAndGetServer(); QueuedThreadPool threadPool = (QueuedThreadPool) server.getServer().getThreadPool(); - assertThat(threadPool.getIdleTimeout()).isEqualTo(100); + assertThat(threadPool.getIdleTimeout()).isEqualTo(100000); } private CustomRequestLog getRequestLog(JettyWebServer server) {