use of software.amazon.awssdk.core.internal.http.RequestExecutionContext in project aws-sdk-java-v2 by aws.
the class AsyncApiCallTimeoutTrackingStageTest method methodSetup.
@Before
public void methodSetup() throws Exception {
configuration = SdkClientConfiguration.builder().option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, executorService).option(SdkClientOption.API_CALL_TIMEOUT, Duration.ofMillis(TIMEOUT_MILLIS)).build();
dependencies = HttpClientDependencies.builder().clientConfiguration(configuration).build();
httpRequest = SdkHttpFullRequest.builder().uri(URI.create("https://localhost")).method(SdkHttpMethod.GET).build();
requestExecutionContext = RequestExecutionContext.builder().originalRequest(sdkRequest).executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(ValidSdkObjects.sdkHttpFullRequest().build())).build();
when(requestPipeline.execute(any(SdkHttpFullRequest.class), any(RequestExecutionContext.class))).thenReturn(new CompletableFuture());
when(executorService.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenReturn(mock(ScheduledFuture.class));
}
use of software.amazon.awssdk.core.internal.http.RequestExecutionContext in project aws-sdk-java-v2 by aws.
the class ExceptionReportingUtilsTest method onExecutionFailureThrowException_shouldSwallow.
@Test
public void onExecutionFailureThrowException_shouldSwallow() {
RequestExecutionContext context = context(new ThrowErrorOnExecutionFailureInterceptor());
assertThat(ExceptionReportingUtils.reportFailureToInterceptors(context, SdkClientException.create("test"))).isExactlyInstanceOf(SdkClientException.class);
}
use of software.amazon.awssdk.core.internal.http.RequestExecutionContext in project aws-sdk-java-v2 by aws.
the class MakeHttpRequestStageTest method testExecute_contextContainsMetricCollector_addsChildToExecuteRequest.
@Test
public void testExecute_contextContainsMetricCollector_addsChildToExecuteRequest() {
SdkHttpFullRequest sdkRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).host("mybucket.s3.us-west-2.amazonaws.com").protocol("https").build();
MetricCollector mockCollector = mock(MetricCollector.class);
MetricCollector childCollector = mock(MetricCollector.class);
when(mockCollector.createChild(any(String.class))).thenReturn(childCollector);
ExecutionContext executionContext = ExecutionContext.builder().executionAttributes(new ExecutionAttributes()).build();
RequestExecutionContext context = RequestExecutionContext.builder().originalRequest(ValidSdkObjects.sdkRequest()).executionContext(executionContext).build();
context.attemptMetricCollector(mockCollector);
context.apiCallAttemptTimeoutTracker(mock(TimeoutTracker.class));
context.apiCallTimeoutTracker(mock(TimeoutTracker.class));
try {
stage.execute(sdkRequest, context);
} catch (Exception e) {
// ignored, don't really care about successful execution of the stage in this case
} finally {
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
verify(mockCollector).createChild(eq("HttpClient"));
verify(mockClient).prepareRequest(httpRequestCaptor.capture());
assertThat(httpRequestCaptor.getValue().metricCollector()).contains(childCollector);
}
}
use of software.amazon.awssdk.core.internal.http.RequestExecutionContext in project aws-sdk-java-v2 by aws.
the class RetryableStageAdaptiveModeTest method execute_acquireReturnsFalse_throws.
@Test
public void execute_acquireReturnsFalse_throws() {
when(tokenBucket.acquire(anyDouble(), anyBoolean())).thenReturn(false);
retryableStage = createStage(false);
SdkHttpFullRequest httpRequest = createHttpRequest();
RequestExecutionContext executionContext = createExecutionContext();
assertThatThrownBy(() -> retryableStage.execute(httpRequest, executionContext)).isInstanceOf(SdkClientException.class).hasMessageContaining("Unable to acquire a send token");
}
use of software.amazon.awssdk.core.internal.http.RequestExecutionContext in project aws-sdk-java-v2 by aws.
the class RetryableStageAdaptiveModeTest method execute_unsuccessfulResponse_throttlingError_updatesRate.
@Test
public void execute_unsuccessfulResponse_throttlingError_updatesRate() throws Exception {
RetryPolicy retryPolicy = RetryPolicy.builder(RetryMode.ADAPTIVE).numRetries(0).build();
retryableStage = createStage(retryPolicy);
SdkServiceException error = SdkServiceException.builder().statusCode(HttpStatusCode.THROTTLING).build();
mockChildResponse(createUnsuccessfulResponse(error));
SdkHttpFullRequest httpRequest = createHttpRequest();
RequestExecutionContext executionContext = createExecutionContext();
assertThatThrownBy(() -> retryableStage.execute(httpRequest, executionContext)).isInstanceOf(SdkServiceException.class);
verify(tokenBucket).updateClientSendingRate(true);
verify(tokenBucket, never()).updateClientSendingRate(false);
}
Aggregations