Search in sources :

Example 11 with ExecutionAttribute

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

Example 12 with ExecutionAttribute

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();
    }
}
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) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.Test)

Example 13 with ExecutionAttribute

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();
    }
}
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 14 with ExecutionAttribute

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();
    }
}
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) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.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