Skip to content

Commit

Permalink
Merge branch '2.0.x' into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Dec 20, 2018
2 parents 84a064a + 8c68da0 commit 9a33d1a
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +65,8 @@ public void healthDetailsAlwaysPresent() {
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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,16 +199,17 @@ public void cloudFoundryPathsIgnoredBySpringSecurity() {
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();
});

Expand Down Expand Up @@ -312,7 +314,7 @@ public void skipSslValidation() {
WebClient webClient = (WebClient) ReflectionTestUtils
.getField(interceptorSecurityService, "webClient");
webClient.get().uri("https://self-signed.badssl.com/").exchange()
.block();
.block(Duration.ofSeconds(30));
});
}

Expand All @@ -334,9 +336,9 @@ public void sslValidationNotSkippedByDefault() {
WebClient webClient = (WebClient) ReflectionTestUtils
.getField(interceptorSecurityService, "webClient");
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(
webClient.get().uri("https://self-signed.badssl.com/")
.exchange()::block)
.isThrownBy(() -> webClient.get()
.uri("https://self-signed.badssl.com/").exchange()
.block(Duration.ofSeconds(30)))
.withCauseInstanceOf(SSLException.class);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,8 +99,8 @@ public void regularAndReactiveHealthIndicatorsMatch() {
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())
Expand All @@ -112,8 +113,8 @@ public void unauthenticatedUsersAreNotShownDetailsByDefault() {
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();
});
}

Expand All @@ -124,8 +125,8 @@ public void authenticatedUsersAreNotShownDetailsByDefault() {
.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();
});
}

Expand All @@ -140,8 +141,9 @@ public void authenticatedUsersWhenAuthorizedCanBeShownDetails() {
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();
});
}

Expand All @@ -152,8 +154,8 @@ public void unauthenticatedUsersCanBeShownDetails() {
.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();
});
}

Expand All @@ -165,8 +167,9 @@ public void detailsCanBeHiddenFromAuthenticatedUsers() {
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();
});
}

Expand All @@ -181,8 +184,9 @@ public void detailsCanBeHiddenFromUnauthorizedUsers() {
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();
});
}

Expand All @@ -197,8 +201,9 @@ public void detailsCanBeShownToAuthorizedUsers() {
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();
});
}

Expand All @@ -213,8 +218,9 @@ public void roleCanBeCustomized() {
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();
});
}

