Search in sources :

Example 1 with ExecutionAttribute

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

Example 2 with ExecutionAttribute

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);
}
Also used : SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) Test(org.junit.Test)

Example 3 with ExecutionAttribute

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();
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) ConcurrentMap(java.util.concurrent.ConcurrentMap) Context(software.amazon.awssdk.core.interceptor.Context) Mockito.doThrow(org.mockito.Mockito.doThrow) Rule(org.junit.Rule) ArgumentCaptor(org.mockito.ArgumentCaptor) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) ExpectedException(org.junit.rules.ExpectedException) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Mockito.mock(org.mockito.Mockito.mock) AllTypesRequest(software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) AllTypesRequest(software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Test(org.junit.Test)

Example 4 with ExecutionAttribute

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();
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) ConcurrentMap(java.util.concurrent.ConcurrentMap) Context(software.amazon.awssdk.core.interceptor.Context) Mockito.doThrow(org.mockito.Mockito.doThrow) Rule(org.junit.Rule) ArgumentCaptor(org.mockito.ArgumentCaptor) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) ExpectedException(org.junit.rules.ExpectedException) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Mockito.mock(org.mockito.Mockito.mock) AllTypesRequest(software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Test(org.junit.Test)

Example 5 with ExecutionAttribute

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

Aggregations

ExecutionAttribute (software.amazon.awssdk.core.interceptor.ExecutionAttribute)14 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)12 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 Mockito.mock (org.mockito.Mockito.mock)6 SdkAdvancedClientOption (software.amazon.awssdk.core.client.config.SdkAdvancedClientOption)6 ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)6 SdkInternalExecutionAttribute (software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute)6 CompletionException (java.util.concurrent.CompletionException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)5 Rule (org.junit.Rule)5 ExpectedException (org.junit.rules.ExpectedException)5 ArgumentCaptor (org.mockito.ArgumentCaptor)5 Mockito.doThrow (org.mockito.Mockito.doThrow)5 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)5 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)5 Context (software.amazon.awssdk.core.interceptor.Context)5