Improve handling of non-standard status codes in RestTemplate metrics

See gh-17991
This commit is contained in:
Johnny Lim
2019-08-29 12:24:22 +09:00
committed by Andy Wilkinson
parent 7f8b3a7b86
commit 1acff410a2
4 changed files with 42 additions and 23 deletions

View File

@@ -81,7 +81,7 @@ class RestTemplateExchangeTagsTests {
@Test
void outcomeTagIsUnknownWhenResponseThrowsIOException() throws Exception {
ClientHttpResponse response = mock(ClientHttpResponse.class);
given(response.getStatusCode()).willThrow(IOException.class);
given(response.getRawStatusCode()).willThrow(IOException.class);
Tag tag = RestTemplateExchangeTags.outcome(response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@@ -89,7 +89,23 @@ class RestTemplateExchangeTagsTests {
@Test
void outcomeTagIsUnknownForCustomResponseStatus() throws Exception {
ClientHttpResponse response = mock(ClientHttpResponse.class);
given(response.getStatusCode()).willThrow(IllegalArgumentException.class);
given(response.getRawStatusCode()).willThrow(IllegalArgumentException.class);
Tag tag = RestTemplateExchangeTags.outcome(response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@Test
void outcomeTagIsClientErrorWhenResponseIsNonStandardInKnownSeries() throws IOException {
ClientHttpResponse response = mock(ClientHttpResponse.class);
given(response.getRawStatusCode()).willReturn(490);
Tag tag = RestTemplateExchangeTags.outcome(response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
@Test
void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() throws IOException {
ClientHttpResponse response = mock(ClientHttpResponse.class);
given(response.getRawStatusCode()).willReturn(701);
Tag tag = RestTemplateExchangeTags.outcome(response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}

View File

@@ -148,7 +148,7 @@ class WebClientExchangeTagsTests {
}
@Test
void outcomeTagIsServerErrorWhenResponseIsNonStandardInKnownSeries() {
void outcomeTagIsClientErrorWhenResponseIsNonStandardInKnownSeries() {
given(this.response.rawStatusCode()).willReturn(490);
Tag tag = WebClientExchangeTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");