Merge branch '2.1.x'

Closes gh-17950
This commit is contained in:
Andy Wilkinson
2019-08-23 20:34:35 +01:00
4 changed files with 46 additions and 29 deletions

View File

@@ -54,7 +54,7 @@ class DefaultWebClientExchangeTagsProviderTests {
this.request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot"))
.attribute(URI_TEMPLATE_ATTRIBUTE, "https://example.org/projects/{project}").build();
this.response = mock(ClientResponse.class);
given(this.response.statusCode()).willReturn(HttpStatus.OK);
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
}
@Test

View File

@@ -72,7 +72,7 @@ class MetricsWebClientFilterFunctionTests {
void filterShouldRecordTimer() {
ClientRequest request = ClientRequest
.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot")).build();
given(this.response.statusCode()).willReturn(HttpStatus.OK);
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
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);
@@ -83,7 +83,7 @@ class MetricsWebClientFilterFunctionTests {
ClientRequest request = ClientRequest
.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot"))
.attribute(URI_TEMPLATE_ATTRIBUTE, "/projects/{project}").build();
given(this.response.statusCode()).willReturn(HttpStatus.OK);
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
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);

View File

@@ -52,7 +52,6 @@ class WebClientExchangeTagsTests {
this.request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot"))
.attribute(URI_TEMPLATE_ATTRIBUTE, "https://example.org/projects/{project}").build();
this.response = mock(ClientResponse.class);
given(this.response.statusCode()).willReturn(HttpStatus.OK);
}
@Test
@@ -86,6 +85,7 @@ class WebClientExchangeTagsTests {
@Test
void status() {
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
assertThat(WebClientExchangeTags.status(this.response)).isEqualTo(Tag.of("status", "200"));
}
@@ -100,6 +100,12 @@ class WebClientExchangeTagsTests {
.isEqualTo(Tag.of("status", "CLIENT_ERROR"));
}
@Test
void statusWhenNonStandard() {
given(this.response.rawStatusCode()).willReturn(490);
assertThat(WebClientExchangeTags.status(this.response)).isEqualTo(Tag.of("status", "490"));
}
@Test
void outcomeTagIsUnknownWhenResponseIsNull() {
Tag tag = WebClientExchangeTags.outcome(null);
@@ -108,42 +114,49 @@ class WebClientExchangeTagsTests {
@Test
void outcomeTagIsInformationalWhenResponseIs1xx() {
given(this.response.statusCode()).willReturn(HttpStatus.CONTINUE);
given(this.response.rawStatusCode()).willReturn(HttpStatus.CONTINUE.value());
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("INFORMATIONAL");
}
@Test
void outcomeTagIsSuccessWhenResponseIs2xx() {
given(this.response.statusCode()).willReturn(HttpStatus.OK);
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("SUCCESS");
}
@Test
void outcomeTagIsRedirectionWhenResponseIs3xx() {
given(this.response.statusCode()).willReturn(HttpStatus.MOVED_PERMANENTLY);
given(this.response.rawStatusCode()).willReturn(HttpStatus.MOVED_PERMANENTLY.value());
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("REDIRECTION");
}
@Test
void outcomeTagIsClientErrorWhenResponseIs4xx() {
given(this.response.statusCode()).willReturn(HttpStatus.BAD_REQUEST);
given(this.response.rawStatusCode()).willReturn(HttpStatus.BAD_REQUEST.value());
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
@Test
void outcomeTagIsServerErrorWhenResponseIs5xx() {
given(this.response.statusCode()).willReturn(HttpStatus.BAD_GATEWAY);
given(this.response.rawStatusCode()).willReturn(HttpStatus.BAD_GATEWAY.value());
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
}
@Test
void outcomeTagIsUnknownWhenResponseStatusIsUnknown() {
given(this.response.statusCode()).willThrow(IllegalArgumentException.class);
void outcomeTagIsServerErrorWhenResponseIsNonStandardInKnownSeries() {
given(this.response.rawStatusCode()).willReturn(490);
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
@Test
void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() {
given(this.response.rawStatusCode()).willReturn(701);
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}