|
30 | 30 | import org.springframework.mock.web.MockHttpServletResponse;
|
31 | 31 |
|
32 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
| 33 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
33 | 34 | import static org.mockito.ArgumentMatchers.any;
|
34 | 35 | import static org.mockito.BDDMockito.given;
|
| 36 | +import static org.mockito.BDDMockito.willThrow; |
35 | 37 | import static org.mockito.Mockito.mock;
|
36 | 38 | import static org.mockito.Mockito.times;
|
37 | 39 | import static org.mockito.Mockito.verify;
|
@@ -87,4 +89,21 @@ void decorateFiltersWhenDefaultsThenObserves() throws Exception {
|
87 | 89 | assertThat(events.get(1).getName()).isEqualTo(filter.getClass().getSimpleName() + ".after");
|
88 | 90 | }
|
89 | 91 |
|
| 92 | + // gh-12787 |
| 93 | + @Test |
| 94 | + void decorateFiltersWhenErrorsThenClosesObservationOnlyOnce() throws Exception { |
| 95 | + ObservationHandler<?> handler = mock(ObservationHandler.class); |
| 96 | + given(handler.supportsContext(any())).willReturn(true); |
| 97 | + ObservationRegistry registry = ObservationRegistry.create(); |
| 98 | + registry.observationConfig().observationHandler(handler); |
| 99 | + ObservationFilterChainDecorator decorator = new ObservationFilterChainDecorator(registry); |
| 100 | + FilterChain chain = mock(FilterChain.class); |
| 101 | + Filter filter = mock(Filter.class); |
| 102 | + willThrow(IllegalArgumentException.class).given(filter).doFilter(any(), any(), any()); |
| 103 | + FilterChain decorated = decorator.decorate(chain, List.of(filter)); |
| 104 | + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( |
| 105 | + () -> decorated.doFilter(new MockHttpServletRequest("GET", "/"), new MockHttpServletResponse())); |
| 106 | + verify(handler).onScopeClosed(any()); |
| 107 | + } |
| 108 | + |
90 | 109 | }
|
0 commit comments