Search in sources :

Example 16 with ExecutionInterceptor

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.

the class ExecutionInterceptorTest method sync_streamingOutput_success_allInterceptorMethodsCalled.

@Test
public void sync_streamingOutput_success_allInterceptorMethodsCalled() throws IOException {
    // Given
    ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
    ProtocolRestJsonClient client = client(interceptor);
    StreamingOutputOperationRequest request = StreamingOutputOperationRequest.builder().build();
    stubFor(post(urlPathEqualTo(STREAMING_OUTPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("\0")));
    // When
    client.streamingOutputOperation(request, (r, i) -> {
        assertThat(i.read()).isEqualTo(0);
        // being the unmarshaller
        return r;
    });
    // Expect
    Context.AfterTransmission afterTransmissionArg = captureAfterTransmissionArg(interceptor);
    // TODO: When we don't always close the input stream, make sure we can read the service's '0' response.
    assertThat(afterTransmissionArg.responseBody() != null);
}
Also used : Context(software.amazon.awssdk.core.interceptor.Context) StreamingOutputOperationRequest(software.amazon.awssdk.services.protocolrestjson.model.StreamingOutputOperationRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.Test)

Example 17 with ExecutionInterceptor

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.

the class ExecutionInterceptorTest method async_interceptorException_failureInterceptorMethodsCalled.

@Test
public void async_interceptorException_failureInterceptorMethodsCalled() {
    // Given
    ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
    RuntimeException exception = new RuntimeException("Uh oh!");
    doThrow(exception).when(interceptor).afterExecution(any(), any());
    ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
    MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
    stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
    // When
    assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> client.membersInHeaders(request).get()).withCause(SdkClientException.builder().cause(exception).build());
    // Expect
    expectAllMethodsCalled(interceptor, request, exception, true);
}
Also used : ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) MembersInHeadersRequest(software.amazon.awssdk.services.protocolrestjson.model.MembersInHeadersRequest) Test(org.junit.Test)

Example 18 with ExecutionInterceptor

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.

the class ExecutionInterceptorTest method sync_success_allInterceptorMethodsCalled.

@Test
public void sync_success_allInterceptorMethodsCalled() {
    // Given
    ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
    ProtocolRestJsonClient client = client(interceptor);
    MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
    stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
    // When
    MembersInHeadersResponse result = client.membersInHeaders(request);
    // Expect
    expectAllMethodsCalled(interceptor, request, null, false);
    validateRequestResponse(result);
}
Also used : ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) MembersInHeadersResponse(software.amazon.awssdk.services.protocolrestjson.model.MembersInHeadersResponse) MembersInHeadersRequest(software.amazon.awssdk.services.protocolrestjson.model.MembersInHeadersRequest) Test(org.junit.Test)

Example 19 with ExecutionInterceptor

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.

the class ExecutionInterceptorTest method sync_streamingInput_success_allInterceptorMethodsCalled.

@Test
public void sync_streamingInput_success_allInterceptorMethodsCalled() throws IOException {
    // Given
    ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
    ProtocolRestJsonClient client = client(interceptor);
    StreamingInputOperationRequest request = StreamingInputOperationRequest.builder().build();
    stubFor(post(urlPathEqualTo(STREAMING_INPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
    // When
    client.streamingInputOperation(request, RequestBody.fromBytes(new byte[] { 0 }));
    // Expect
    Context.BeforeTransmission beforeTransmissionArg = captureBeforeTransmissionArg(interceptor, false);
    assertThat(beforeTransmissionArg.requestBody().get().contentStreamProvider().newStream().read()).isEqualTo(0);
    assertThat(beforeTransmissionArg.httpRequest().firstMatchingHeader(Header.CONTENT_LENGTH).get()).contains(Long.toString(1L));
}
Also used : Context(software.amazon.awssdk.core.interceptor.Context) StreamingInputOperationRequest(software.amazon.awssdk.services.protocolrestjson.model.StreamingInputOperationRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.Test)

Example 20 with ExecutionInterceptor

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.

the class ExecutionInterceptorTest method async_serviceException_failureInterceptorMethodsCalled.

@Test
public void async_serviceException_failureInterceptorMethodsCalled() throws Exception {
    // Given
    ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
    ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
    MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
    // When
    assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> client.membersInHeaders(request).get()).withCauseInstanceOf(SdkServiceException.class);
    // Expect
    expectServiceCallErrorMethodsCalled(interceptor, true);
}
Also used : ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) MembersInHeadersRequest(software.amazon.awssdk.services.protocolrestjson.model.MembersInHeadersRequest) Test(org.junit.Test)

Aggregations

ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)33 Test (org.junit.Test)25 Context (software.amazon.awssdk.core.interceptor.Context)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)12 ProtocolRestJsonAsyncClient (software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient)12 ProtocolRestJsonClient (software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient)12 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)11 ArgumentCaptor (org.mockito.ArgumentCaptor)10 Region (software.amazon.awssdk.regions.Region)10 Mockito.mock (org.mockito.Mockito.mock)9 SdkAdvancedClientOption (software.amazon.awssdk.core.client.config.SdkAdvancedClientOption)9 ExecutionAttribute (software.amazon.awssdk.core.interceptor.ExecutionAttribute)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 CompletionException (java.util.concurrent.CompletionException)7 ConcurrentMap (java.util.concurrent.ConcurrentMap)7 Rule (org.junit.Rule)7 ExpectedException (org.junit.rules.ExpectedException)7 Mockito.doThrow (org.mockito.Mockito.doThrow)7 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)7