|
9 | 9 | import static org.assertj.core.api.Assertions.assertThat; |
10 | 10 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
11 | 11 |
|
| 12 | +import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; |
12 | 13 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
13 | 14 | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; |
14 | 15 | import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; |
|
26 | 27 | import org.junit.jupiter.api.extension.RegisterExtension; |
27 | 28 | import org.springframework.context.ConfigurableApplicationContext; |
28 | 29 |
|
29 | | -public class SpringWebfluxServerInstrumentationTest |
| 30 | +class SpringWebfluxServerInstrumentationTest |
30 | 31 | extends AbstractHttpServerTest<ConfigurableApplicationContext> { |
31 | 32 |
|
32 | 33 | private static final String CONTEXT_PATH = "/test"; |
33 | 34 |
|
34 | 35 | @RegisterExtension |
35 | 36 | static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forLibrary(); |
36 | 37 |
|
| 38 | + @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); |
| 39 | + |
37 | 40 | @Override |
38 | 41 | protected ConfigurableApplicationContext setupServer() { |
39 | 42 | return TestWebfluxSpringBootApp.start(port, CONTEXT_PATH); |
40 | 43 | } |
41 | 44 |
|
42 | 45 | @Override |
43 | | - public void stopServer(ConfigurableApplicationContext applicationContext) { |
| 46 | + protected void stopServer(ConfigurableApplicationContext applicationContext) { |
44 | 47 | applicationContext.close(); |
45 | 48 | } |
46 | 49 |
|
@@ -79,16 +82,16 @@ void cancelRequest() throws InterruptedException { |
79 | 82 | String method = "GET"; |
80 | 83 | AggregatedHttpRequest request = request(endpoint, method); |
81 | 84 |
|
82 | | - try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) { |
83 | | - CompletableFuture<AggregatedHttpResponse> future = |
84 | | - client.execute(request).aggregate().toCompletableFuture(); |
85 | | - ClientRequestContext clientRequestContext = captor.get(); |
86 | | - Thread.sleep(1_000); |
87 | | - clientRequestContext.cancel(); |
88 | | - assertThatThrownBy(future::join) |
89 | | - .isInstanceOf(CompletionException.class) |
90 | | - .hasMessage(ResponseCancellationException.class.getName()); |
91 | | - } |
| 85 | + ClientRequestContextCaptor captor = Clients.newContextCaptor(); |
| 86 | + cleanup.deferCleanup(captor); |
| 87 | + CompletableFuture<AggregatedHttpResponse> future = |
| 88 | + client.execute(request).aggregate().toCompletableFuture(); |
| 89 | + ClientRequestContext clientRequestContext = captor.get(); |
| 90 | + Thread.sleep(1_000); |
| 91 | + clientRequestContext.cancel(); |
| 92 | + assertThatThrownBy(future::join) |
| 93 | + .isInstanceOf(CompletionException.class) |
| 94 | + .hasMessage(ResponseCancellationException.class.getName()); |
92 | 95 |
|
93 | 96 | assertTheTraces(1, null, null, null, method, endpoint); |
94 | 97 | } |
|
0 commit comments