From 0741c90489c94c7a15a415013301f40f93caae05 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 20 Dec 2018 15:24:53 +0000 Subject: [PATCH] Avoid blocking on a Mono indefinitely Closes gh-15535 --- ...activeHealthEndpointWebExtensionTests.java | 5 ++- ...FoundryActuatorAutoConfigurationTests.java | 16 +++---- ...activeHealthEndpointWebExtensionTests.java | 42 +++++++++++-------- .../reactive/EndpointRequestTests.java | 10 +++-- ...ControllerEndpointHandlerMappingTests.java | 4 +- .../server/MetricsWebFilterTests.java | 10 +++-- .../reactive/HttpTraceWebFilterTests.java | 19 +++++---- ...ConfigurationReactiveIntegrationTests.java | 16 ++++--- ...rDetailsServiceAutoConfigurationTests.java | 26 ++++++------ .../reactive/StaticResourceRequestTests.java | 11 +++-- .../WebClientAutoConfigurationTests.java | 7 +++- ...DataMongoTestReactiveIntegrationTests.java | 11 +++-- ...UndertowReactiveWebServerFactoryTests.java | 3 +- .../view/MustacheViewResolverTests.java | 11 +++-- .../result/view/MustacheViewTests.java | 9 ++-- ...AbstractReactiveWebServerFactoryTests.java | 17 ++++---- .../SampleSessionWebFluxApplicationTests.java | 13 +++--- 17 files changed, 139 insertions(+), 91 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtensionTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtensionTests.java index 1284ca3021..bad67cc5b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtensionTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtensionTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive; +import java.time.Duration; + import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; @@ -63,7 +65,8 @@ public class CloudFoundryReactiveHealthEndpointWebExtensionTests { this.contextRunner.run((context) -> { CloudFoundryReactiveHealthEndpointWebExtension extension = context .getBean(CloudFoundryReactiveHealthEndpointWebExtension.class); - assertThat(extension.health().block().getBody().getDetails()).isNotEmpty(); + assertThat(extension.health().block(Duration.ofSeconds(30)).getBody() + .getDetails()).isNotEmpty(); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java index 3a7e47bc5d..0c65e3423c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive; +import java.time.Duration; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -201,16 +202,17 @@ public class ReactiveCloudFoundryActuatorAutoConfigurationTests { Boolean cfRequestMatches = filters.get(0) .matches(MockServerWebExchange.from(MockServerHttpRequest .get("/cloudfoundryapplication/my-path").build())) - .block(); + .block(Duration.ofSeconds(30)); Boolean otherRequestMatches = filters.get(0) .matches(MockServerWebExchange.from(MockServerHttpRequest .get("/some-other-path").build())) - .block(); + .block(Duration.ofSeconds(30)); assertThat(cfRequestMatches).isTrue(); assertThat(otherRequestMatches).isFalse(); - otherRequestMatches = filters.get(1).matches(MockServerWebExchange - .from(MockServerHttpRequest.get("/some-other-path").build())) - .block(); + otherRequestMatches = filters.get(1) + .matches(MockServerWebExchange.from(MockServerHttpRequest + .get("/some-other-path").build())) + .block(Duration.ofSeconds(30)); assertThat(otherRequestMatches).isTrue(); }); @@ -314,7 +316,7 @@ public class ReactiveCloudFoundryActuatorAutoConfigurationTests { WebClient webClient = (WebClient) ReflectionTestUtils .getField(interceptorSecurityService, "webClient"); webClient.get().uri("https://self-signed.badssl.com/").exchange() - .block(); + .block(Duration.ofSeconds(30)); }); } @@ -337,7 +339,7 @@ public class ReactiveCloudFoundryActuatorAutoConfigurationTests { .getField(interceptorSecurityService, "webClient"); this.thrown.expectCause(instanceOf(SSLException.class)); webClient.get().uri("https://self-signed.badssl.com/").exchange() - .block(); + .block(Duration.ofSeconds(30)); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthEndpointWebExtensionTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthEndpointWebExtensionTests.java index 2282b1a9dc..2f979537d6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthEndpointWebExtensionTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthEndpointWebExtensionTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.health; import java.security.Principal; +import java.time.Duration; import org.junit.Test; import reactor.core.publisher.Mono; @@ -97,8 +98,8 @@ public class ReactiveHealthEndpointWebExtensionTests { SecurityContext securityContext = mock(SecurityContext.class); given(securityContext.getPrincipal()) .willReturn(mock(Principal.class)); - Health extensionHealth = extension.health(securityContext).block() - .getBody(); + Health extensionHealth = extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody(); assertThat(endpointHealth.getDetails()) .containsOnlyKeys("application", "first", "second"); assertThat(extensionHealth.getDetails()) @@ -111,8 +112,8 @@ public class ReactiveHealthEndpointWebExtensionTests { this.contextRunner.run((context) -> { ReactiveHealthEndpointWebExtension extension = context .getBean(ReactiveHealthEndpointWebExtension.class); - assertThat(extension.health(mock(SecurityContext.class)).block().getBody() - .getDetails()).isEmpty(); + assertThat(extension.health(mock(SecurityContext.class)) + .block(Duration.ofSeconds(30)).getBody().getDetails()).isEmpty(); }); } @@ -123,8 +124,8 @@ public class ReactiveHealthEndpointWebExtensionTests { .getBean(ReactiveHealthEndpointWebExtension.class); SecurityContext securityContext = mock(SecurityContext.class); given(securityContext.getPrincipal()).willReturn(mock(Principal.class)); - assertThat(extension.health(securityContext).block().getBody().getDetails()) - .isEmpty(); + assertThat(extension.health(securityContext).block(Duration.ofSeconds(30)) + .getBody().getDetails()).isEmpty(); }); } @@ -139,8 +140,9 @@ public class ReactiveHealthEndpointWebExtensionTests { SecurityContext securityContext = mock(SecurityContext.class); given(securityContext.getPrincipal()) .willReturn(mock(Principal.class)); - assertThat(extension.health(securityContext).block().getBody() - .getDetails()).isNotEmpty(); + assertThat(extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody().getDetails()) + .isNotEmpty(); }); } @@ -151,8 +153,8 @@ public class ReactiveHealthEndpointWebExtensionTests { .run((context) -> { ReactiveHealthEndpointWebExtension extension = context .getBean(ReactiveHealthEndpointWebExtension.class); - assertThat(extension.health(null).block().getBody().getDetails()) - .isNotEmpty(); + assertThat(extension.health(null).block(Duration.ofSeconds(30)) + .getBody().getDetails()).isNotEmpty(); }); } @@ -164,8 +166,9 @@ public class ReactiveHealthEndpointWebExtensionTests { ReactiveHealthEndpointWebExtension extension = context .getBean(ReactiveHealthEndpointWebExtension.class); SecurityContext securityContext = mock(SecurityContext.class); - assertThat(extension.health(securityContext).block().getBody() - .getDetails()).isEmpty(); + assertThat(extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody().getDetails()) + .isEmpty(); }); } @@ -180,8 +183,9 @@ public class ReactiveHealthEndpointWebExtensionTests { given(securityContext.getPrincipal()) .willReturn(mock(Principal.class)); given(securityContext.isUserInRole("ACTUATOR")).willReturn(false); - assertThat(extension.health(securityContext).block().getBody() - .getDetails()).isEmpty(); + assertThat(extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody().getDetails()) + .isEmpty(); }); } @@ -196,8 +200,9 @@ public class ReactiveHealthEndpointWebExtensionTests { given(securityContext.getPrincipal()) .willReturn(mock(Principal.class)); given(securityContext.isUserInRole("ACTUATOR")).willReturn(true); - assertThat(extension.health(securityContext).block().getBody() - .getDetails()).isNotEmpty(); + assertThat(extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody().getDetails()) + .isNotEmpty(); }); } @@ -212,8 +217,9 @@ public class ReactiveHealthEndpointWebExtensionTests { given(securityContext.getPrincipal()) .willReturn(mock(Principal.class)); given(securityContext.isUserInRole("ADMIN")).willReturn(true); - assertThat(extension.health(securityContext).block().getBody() - .getDetails()).isNotEmpty(); + assertThat(extension.health(securityContext) + .block(Duration.ofSeconds(30)).getBody().getDetails()) + .isNotEmpty(); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequestTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequestTests.java index 52cd393267..5597015697 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequestTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequestTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.security.reactive; +import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -250,8 +251,8 @@ public class EndpointRequestTests { } private void matches(ServerWebExchange exchange) { - assertThat(this.matcher.matches(exchange).block().isMatch()) - .as("Matches " + getRequestPath(exchange)).isTrue(); + assertThat(this.matcher.matches(exchange).block(Duration.ofSeconds(30)) + .isMatch()).as("Matches " + getRequestPath(exchange)).isTrue(); } void doesNotMatch(String path) { @@ -262,8 +263,9 @@ public class EndpointRequestTests { } private void doesNotMatch(ServerWebExchange exchange) { - assertThat(this.matcher.matches(exchange).block().isMatch()) - .as("Does not match " + getRequestPath(exchange)).isFalse(); + assertThat(this.matcher.matches(exchange).block(Duration.ofSeconds(30)) + .isMatch()).as("Does not match " + getRequestPath(exchange)) + .isFalse(); } private TestHttpWebHandlerAdapter webHandler() { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingTests.java index daf13f0681..620868e4c9 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.endpoint.web.reactive; +import java.time.Duration; import java.util.Arrays; import org.junit.Rule; @@ -99,7 +100,8 @@ public class ControllerEndpointHandlerMappingTests { private Object getHandler(ControllerEndpointHandlerMapping mapping, HttpMethod method, String requestURI) { - return mapping.getHandler(exchange(method, requestURI)).block(); + return mapping.getHandler(exchange(method, requestURI)) + .block(Duration.ofSeconds(30)); } private ControllerEndpointHandlerMapping createMapping(String prefix, diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilterTests.java index f082257831..3b894632d9 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilterTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.actuate.metrics.web.reactive.server; +import java.time.Duration; + import io.micrometer.core.instrument.MockClock; import io.micrometer.core.instrument.simple.SimpleConfig; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -58,7 +60,7 @@ public class MetricsWebFilterTests { this.webFilter .filter(exchange, (serverWebExchange) -> exchange.getResponse().setComplete()) - .block(); + .block(Duration.ofSeconds(30)); assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("status", "200"); } @@ -74,7 +76,7 @@ public class MetricsWebFilterTests { .onErrorResume((t) -> { exchange.getResponse().setStatusCodeValue(500); return exchange.getResponse().setComplete(); - }).block(); + }).block(Duration.ofSeconds(30)); assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("status", "500"); assertMetricsContainsTag("exception", "IllegalStateException"); @@ -91,7 +93,7 @@ public class MetricsWebFilterTests { .onErrorResume((t) -> { exchange.getResponse().setStatusCodeValue(500); return exchange.getResponse().setComplete(); - }).block(); + }).block(Duration.ofSeconds(30)); assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("status", "500"); assertMetricsContainsTag("exception", anonymous.getClass().getName()); @@ -105,7 +107,7 @@ public class MetricsWebFilterTests { exchange.getResponse().setStatusCodeValue(500); return exchange.getResponse().setComplete() .then(Mono.error(new IllegalStateException("test error"))); - }).onErrorResume((t) -> Mono.empty()).block(); + }).onErrorResume((t) -> Mono.empty()).block(Duration.ofSeconds(30)); assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("status", "500"); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java index 0750ff908b..2bc1890bf3 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.actuate.trace.http.reactive; import java.io.IOException; import java.security.Principal; +import java.time.Duration; import java.util.EnumSet; import javax.servlet.ServletException; @@ -68,7 +69,7 @@ public class HttpTraceWebFilterTests { return Mono.empty(); } - }).block(); + }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); } @@ -82,11 +83,12 @@ public class HttpTraceWebFilterTests { @Override public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block().getAttributes().put("a", "alpha"); + exchange.getSession().block(Duration.ofSeconds(30)) + .getAttributes().put("a", "alpha"); return Mono.empty(); } - }).block(); + }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); Session session = this.repository.findAll().get(0).getSession(); assertThat(session).isNotNull(); @@ -103,11 +105,11 @@ public class HttpTraceWebFilterTests { @Override public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block(); + exchange.getSession().block(Duration.ofSeconds(30)); return Mono.empty(); } - }).block(); + }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); Session session = this.repository.findAll().get(0).getSession(); assertThat(session).isNull(); @@ -129,11 +131,12 @@ public class HttpTraceWebFilterTests { @Override public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block().getAttributes().put("a", "alpha"); + exchange.getSession().block(Duration.ofSeconds(30)).getAttributes() + .put("a", "alpha"); return Mono.empty(); } - }).block(); + }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository .findAll().get(0).getPrincipal(); @@ -155,7 +158,7 @@ public class HttpTraceWebFilterTests { return Mono.error(new RuntimeException()); } - }).block(); + }).block(Duration.ofSeconds(30)); fail(); } catch (Exception ex) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java index e2572a37bd..4e8e3cff66 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.freemarker; import java.io.StringWriter; +import java.time.Duration; import java.util.Locale; import org.junit.Test; @@ -60,7 +61,8 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { public void defaultViewResolution() { this.contextRunner.run((context) -> { MockServerWebExchange exchange = render(context, "home"); - String result = exchange.getResponse().getBodyAsString().block(); + String result = exchange.getResponse().getBodyAsString() + .block(Duration.ofSeconds(30)); assertThat(result).contains("home"); assertThat(exchange.getResponse().getHeaders().getContentType()) .isEqualTo(MediaType.TEXT_HTML); @@ -72,7 +74,8 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { this.contextRunner.withPropertyValues("spring.freemarker.prefix:prefix/") .run((context) -> { MockServerWebExchange exchange = render(context, "prefixed"); - String result = exchange.getResponse().getBodyAsString().block(); + String result = exchange.getResponse().getBodyAsString() + .block(Duration.ofSeconds(30)); assertThat(result).contains("prefixed"); }); } @@ -82,7 +85,8 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { this.contextRunner.withPropertyValues("spring.freemarker.suffix:.freemarker") .run((context) -> { MockServerWebExchange exchange = render(context, "suffixed"); - String result = exchange.getResponse().getBodyAsString().block(); + String result = exchange.getResponse().getBodyAsString() + .block(Duration.ofSeconds(30)); assertThat(result).contains("suffixed"); }); } @@ -93,7 +97,8 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { "spring.freemarker.templateLoaderPath:classpath:/custom-templates/") .run((context) -> { MockServerWebExchange exchange = render(context, "custom"); - String result = exchange.getResponse().getBodyAsString().block(); + String result = exchange.getResponse().getBodyAsString() + .block(Duration.ofSeconds(30)); assertThat(result).contains("custom"); }); } @@ -128,7 +133,8 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { Mono view = resolver.resolveViewName(viewName, Locale.UK); MockServerWebExchange exchange = MockServerWebExchange .from(MockServerHttpRequest.get("/path")); - view.flatMap((v) -> v.render(null, MediaType.TEXT_HTML, exchange)).block(); + view.flatMap((v) -> v.render(null, MediaType.TEXT_HTML, exchange)) + .block(Duration.ofSeconds(30)); return exchange; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java index 3c5288e645..7dfeeb07f9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.security.reactive; +import java.time.Duration; + import org.junit.Test; import reactor.core.publisher.Mono; @@ -55,8 +57,8 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests { .run((context) -> { ReactiveUserDetailsService userDetailsService = context .getBean(ReactiveUserDetailsService.class); - assertThat(userDetailsService.findByUsername("user").block()) - .isNotNull(); + assertThat(userDetailsService.findByUsername("user") + .block(Duration.ofSeconds(30))).isNotNull(); }); } @@ -67,12 +69,12 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests { .run((context) -> { ReactiveUserDetailsService userDetailsService = context .getBean(ReactiveUserDetailsService.class); - assertThat(userDetailsService.findByUsername("user").block()) - .isNull(); - assertThat(userDetailsService.findByUsername("foo").block()) - .isNotNull(); - assertThat(userDetailsService.findByUsername("admin").block()) - .isNotNull(); + assertThat(userDetailsService.findByUsername("user") + .block(Duration.ofSeconds(30))).isNull(); + assertThat(userDetailsService.findByUsername("foo") + .block(Duration.ofSeconds(30))).isNotNull(); + assertThat(userDetailsService.findByUsername("admin") + .block(Duration.ofSeconds(30))).isNotNull(); }); } @@ -93,8 +95,8 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests { .run(((context) -> { MapReactiveUserDetailsService userDetailsService = context .getBean(MapReactiveUserDetailsService.class); - String password = userDetailsService.findByUsername("user").block() - .getPassword(); + String password = userDetailsService.findByUsername("user") + .block(Duration.ofSeconds(30)).getPassword(); assertThat(password).startsWith("{noop}"); })); } @@ -122,8 +124,8 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests { .run(((context) -> { MapReactiveUserDetailsService userDetailsService = context .getBean(MapReactiveUserDetailsService.class); - String password = userDetailsService.findByUsername("user").block() - .getPassword(); + String password = userDetailsService.findByUsername("user") + .block(Duration.ofSeconds(30)).getPassword(); assertThat(password).isEqualTo(expectedPassword); })); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequestTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequestTests.java index ca02bc9428..d77366a89f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequestTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequestTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.security.reactive; +import java.time.Duration; + import org.assertj.core.api.AssertDelegateTarget; import org.junit.Rule; import org.junit.Test; @@ -116,8 +118,8 @@ public class StaticResourceRequestTests { } private void matches(ServerWebExchange exchange) { - assertThat(this.matcher.matches(exchange).block().isMatch()) - .as("Matches " + getRequestPath(exchange)).isTrue(); + assertThat(this.matcher.matches(exchange).block(Duration.ofSeconds(30)) + .isMatch()).as("Matches " + getRequestPath(exchange)).isTrue(); } void doesNotMatch(String path) { @@ -128,8 +130,9 @@ public class StaticResourceRequestTests { } private void doesNotMatch(ServerWebExchange exchange) { - assertThat(this.matcher.matches(exchange).block().isMatch()) - .as("Does not match " + getRequestPath(exchange)).isFalse(); + assertThat(this.matcher.matches(exchange).block(Duration.ofSeconds(30)) + .isMatch()).as("Does not match " + getRequestPath(exchange)) + .isFalse(); } private TestHttpWebHandlerAdapter webHandler() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java index 90d0a85bca..f2c5391118 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientAutoConfigurationTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.web.reactive.function.client; import java.net.URI; +import java.time.Duration; import org.junit.Test; import reactor.core.publisher.Mono; @@ -108,8 +109,10 @@ public class WebClientAutoConfigurationTests { secondBuilder.clientConnector(secondConnector) .baseUrl("http://second.example.org"); assertThat(firstBuilder).isNotEqualTo(secondBuilder); - firstBuilder.build().get().uri("/foo").exchange().block(); - secondBuilder.build().get().uri("/foo").exchange().block(); + firstBuilder.build().get().uri("/foo").exchange() + .block(Duration.ofSeconds(30)); + secondBuilder.build().get().uri("/foo").exchange() + .block(Duration.ofSeconds(30)); verify(firstConnector).connect(eq(HttpMethod.GET), eq(URI.create("http://first.example.org/foo")), any()); verify(secondConnector).connect(eq(HttpMethod.GET), diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java index 29f15663f6..52a33cba59 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestReactiveIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.data.mongo; +import java.time.Duration; + import org.junit.Test; import org.junit.runner.RunWith; @@ -44,10 +46,11 @@ public class DataMongoTestReactiveIntegrationTests { public void testRepository() { ExampleDocument exampleDocument = new ExampleDocument(); exampleDocument.setText("Look, new @DataMongoTest!"); - exampleDocument = this.exampleRepository.save(exampleDocument).block(); + exampleDocument = this.exampleRepository.save(exampleDocument) + .block(Duration.ofSeconds(30)); assertThat(exampleDocument.getId()).isNotNull(); - assertThat(this.mongoTemplate.collectionExists("exampleDocuments").block()) - .isTrue(); + assertThat(this.mongoTemplate.collectionExists("exampleDocuments") + .block(Duration.ofSeconds(30))).isTrue(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java index ace65c1f85..4f549af320 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.time.Duration; import java.util.Arrays; import io.undertow.Undertow; @@ -114,7 +115,7 @@ public class UndertowReactiveWebServerFactoryTests Mono result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromObject("Hello World")).exchange() .flatMap((response) -> response.bodyToMono(String.class)); - assertThat(result.block()).isEqualTo("Hello World"); + assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World"); File accessLog = new File(accessLogDirectory, expectedFile); awaitFile(accessLog); assertThat(accessLogDirectory.listFiles()).contains(accessLog); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewResolverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewResolverTests.java index 62db939bfd..f688ccfb87 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewResolverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.boot.web.reactive.result.view; +import java.time.Duration; + import org.junit.Before; import org.junit.Test; @@ -46,12 +48,15 @@ public class MustacheViewResolverTests { @Test public void resolveNonExistent() { - assertThat(this.resolver.resolveViewName("bar", null).block()).isNull(); + assertThat( + this.resolver.resolveViewName("bar", null).block(Duration.ofSeconds(30))) + .isNull(); } @Test public void resolveExisting() { - assertThat(this.resolver.resolveViewName("template", null).block()).isNotNull(); + assertThat(this.resolver.resolveViewName("template", null) + .block(Duration.ofSeconds(30))).isNotNull(); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java index 93ceb0a9fe..05b5030443 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.web.reactive.result.view; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.Collections; import com.samskivert.mustache.Mustache; @@ -59,9 +60,9 @@ public class MustacheViewTests { view.setCharset(StandardCharsets.UTF_8.displayName()); view.setApplicationContext(this.context); view.render(Collections.singletonMap("World", "Spring"), MediaType.TEXT_HTML, - this.exchange).block(); - assertThat(this.exchange.getResponse().getBodyAsString().block()) - .isEqualTo("Hello Spring"); + this.exchange).block(Duration.ofSeconds(30)); + assertThat(this.exchange.getResponse().getBodyAsString() + .block(Duration.ofSeconds(30))).isEqualTo("Hello Spring"); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index 6fa3cc46f5..22bd1d5330 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -102,7 +102,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { .contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromObject("Hello World")).exchange() .flatMap((response) -> response.bodyToMono(String.class)); - assertThat(result.block()).isEqualTo("Hello World"); + assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World"); assertThat(this.webServer.getPort()).isEqualTo(specificPort); } @@ -131,7 +131,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { Mono result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromObject("Hello World")).exchange() .flatMap((response) -> response.bodyToMono(String.class)); - assertThat(result.block()).isEqualTo("Hello World"); + assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World"); } protected ReactorClientHttpConnector buildTrustAllSslConnector() { @@ -187,7 +187,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { Mono result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromObject("Hello World")).exchange() .flatMap((response) -> response.bodyToMono(String.class)); - assertThat(result.block()).isEqualTo("Hello World"); + assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World"); } @Test @@ -245,7 +245,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { public void compressionOfResponseToGetRequest() { WebClient client = prepareCompressionTest(); ResponseEntity response = client.get().exchange() - .flatMap((res) -> res.toEntity(Void.class)).block(); + .flatMap((res) -> res.toEntity(Void.class)).block(Duration.ofSeconds(30)); assertResponseIsCompressed(response); } @@ -253,7 +253,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { public void compressionOfResponseToPostRequest() { WebClient client = prepareCompressionTest(); ResponseEntity response = client.post().exchange() - .flatMap((res) -> res.toEntity(Void.class)).block(); + .flatMap((res) -> res.toEntity(Void.class)).block(Duration.ofSeconds(30)); assertResponseIsCompressed(response); } @@ -264,7 +264,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { compression.setMinResponseSize(3001); WebClient client = prepareCompressionTest(compression); ResponseEntity response = client.get().exchange() - .flatMap((res) -> res.toEntity(Void.class)).block(); + .flatMap((res) -> res.toEntity(Void.class)).block(Duration.ofSeconds(30)); assertResponseIsNotCompressed(response); } @@ -274,7 +274,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { compression.setMimeTypes(new String[] { "application/json" }); WebClient client = prepareCompressionTest(compression); ResponseEntity response = client.get().exchange() - .flatMap((res) -> res.toEntity(Void.class)).block(); + .flatMap((res) -> res.toEntity(Void.class)).block(Duration.ofSeconds(30)); assertResponseIsNotCompressed(response); } @@ -285,7 +285,8 @@ public abstract class AbstractReactiveWebServerFactoryTests { compression.setExcludedUserAgents(new String[] { "testUserAgent" }); WebClient client = prepareCompressionTest(compression); ResponseEntity response = client.get().header("User-Agent", "testUserAgent") - .exchange().flatMap((res) -> res.toEntity(Void.class)).block(); + .exchange().flatMap((res) -> res.toEntity(Void.class)) + .block(Duration.ofSeconds(30)); assertResponseIsNotCompressed(response); } diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java index d58c4210f2..3fbc4c9fb2 100644 --- a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java @@ -16,6 +16,7 @@ package sample.session; +import java.time.Duration; import java.util.Base64; import org.junit.Test; @@ -52,17 +53,19 @@ public class SampleSessionWebFluxApplicationTests { WebClient webClient = this.webClientBuilder .baseUrl("http://localhost:" + this.port + "/").build(); ClientResponse response = webClient.get().header("Authorization", getBasicAuth()) - .exchange().block(); + .exchange().block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); ResponseCookie sessionCookie = response.cookies().getFirst("SESSION"); - String sessionId = response.bodyToMono(String.class).block(); + String sessionId = response.bodyToMono(String.class) + .block(Duration.ofSeconds(30)); response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange() - .block(); + .block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.bodyToMono(String.class).block()).isEqualTo(sessionId); + assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))) + .isEqualTo(sessionId); Thread.sleep(2000); response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange() - .block(); + .block(Duration.ofSeconds(30)); assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }