|
17 | 17 | import java.time.Duration; |
18 | 18 | import java.util.Collections; |
19 | 19 | import java.util.Set; |
| 20 | +import java.util.concurrent.ExecutorService; |
| 21 | +import java.util.concurrent.Executors; |
20 | 22 | import okhttp3.MediaType; |
21 | 23 | import okhttp3.Protocol; |
22 | 24 | import okhttp3.Request; |
@@ -107,6 +109,40 @@ void shutdown_CompletableResultCodeShouldWaitForThreads() throws Exception { |
107 | 109 | assertTrue(shutdownResult.isSuccess(), "Shutdown should complete successfully"); |
108 | 110 | } |
109 | 111 |
|
| 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 | + |
110 | 146 | /** Simple test marshaler for testing purposes. */ |
111 | 147 | private static class TestMarshaler extends Marshaler { |
112 | 148 | @Override |
|
0 commit comments