|
24 | 24 | import io.micrometer.core.instrument.MeterRegistry;
|
25 | 25 | import io.micrometer.core.instrument.MockClock;
|
26 | 26 | import io.micrometer.core.instrument.Timer;
|
| 27 | +import io.micrometer.core.instrument.search.MeterNotFoundException; |
27 | 28 | import io.micrometer.core.instrument.simple.SimpleConfig;
|
28 | 29 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
29 | 30 | import org.junit.jupiter.api.BeforeEach;
|
|
40 | 41 | import org.springframework.web.reactive.function.client.WebClient;
|
41 | 42 |
|
42 | 43 | import static org.assertj.core.api.Assertions.assertThat;
|
| 44 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
43 | 45 | import static org.mockito.BDDMockito.given;
|
44 | 46 | import static org.mockito.Mockito.mock;
|
45 | 47 |
|
@@ -124,6 +126,23 @@ void filterWhenCancelThrownShouldRecordTimer() {
|
124 | 126 | assertThat(this.registry.get("http.client.requests")
|
125 | 127 | .tags("method", "GET", "uri", "/projects/spring-boot", "status", "CLIENT_ERROR").timer().count())
|
126 | 128 | .isEqualTo(1);
|
| 129 | + assertThatThrownBy(() -> this.registry.get("http.client.requests") |
| 130 | + .tags("method", "GET", "uri", "/projects/spring-boot", "status", "200").timer()) |
| 131 | + .isInstanceOf(MeterNotFoundException.class); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + void filterWhenCancelAfterResponseThrownShouldNotRecordTimer() { |
| 136 | + ClientRequest request = ClientRequest |
| 137 | + .create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot")).build(); |
| 138 | + given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value()); |
| 139 | + Mono<ClientResponse> filter = this.filterFunction.filter(request, this.exchange); |
| 140 | + StepVerifier.create(filter).expectNextCount(1).thenCancel().verify(Duration.ofSeconds(5)); |
| 141 | + assertThat(this.registry.get("http.client.requests") |
| 142 | + .tags("method", "GET", "uri", "/projects/spring-boot", "status", "200").timer().count()).isEqualTo(1); |
| 143 | + assertThatThrownBy(() -> this.registry.get("http.client.requests") |
| 144 | + .tags("method", "GET", "uri", "/projects/spring-boot", "status", "CLIENT_ERROR").timer()) |
| 145 | + .isInstanceOf(MeterNotFoundException.class); |
127 | 146 | }
|
128 | 147 |
|
129 | 148 | @Test
|
|
0 commit comments