|
19 | 19 | import static org.mockito.ArgumentMatchers.any;
|
20 | 20 | import static org.mockito.ArgumentMatchers.anyLong;
|
21 | 21 | import static org.mockito.ArgumentMatchers.eq;
|
| 22 | +import static org.mockito.Mockito.doThrow; |
22 | 23 | import static org.mockito.Mockito.mock;
|
23 | 24 | import static org.mockito.Mockito.never;
|
24 | 25 | import static org.mockito.Mockito.times;
|
|
31 | 32 |
|
32 | 33 | import java.time.Duration;
|
33 | 34 | import java.util.concurrent.CompletableFuture;
|
| 35 | +import java.util.concurrent.ExecutorService; |
| 36 | +import java.util.concurrent.RejectedExecutionException; |
34 | 37 | import java.util.concurrent.ScheduledExecutorService;
|
35 | 38 | import java.util.concurrent.ScheduledFuture;
|
36 | 39 | import java.util.concurrent.TimeUnit;
|
|
47 | 50 | import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
|
48 | 51 | import software.amazon.awssdk.core.internal.http.HttpClientDependencies;
|
49 | 52 | import software.amazon.awssdk.core.internal.http.RequestExecutionContext;
|
| 53 | +import software.amazon.awssdk.core.internal.http.TransformingAsyncResponseHandler; |
50 | 54 | import software.amazon.awssdk.core.internal.http.timers.ClientExecutionAndRequestTimerTestUtils;
|
51 | 55 | import software.amazon.awssdk.core.internal.util.AsyncResponseHandlerTestUtils;
|
52 | 56 | import software.amazon.awssdk.http.SdkHttpFullRequest;
|
@@ -152,6 +156,33 @@ public void testExecute_contextContainsMetricCollector_addsChildToExecuteRequest
|
152 | 156 | }
|
153 | 157 | }
|
154 | 158 |
|
| 159 | + @Test |
| 160 | + public void execute_futureCompletionExecutorRejectsWhenCompleteAsync_futureCompletedSynchronously() { |
| 161 | + ExecutorService mockExecutor = mock(ExecutorService.class); |
| 162 | + doThrow(new RejectedExecutionException("Busy")).when(mockExecutor).execute(any(Runnable.class)); |
| 163 | + |
| 164 | + SdkClientConfiguration config = |
| 165 | + SdkClientConfiguration.builder() |
| 166 | + .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, mockExecutor) |
| 167 | + .option(ASYNC_HTTP_CLIENT, sdkAsyncHttpClient) |
| 168 | + .build(); |
| 169 | + HttpClientDependencies dependencies = HttpClientDependencies.builder().clientConfiguration(config).build(); |
| 170 | + |
| 171 | + TransformingAsyncResponseHandler mockHandler = mock(TransformingAsyncResponseHandler.class); |
| 172 | + when(mockHandler.prepare()).thenReturn(CompletableFuture.completedFuture(null)); |
| 173 | + |
| 174 | + stage = new MakeAsyncHttpRequestStage<>(mockHandler, dependencies); |
| 175 | + |
| 176 | + CompletableFuture<SdkHttpFullRequest> requestFuture = CompletableFuture.completedFuture( |
| 177 | + ValidSdkObjects.sdkHttpFullRequest().build()); |
| 178 | + |
| 179 | + CompletableFuture executeFuture = stage.execute(requestFuture, requestContext()); |
| 180 | + |
| 181 | + long testThreadId = Thread.currentThread().getId(); |
| 182 | + executeFuture.whenComplete((r, t) -> assertThat(Thread.currentThread().getId()).isEqualTo(testThreadId)).join(); |
| 183 | + verify(mockExecutor).execute(any(Runnable.class)); |
| 184 | + } |
| 185 | + |
155 | 186 | private HttpClientDependencies clientDependencies(Duration timeout) {
|
156 | 187 | SdkClientConfiguration configuration = SdkClientConfiguration.builder()
|
157 | 188 | .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run)
|
|
0 commit comments