Merge pull request #18206 from izeye

* pr/18206:
  Polish "Use Duration for ServerProperties.Jetty.idleTimeout"
  Use Duration for ServerProperties.Jetty.idleTimeout

Closes gh-18206
pull/18214/head
Stephane Nicoll 5 years ago
commit c2023a8c90

@ -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;
}

@ -86,7 +86,7 @@ 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(
propertyMapper.from(jettyProperties::getIdleTimeout).whenNonNull().asInt(Duration::toMillis).to(
(idleTimeout) -> customizeThreadPool(factory, (threadPool) -> threadPool.setIdleTimeout(idleTimeout)));
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));

@ -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

@ -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) {

Loading…
Cancel
Save