Expand All @@ -227,11 +233,12 @@ public void registryCanBeAltered() {
.getBean(ReactiveHealthIndicatorRegistry.class);
ReactiveHealthEndpointWebExtension extension = context
.getBean(ReactiveHealthEndpointWebExtension.class);
assertThat(extension.health(null).block().getBody().getDetails())
.containsOnlyKeys("application", "first", "second");
assertThat(extension.health(null).block(Duration.ofSeconds(30))
.getBody().getDetails()).containsOnlyKeys("application",
"first", "second");
assertThat(registry.unregister("second")).isNotNull();
assertThat(extension.health(null).block().getBody().getDetails())
.containsKeys("application", "first");
assertThat(extension.health(null).block(Duration.ofSeconds(30))
.getBody().getDetails()).containsKeys("application", "first");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.actuate.autoconfigure.metrics.web.client;

import java.time.Duration;

import io.micrometer.core.instrument.MeterRegistry;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -106,7 +108,8 @@ private MeterRegistry getInitializedMeterRegistry(
WebClient webClient = mockWebClient(context.getBean(WebClient.Builder.class));
MeterRegistry registry = context.getBean(MeterRegistry.class);
for (int i = 0; i < 3; i++) {
webClient.get().uri("http://example.org/projects/" + i).exchange().block();
webClient.get().uri("http://example.org/projects/" + i).exchange()
.block(Duration.ofSeconds(30));
}
return registry;
}
Expand All @@ -115,7 +118,7 @@ private void validateWebClient(WebClient.Builder builder, MeterRegistry registry
WebClient webClient = mockWebClient(builder);
assertThat(registry.find("http.client.requests").meter()).isNull();
webClient.get().uri("http://example.org/projects/{project}", "spring-boot")
.exchange().block();
.exchange().block(Duration.ofSeconds(30));
assertThat(registry.find("http.client.requests")
.tags("uri", "/projects/{project}").meter()).isNotNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.actuate.autoconfigure.security.reactive;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -250,8 +251,8 @@ void matches(String path) {
}

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) {
Expand All @@ -262,8 +263,9 @@ void doesNotMatch(String path) {
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.security.reactive;

import java.net.URI;
import java.time.Duration;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -139,7 +140,8 @@ private ServerWebExchange performFilter(
ServerWebExchange exchange = webHandler(context).createExchange(
MockServerHttpRequest.get(path).build(), new MockServerHttpResponse());
WebFilterChainProxy proxy = context.getBean(WebFilterChainProxy.class);
proxy.filter(exchange, (serverWebExchange) -> Mono.empty()).block();
proxy.filter(exchange, (serverWebExchange) -> Mono.empty())
.block(Duration.ofSeconds(30));
return exchange;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.boot.actuate.couchbase;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -52,7 +53,7 @@ ServiceType.BINARY, LifecycleState.CONNECTED, new InetSocketAddress(0),
DiagnosticsReport diagnostics = new DiagnosticsReport(endpoints, "test-sdk",
"test-id", null);
given(cluster.diagnostics()).willReturn(diagnostics);
Health health = healthIndicator.health().block();
Health health = healthIndicator.health().block(Duration.ofSeconds(30));
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("sdk", "test-sdk");
assertThat(health.getDetails()).containsKey("endpoints");
Expand All @@ -77,7 +78,7 @@ public void couchbaseClusterIsDown() {
DiagnosticsReport diagnostics = new DiagnosticsReport(endpoints, "test-sdk",
"test-id", null);
given(cluster.diagnostics()).willReturn(diagnostics);
Health health = healthIndicator.health().block();
Health health = healthIndicator.health().block(Duration.ofSeconds(30));
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsEntry("sdk", "test-sdk");
assertThat(health.getDetails()).containsKey("endpoints");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.actuate.endpoint.web.reactive;

import java.time.Duration;
import java.util.Arrays;

import org.junit.Test;
Expand Down Expand Up @@ -95,7 +96,8 @@ public void mappingNarrowedToMethod() throws Exception {

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void filterShouldRecordTimer() {
ClientRequest request = ClientRequest.create(HttpMethod.GET,
URI.create("http://example.com/projects/spring-boot")).build();
given(this.response.statusCode()).willReturn(HttpStatus.OK);
this.filterFunction.filter(request, this.exchange).block();
this.filterFunction.filter(request, this.exchange).block(Duration.ofSeconds(30));
assertThat(this.registry.get("http.client.requests")
.tags("method", "GET", "uri", "/projects/spring-boot", "status", "200")
.timer().count()).isEqualTo(1);
Expand All @@ -86,7 +86,7 @@ public void filterWhenUriTemplatePresentShouldRecordTimer() {
URI.create("http://example.com/projects/spring-boot"))
.attribute(URI_TEMPLATE_ATTRIBUTE, "/projects/{project}").build();
given(this.response.statusCode()).willReturn(HttpStatus.OK);
this.filterFunction.filter(request, this.exchange).block();
this.filterFunction.filter(request, this.exchange).block(Duration.ofSeconds(30));
assertThat(this.registry.get("http.client.requests")
.tags("method", "GET", "uri", "/projects/{project}", "status", "200")
.timer().count()).isEqualTo(1);
Expand All @@ -98,7 +98,8 @@ public void filterWhenIoExceptionThrownShouldRecordTimer() {
URI.create("http://example.com/projects/spring-boot")).build();
ExchangeFunction errorExchange = (r) -> Mono.error(new IOException());
this.filterFunction.filter(request, errorExchange)
.onErrorResume(IOException.class, (t) -> Mono.empty()).block();
.onErrorResume(IOException.class, (t) -> Mono.empty())
.block(Duration.ofSeconds(30));
assertThat(
this.registry
.get("http.client.requests").tags("method", "GET", "uri",
Expand All @@ -113,7 +114,7 @@ public void filterWhenExceptionThrownShouldRecordTimer() {
ExchangeFunction exchange = (r) -> Mono.error(new IllegalArgumentException());
this.filterFunction.filter(request, exchange)
.onErrorResume(IllegalArgumentException.class, (t) -> Mono.empty())
.block();
.block(Duration.ofSeconds(30));
assertThat(this.registry
.get("http.client.requests").tags("method", "GET", "uri",
"/projects/spring-boot", "status", "CLIENT_ERROR")
Expand All @@ -128,7 +129,7 @@ public void filterWhenExceptionAndRetryShouldNotCumulateRecordTime() {
.delaySubscription(Duration.ofMillis(300)).cast(ClientResponse.class);
this.filterFunction.filter(request, exchange).retry(1)
.onErrorResume(IllegalArgumentException.class, (t) -> Mono.empty())
.block();
.block(Duration.ofSeconds(30));
Timer timer = this.registry.get("http.client.requests").tags("method", "GET",
"uri", "/projects/spring-boot", "status", "CLIENT_ERROR").timer();
assertThat(timer.count()).isEqualTo(2);
Expand Down
Loading

0 comments on commit 9a33d1a

Please sign in to comment.