use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class AsyncHttpClientApiCallTimeoutTests method successfulResponse_SlowBeforeRequestRequestHandler_ThrowsApiCallTimeoutException.
@Test
public void successfulResponse_SlowBeforeRequestRequestHandler_ThrowsApiCallTimeoutException() {
stubFor(get(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}")));
ExecutionInterceptor interceptor = new SlowExecutionInterceptor().beforeTransmissionWaitInSeconds(SLOW_REQUEST_HANDLER_TIMEOUT);
CompletableFuture future = requestBuilder().executionContext(withInterceptors(interceptor)).execute(noOpResponseHandler());
assertThatThrownBy(future::join).hasCauseInstanceOf(ApiCallTimeoutException.class);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class HttpClientApiCallAttemptTimeoutTest method successfulResponse_SlowBeforeTransmissionExecutionInterceptor_ThrowsApiCallTimeoutException.
@Test
public void successfulResponse_SlowBeforeTransmissionExecutionInterceptor_ThrowsApiCallTimeoutException() {
stubFor(get(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}")));
ExecutionInterceptor interceptor = new SlowExecutionInterceptor().beforeTransmissionWaitInSeconds(SLOW_REQUEST_HANDLER_TIMEOUT);
assertThatThrownBy(() -> requestBuilder().executionContext(withInterceptors(interceptor)).execute(noOpSyncResponseHandler())).isInstanceOf(ApiCallAttemptTimeoutException.class);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ProfileUseArnRegionProviderTest method specifiedInOverrideConfig_shouldUse.
@Test
public void specifiedInOverrideConfig_shouldUse() {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "s3_use_arn_region = true\n";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
S3Client s3 = S3Client.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).build();
String arn = "arn:aws:s3:us-banana-46:12345567890:accesspoint:foo";
assertThatThrownBy(() -> s3.getObject(r -> r.bucket(arn).key("bar"))).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor).beforeTransmission(context.capture(), any());
String host = context.getValue().httpRequest().host();
assertThat(host).contains("us-banana-46");
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method syncClient_requestOverrideExecutionAttributesHavePrecedence.
@Test
public void syncClient_requestOverrideExecutionAttributesHavePrecedence() {
ExecutionInterceptor interceptor = mock(ExecutionInterceptor.class);
ArgumentCaptor<ExecutionAttributes> attributesCaptor = ArgumentCaptor.forClass(ExecutionAttributes.class);
doThrow(new RuntimeException("BOOM")).when(interceptor).beforeExecution(any(Context.BeforeExecution.class), attributesCaptor.capture());
ExecutionAttribute testAttribute = attr("TestAttribute");
String testValue = "TestValue";
ProtocolRestJsonClient sync = ProtocolRestJsonClient.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_WEST_2).overrideConfiguration(c -> c.addExecutionInterceptor(interceptor).putExecutionAttribute(testAttribute, testValue)).build();
String overwrittenValue = "TestValue2";
AllTypesRequest request = AllTypesRequest.builder().overrideConfiguration(c -> c.putExecutionAttribute(testAttribute, overwrittenValue)).build();
thrown.expect(RuntimeException.class);
try {
sync.allTypes(request);
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(overwrittenValue);
sync.close();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method asyncClient_requestOverrideExecutionAttributesHavePrecedence.
@Test
public void asyncClient_requestOverrideExecutionAttributesHavePrecedence() {
ExecutionInterceptor interceptor = mock(ExecutionInterceptor.class);
ArgumentCaptor<ExecutionAttributes> attributesCaptor = ArgumentCaptor.forClass(ExecutionAttributes.class);
doThrow(new RuntimeException("BOOM")).when(interceptor).beforeExecution(any(Context.BeforeExecution.class), attributesCaptor.capture());
ExecutionAttribute testAttribute = attr("TestAttribute");
String testValue = "TestValue";
ProtocolRestJsonAsyncClient async = ProtocolRestJsonAsyncClient.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_WEST_2).overrideConfiguration(c -> c.addExecutionInterceptor(interceptor).putExecutionAttribute(testAttribute, testValue)).build();
String overwrittenValue = "TestValue2";
AllTypesRequest request = AllTypesRequest.builder().overrideConfiguration(c -> c.putExecutionAttribute(testAttribute, overwrittenValue)).build();
thrown.expect(CompletionException.class);
try {
async.allTypes(request).join();
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(overwrittenValue);
async.close();
}
}
Aggregations