use of software.amazon.awssdk.core.interceptor.ExecutionAttribute in project aws-sdk-java-v2 by aws.
the class RequestOverrideConfigurationTest method executionAttributes_isImmutable.
@Test
public void executionAttributes_isImmutable() {
ExecutionAttributes executionAttributes = new ExecutionAttributes();
ExecutionAttribute testAttribute = attr("TestAttribute");
String expectedValue = "Value1";
executionAttributes.putAttribute(testAttribute, expectedValue);
SdkRequestOverrideConfiguration overrideConfig = SdkRequestOverrideConfiguration.builder().executionAttributes(executionAttributes).build();
try {
overrideConfig.executionAttributes().putAttribute(testAttribute, 2);
fail("Expected unsupported operation exception");
} catch (Exception ex) {
assertThat(ex instanceof UnsupportedOperationException).isTrue();
}
try {
overrideConfig.executionAttributes().putAttributeIfAbsent(testAttribute, 2);
fail("Expected unsupported operation exception");
} catch (Exception ex) {
assertThat(ex instanceof UnsupportedOperationException).isTrue();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionAttribute in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method testAttributeEquals.
@Test
public void testAttributeEquals() {
ExecutionAttribute attribute1 = getAttribute(0);
ExecutionAttribute attribute2 = getAttribute(0);
assertThat(attribute1).isEqualTo(attribute1);
assertThat(attribute1).isEqualTo(attribute2);
assertThat(attribute1).isNotEqualTo(null);
}
use of software.amazon.awssdk.core.interceptor.ExecutionAttribute 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.ExecutionAttribute 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.ExecutionAttribute in project aws-sdk-java-v2 by aws.
the class ClientOverrideConfigurationTest method executionAttributes_isImmutable.
@Test
public void executionAttributes_isImmutable() {
ExecutionAttributes executionAttributes = new ExecutionAttributes();
ExecutionAttribute testAttribute = attr("TestAttribute");
String expectedValue = "Value1";
executionAttributes.putAttribute(testAttribute, expectedValue);
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder().executionAttributes(executionAttributes).build();
try {
overrideConfig.executionAttributes().putAttribute(testAttribute, 2);
fail("Expected unsupported operation exception");
} catch (Exception ex) {
assertThat(ex instanceof UnsupportedOperationException).isTrue();
}
}
Aggregations