use of software.amazon.awssdk.core.interceptor.ExecutionAttribute in project aws-sdk-java-v2 by aws.
the class RequestOverrideConfigurationTest method toBuilder_maximal.
@Test
public void toBuilder_maximal() {
ExecutionAttribute testAttribute = attr("TestAttribute");
String expectedValue = "Value1";
RequestOverrideConfiguration configuration = SdkRequestOverrideConfiguration.builder().putHeader(HEADER, "foo").putRawQueryParameter(QUERY_PARAM, "foo").addApiName(a -> a.name("test1").version("1")).apiCallTimeout(Duration.ofSeconds(1)).apiCallAttemptTimeout(Duration.ofSeconds(1)).signer(new NoOpSigner()).executionAttributes(ExecutionAttributes.builder().put(testAttribute, expectedValue).build()).addMetricPublisher(mock(MetricPublisher.class)).build();
assertThat(configuration.toBuilder().build()).usingRecursiveComparison().isEqualTo(configuration);
}
use of software.amazon.awssdk.core.interceptor.ExecutionAttribute 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.ExecutionAttribute 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();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionAttribute in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method syncClient_requestOverrideExecutionAttribute.
@Test
public void syncClient_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";
ProtocolRestJsonClient sync = ProtocolRestJsonClient.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(RuntimeException.class);
try {
sync.allTypes(request);
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(testValue);
sync.close();
}
}
Aggregations