|
16 | 16 |
|
17 | 17 | import io.opentelemetry.exporter.internal.marshal.Marshaler;
|
18 | 18 | import io.opentelemetry.exporter.internal.marshal.Serializer;
|
| 19 | +import io.opentelemetry.sdk.common.CompletableResultCode; |
19 | 20 | import io.opentelemetry.sdk.common.export.RetryPolicy;
|
20 | 21 | import java.io.IOException;
|
| 22 | +import java.lang.reflect.Method; |
21 | 23 | import java.net.ConnectException;
|
22 | 24 | import java.net.ServerSocket;
|
23 | 25 | import java.net.http.HttpClient;
|
|
29 | 31 | import org.assertj.core.api.InstanceOfAssertFactories;
|
30 | 32 | import org.junit.jupiter.api.BeforeEach;
|
31 | 33 | import org.junit.jupiter.api.Test;
|
| 34 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
32 | 35 | import org.junit.jupiter.api.extension.ExtendWith;
|
33 | 36 | import org.mockito.Mock;
|
34 | 37 | import org.mockito.junit.jupiter.MockitoExtension;
|
@@ -66,6 +69,33 @@ void setup() throws IOException, InterruptedException {
|
66 | 69 | null);
|
67 | 70 | }
|
68 | 71 |
|
| 72 | + @Test |
| 73 | + @EnabledForJreRange( |
| 74 | + minVersion = 21, |
| 75 | + disabledReason = "HttpClient#close has been added in Java 21") |
| 76 | + void testShutdown() throws Exception { |
| 77 | + CompletableResultCode result = sender.shutdown(); |
| 78 | + result.join(1, TimeUnit.SECONDS); |
| 79 | + assertThat(result.isSuccess()).isTrue(); |
| 80 | + Method close = HttpClient.class.getMethod("close"); |
| 81 | + close.invoke(verify(mockHttpClient)); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + @EnabledForJreRange( |
| 86 | + minVersion = 21, |
| 87 | + disabledReason = "HttpClient#close has been added in Java 21") |
| 88 | + void testShutdownException() throws Exception { |
| 89 | + Method close = HttpClient.class.getMethod("close"); |
| 90 | + close.invoke(doThrow(new RuntimeException("testShutdownException")).when(mockHttpClient)); |
| 91 | + |
| 92 | + CompletableResultCode result = sender.shutdown(); |
| 93 | + result.join(1, TimeUnit.SECONDS); |
| 94 | + assertThat(result.isSuccess()).isFalse(); |
| 95 | + assertThat(result.getFailureThrowable()).isInstanceOf(RuntimeException.class); |
| 96 | + assertThat(result.getFailureThrowable().getMessage()).isEqualTo("testShutdownException"); |
| 97 | + } |
| 98 | + |
69 | 99 | @Test
|
70 | 100 | void sendInternal_RetryableConnectTimeoutException() throws IOException, InterruptedException {
|
71 | 101 | assertThatThrownBy(() -> sender.sendInternal(new NoOpMarshaler()))
|
|
0 commit comments