Skip to content

Commit 092aadb

Browse files
add an additional test
1 parent dead127 commit 092aadb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.time.Duration;
1818
import java.util.Collections;
1919
import java.util.Set;
20+
import java.util.concurrent.ExecutorService;
21+
import java.util.concurrent.Executors;
2022
import okhttp3.MediaType;
2123
import okhttp3.Protocol;
2224
import okhttp3.Request;
@@ -107,6 +109,40 @@ void shutdown_CompletableResultCodeShouldWaitForThreads() throws Exception {
107109
assertTrue(shutdownResult.isSuccess(), "Shutdown should complete successfully");
108110
}
109111

112+
@Test
113+
void shutdown_NonManagedExecutor_ReturnsImmediately() {
114+
// This test verifies that when using a non-managed executor (custom ExecutorService),
115+
// shutdown() returns an already-completed CompletableResultCode immediately.
116+
117+
// Create a custom ExecutorService - this makes the executor non-managed
118+
ExecutorService customExecutor = Executors.newSingleThreadExecutor();
119+
120+
try {
121+
OkHttpGrpcSender<TestMarshaler> sender =
122+
new OkHttpGrpcSender<>(
123+
"http://localhost:8080",
124+
null,
125+
Duration.ofSeconds(10).toNanos(),
126+
Duration.ofSeconds(10).toNanos(),
127+
Collections::emptyMap,
128+
null,
129+
null,
130+
null,
131+
customExecutor); // Pass custom executor -> managedExecutor = false
132+
133+
CompletableResultCode shutdownResult = sender.shutdown();
134+
135+
// Should complete immediately since executor is not managed
136+
assertTrue(
137+
shutdownResult.isDone(),
138+
"CompletableResultCode should be done immediately for non-managed executor");
139+
assertTrue(shutdownResult.isSuccess(), "Shutdown should complete successfully");
140+
} finally {
141+
// Clean up the custom executor
142+
customExecutor.shutdownNow();
143+
}
144+
}
145+
110146
/** Simple test marshaler for testing purposes. */
111147
private static class TestMarshaler extends Marshaler {
112148
@Override

0 commit comments

Comments
 (0)