Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ public CompletableResultCode shutdown() {
if (managedExecutor) {
executorService.shutdown();
}
if (AutoCloseable.class.isInstance(client)) {
try {
AutoCloseable.class.cast(client).close();
} catch (Exception e) {
return CompletableResultCode.ofExceptionalFailure(e);
}
}
return CompletableResultCode.ofSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.exporter.internal.marshal.Serializer;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.export.RetryPolicy;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.ConnectException;
import java.net.ServerSocket;
import java.net.http.HttpClient;
Expand All @@ -29,6 +31,7 @@
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -66,6 +69,33 @@ void setup() throws IOException, InterruptedException {
null);
}

@Test
@EnabledForJreRange(
minVersion = 21,
disabledReason = "HttpClient#close has been added in Java 21")
void testShutdown() throws Exception {
CompletableResultCode result = sender.shutdown();
result.join(1, TimeUnit.SECONDS);
assertThat(result.isSuccess()).isTrue();
Method close = HttpClient.class.getMethod("close");
close.invoke(verify(mockHttpClient));
}

@Test
@EnabledForJreRange(
minVersion = 21,
disabledReason = "HttpClient#close has been added in Java 21")
void testShutdownException() throws Exception {
Method close = HttpClient.class.getMethod("close");
close.invoke(doThrow(new RuntimeException("testShutdownException")).when(mockHttpClient));

CompletableResultCode result = sender.shutdown();
result.join(1, TimeUnit.SECONDS);
assertThat(result.isSuccess()).isFalse();
assertThat(result.getFailureThrowable()).isInstanceOf(RuntimeException.class);
assertThat(result.getFailureThrowable().getMessage()).isEqualTo("testShutdownException");
}

@Test
void sendInternal_RetryableConnectTimeoutException() throws IOException, InterruptedException {
assertThatThrownBy(() -> sender.sendInternal(new NoOpMarshaler()))
Expand Down
Loading