Search in sources :

Example 1 with RequestExecutionContext

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));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) TimeUnit(java.util.concurrent.TimeUnit) ScheduledFuture(java.util.concurrent.ScheduledFuture) Before(org.junit.Before)

Example 2 with RequestExecutionContext

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);
}
Also used : RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) Test(org.junit.jupiter.api.Test)

Example 3 with RequestExecutionContext

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);
    }
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) TimeoutTracker(software.amazon.awssdk.core.internal.http.timers.TimeoutTracker) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with RequestExecutionContext

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");
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) Test(org.junit.jupiter.api.Test)

Example 5 with RequestExecutionContext

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);
}
Also used : SdkServiceException(software.amazon.awssdk.core.exception.SdkServiceException) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) RequestExecutionContext(software.amazon.awssdk.core.internal.http.RequestExecutionContext) RetryPolicy(software.amazon.awssdk.core.retry.RetryPolicy) Test(org.junit.jupiter.api.Test)

Aggregations

RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)26 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)23 Test (org.junit.Test)16 SdkServiceException (software.amazon.awssdk.core.exception.SdkServiceException)8 Test (org.junit.jupiter.api.Test)7 HttpClientDependencies (software.amazon.awssdk.core.internal.http.HttpClientDependencies)5 HashMap (java.util.HashMap)4 List (java.util.List)4 RetryPolicy (software.amazon.awssdk.core.retry.RetryPolicy)4 TimeUnit (java.util.concurrent.TimeUnit)2 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)2 ExecutionContext (software.amazon.awssdk.core.http.ExecutionContext)2 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)2 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)2 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Before (org.junit.Before)1 ApiCallTimeoutException (software.amazon.awssdk.core.exception.ApiCallTimeoutException)1 ApiCallTimeoutTracker (software.amazon.awssdk.core.internal.http.timers.ApiCallTimeoutTracker)1