use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method asyncClient_requestOverrideExecutionAttribute.
@Test
public void asyncClient_requestOverrideExecutionAttribute() {
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)).build();
AllTypesRequest request = AllTypesRequest.builder().overrideConfiguration(c -> c.putExecutionAttribute(testAttribute, testValue)).build();
thrown.expect(CompletionException.class);
try {
async.allTypes(request).join();
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(testValue);
async.close();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method asyncClient_clientOverrideExecutionAttribute.
@Test
public void asyncClient_clientOverrideExecutionAttribute() {
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();
thrown.expect(CompletionException.class);
try {
async.allTypes().join();
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(testValue);
async.close();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class HttpClientApiCallTimeoutTest 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(ApiCallTimeoutException.class);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExceptionReportingUtilsTest method context.
public RequestExecutionContext context(ExecutionInterceptor... executionInterceptors) {
List<ExecutionInterceptor> interceptors = Arrays.asList(executionInterceptors);
ExecutionInterceptorChain executionInterceptorChain = new ExecutionInterceptorChain(interceptors);
return RequestExecutionContext.builder().executionContext(ExecutionContext.builder().signer(new NoOpSigner()).executionAttributes(new ExecutionAttributes()).interceptorContext(InterceptorContext.builder().request(ValidSdkObjects.sdkRequest()).build()).interceptorChain(executionInterceptorChain).build()).originalRequest(ValidSdkObjects.sdkRequest()).build();
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ClientOverrideConfigurationTest method shouldGuaranteeImmutability.
@Test
public void shouldGuaranteeImmutability() {
List<String> headerValues = new ArrayList<>();
headerValues.add("bar");
Map<String, List<String>> headers = new HashMap<>();
headers.put("foo", headerValues);
List<ExecutionInterceptor> executionInterceptors = new ArrayList<>();
SlowExecutionInterceptor slowExecutionInterceptor = new SlowExecutionInterceptor();
executionInterceptors.add(slowExecutionInterceptor);
ClientOverrideConfiguration.Builder configurationBuilder = ClientOverrideConfiguration.builder().executionInterceptors(executionInterceptors).headers(headers);
headerValues.add("test");
headers.put("new header", Collections.singletonList("new value"));
executionInterceptors.clear();
assertThat(configurationBuilder.headers().size()).isEqualTo(1);
assertThat(configurationBuilder.headers().get("foo")).containsExactly("bar");
assertThat(configurationBuilder.executionInterceptors()).containsExactly(slowExecutionInterceptor);
}
Aggregations