|
22 | 22 | import static org.mockito.Mockito.verify; |
23 | 23 | import static org.mockito.Mockito.when; |
24 | 24 |
|
| 25 | +import java.io.IOException; |
25 | 26 | import java.net.URI; |
26 | 27 | import java.time.Duration; |
27 | 28 | import java.util.concurrent.CompletableFuture; |
|
33 | 34 | import org.junit.jupiter.api.BeforeAll; |
34 | 35 | import org.junit.jupiter.api.BeforeEach; |
35 | 36 | import org.junit.jupiter.params.ParameterizedTest; |
| 37 | +import org.junit.jupiter.params.provider.CsvSource; |
36 | 38 | import org.junit.jupiter.params.provider.MethodSource; |
37 | 39 | import org.mockito.ArgumentCaptor; |
38 | 40 | import software.amazon.awssdk.core.Response; |
@@ -233,4 +235,67 @@ void execute_retryableException_treatsRetryAfterCorrectly(RetryAfterTestCase tes |
233 | 235 |
|
234 | 236 | assertThat(refreshRequest.suggestedDelay().get()).isEqualTo(testCase.expectedDelay()); |
235 | 237 | } |
| 238 | + |
| 239 | + @ParameterizedTest(name = "New Retries = {0}") |
| 240 | + @CsvSource({"true", "false"}) |
| 241 | + void execute_delegateThrows_noHttpResponse_uses0SuggestedDelay(boolean newRetries2026) throws Exception { |
| 242 | + SdkClientConfiguration clientConfig = SdkClientConfiguration.builder() |
| 243 | + .option(SdkClientOption.RETRY_STRATEGY, mockRetryStrategy) |
| 244 | + .option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, |
| 245 | + executorService) |
| 246 | + .build(); |
| 247 | + |
| 248 | + HttpClientDependencies deps = HttpClientDependencies.builder() |
| 249 | + .clientConfiguration(clientConfig) |
| 250 | + .build(); |
| 251 | + |
| 252 | + AsyncRetryableStage<SdkResponse> retryableStage = new AsyncRetryableStage<>(mock(TransformingAsyncResponseHandler.class), |
| 253 | + deps, mockDelegatePipeline); |
| 254 | + |
| 255 | + SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder() |
| 256 | + .method(SdkHttpMethod.GET) |
| 257 | + .uri(URI.create("https://my-service.amazonaws.com")) |
| 258 | + .build(); |
| 259 | + |
| 260 | + ExecutionAttributes execAttrs = ExecutionAttributes.builder() |
| 261 | + .put(SdkInternalExecutionAttribute.NEW_RETRIES_2026_ENABLED, |
| 262 | + newRetries2026) |
| 263 | + .build(); |
| 264 | + |
| 265 | + ExecutionContext execCtx = ExecutionContext.builder() |
| 266 | + .metricCollector(NoOpMetricCollector.create()) |
| 267 | + .executionAttributes(execAttrs) |
| 268 | + .build(); |
| 269 | + |
| 270 | + RequestExecutionContext ctx = RequestExecutionContext.builder() |
| 271 | + .originalRequest(mock(SdkRequest.class)) |
| 272 | + .executionContext(execCtx) |
| 273 | + .build(); |
| 274 | + |
| 275 | + SdkHttpFullResponse.Builder httpResponse = SdkHttpFullResponse.builder() |
| 276 | + .statusCode(502); |
| 277 | + |
| 278 | + Response<SdkResponse> response = Response.<SdkResponse>builder() |
| 279 | + .httpResponse(httpResponse.build()) |
| 280 | + .isSuccess(false) |
| 281 | + .exception(SdkException.builder().build()) |
| 282 | + .build(); |
| 283 | + |
| 284 | + |
| 285 | + CompletableFuture<Response<SdkResponse>> future = new CompletableFuture<>(); |
| 286 | + future.completeExceptionally(new IOException("connection")); |
| 287 | + when(mockDelegatePipeline.execute(any(), any())).thenReturn(future); |
| 288 | + |
| 289 | + CompletableFuture<Response<SdkResponse>> execute = retryableStage.execute(httpRequest, ctx); |
| 290 | + // exception thrown doesn't matter, just results in exception because we mock just enough... |
| 291 | + assertThatThrownBy(execute::join); |
| 292 | + |
| 293 | + ArgumentCaptor<RefreshRetryTokenRequest> refreshRequestCaptor = ArgumentCaptor.forClass(RefreshRetryTokenRequest.class); |
| 294 | + |
| 295 | + verify(mockRetryStrategy).refreshRetryToken(refreshRequestCaptor.capture()); |
| 296 | + |
| 297 | + RefreshRetryTokenRequest refreshRequest = refreshRequestCaptor.getValue(); |
| 298 | + |
| 299 | + assertThat(refreshRequest.suggestedDelay().get()).isEqualTo(Duration.ZERO); |
| 300 | + } |
236 | 301 | } |
0 commit comments