Search in sources :

Example 1 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse in project beam by apache.

the class AwsCodersTest method testSdkHttpMetadataDecodeEncodeEquals.

@Test
public void testSdkHttpMetadataDecodeEncodeEquals() throws Exception {
    SdkHttpResponse value = buildSdkHttpMetadata();
    SdkHttpResponse clone = CoderUtils.clone(AwsCoders.sdkHttpResponse(), value);
    assertThat(clone.statusCode(), equalTo(value.statusCode()));
    assertThat(clone.headers(), equalTo(value.headers()));
}
Also used : SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) Test(org.junit.Test)

Example 2 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse in project beam by apache.

the class MockSnsAsyncClient method publish.

@Override
public CompletableFuture<PublishResponse> publish(PublishRequest publishRequest) {
    return CompletableFuture.supplyAsync(() -> {
        SdkHttpResponse sdkHttpResponse = SdkHttpResponse.builder().statusCode(statusCode).build();
        PublishResponse.Builder builder = PublishResponse.builder();
        builder.messageId(UUID.randomUUID().toString());
        builder.sdkHttpResponse(sdkHttpResponse).build();
        return builder.build();
    });
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse)

Example 3 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse in project beam by apache.

the class AwsCodersTest method testSdkHttpMetadataWithoutHeadersDecodeEncodeEquals.

@Test
public void testSdkHttpMetadataWithoutHeadersDecodeEncodeEquals() throws Exception {
    SdkHttpResponse value = buildSdkHttpMetadata();
    SdkHttpResponse clone = CoderUtils.clone(AwsCoders.sdkHttpResponseWithoutHeaders(), value);
    assertThat(clone.statusCode(), equalTo(value.statusCode()));
    assertThat(clone.headers().isEmpty(), equalTo(true));
}
Also used : SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) Test(org.junit.Test)

Example 4 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse in project curiostack by curioswitch.

the class ArmeriaSdkHttpClientTest method converts_success.

@Test
void converts_success() {
    StreamMessage<ByteBuffer> requestStream = StreamMessage.of(ByteBuffer.wrap("meow".getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap("woof".getBytes(StandardCharsets.UTF_8)));
    AtomicReference<SdkHttpResponse> responseHeaders = new AtomicReference<>();
    AtomicReference<Throwable> responseError = new AtomicReference<>();
    AtomicReference<Throwable> responseSubscriberError = new AtomicReference<>();
    AtomicBoolean responseComplete = new AtomicBoolean();
    List<ByteBuffer> responsePayloads = new ArrayList<>();
    AsyncExecuteRequest request = AsyncExecuteRequest.builder().request(SdkHttpRequest.builder().protocol("https").method(SdkHttpMethod.POST).host("github.com").appendHeader("X-Animals", "cat").appendHeader("X-Animals", "dog").appendHeader("Content-Type", "application/json").encodedPath("/foo").appendRawQueryParameter("bar", "baz").build()).responseHandler(new SdkAsyncHttpResponseHandler() {

        @Override
        public void onHeaders(SdkHttpResponse headers) {
            responseHeaders.set(headers);
        }

        @Override
        public void onStream(Publisher<ByteBuffer> stream) {
            stream.subscribe(new Subscriber<ByteBuffer>() {

                @Override
                public void onSubscribe(Subscription s) {
                    s.request(Long.MAX_VALUE);
                }

                @Override
                public void onNext(ByteBuffer byteBuffer) {
                    responsePayloads.add(byteBuffer);
                }

                @Override
                public void onError(Throwable t) {
                    responseSubscriberError.set(t);
                }

                @Override
                public void onComplete() {
                    responseComplete.set(true);
                }
            });
        }

        @Override
        public void onError(Throwable error) {
            responseError.set(error);
        }
    }).requestContentPublisher(new SdkHttpContentPublisher() {

        @Override
        public Optional<Long> contentLength() {
            return Optional.of((long) ("body1" + "body2").length());
        }

        @Override
        public void subscribe(Subscriber<? super ByteBuffer> s) {
            requestStream.subscribe(s);
        }
    }).fullDuplex(false).build();
    AtomicReference<AggregatedHttpRequest> aggregatedRequest = new AtomicReference<>();
    when(webClient.execute(any(HttpRequest.class))).thenAnswer((Answer<HttpResponse>) invocation -> {
        HttpRequest httpRequest = invocation.getArgument(0);
        aggregatedRequest.set(httpRequest.aggregate().join());
        return HttpResponse.of(ResponseHeaders.of(HttpStatus.OK, HttpHeaderNames.CONTENT_TYPE, "application/json", HttpHeaderNames.of("X-Countries"), "Japan", HttpHeaderNames.of("X-Countries"), "US"), HttpData.ofUtf8("purr"), HttpData.ofUtf8("growl"));
    });
    CompletableFuture<Void> responseFuture = client.execute(request);
    assertThat(responseFuture.join()).isNull();
    assertThat(responseHeaders.get()).satisfies(headers -> {
        assertThat(headers.statusCode()).isEqualTo(HttpStatus.OK.code());
        assertThat(headers.statusText()).hasValue(HttpStatus.OK.reasonPhrase());
        assertThat(headers.headers()).containsEntry("content-type", ImmutableList.of("application/json")).containsEntry("x-countries", ImmutableList.of("Japan", "US"));
    });
    assertThat(responsePayloads).extracting(buf -> Unpooled.wrappedBuffer(buf).toString(StandardCharsets.UTF_8)).containsExactly("purr", "growl");
    assertThat(responseError.get()).isNull();
    assertThat(responseSubscriberError.get()).isNull();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpHeaderNames(com.linecorp.armeria.common.HttpHeaderNames) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) CurioAssertions.assertThat(org.curioswitch.common.testing.assertj.CurioAssertions.assertThat) HttpStatus(com.linecorp.armeria.common.HttpStatus) WebClient(com.linecorp.armeria.client.WebClient) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Subscriber(org.reactivestreams.Subscriber) HttpData(com.linecorp.armeria.common.HttpData) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Publisher(org.reactivestreams.Publisher) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) Mockito.when(org.mockito.Mockito.when) StandardCharsets(java.nio.charset.StandardCharsets) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Test(org.junit.jupiter.api.Test) HttpRequest(com.linecorp.armeria.common.HttpRequest) List(java.util.List) StreamMessage(com.linecorp.armeria.common.stream.StreamMessage) ResponseHeaders(com.linecorp.armeria.common.ResponseHeaders) Subscription(org.reactivestreams.Subscription) Optional(java.util.Optional) ArrayList(java.util.ArrayList) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Subscription(org.reactivestreams.Subscription) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpRequest(com.linecorp.armeria.common.HttpRequest) Optional(java.util.Optional) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) Publisher(org.reactivestreams.Publisher) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Test(org.junit.jupiter.api.Test)

Example 5 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method mockSdkAsyncHttpClient.

private SdkAsyncHttpClient mockSdkAsyncHttpClient(SdkHttpResponse response) {
    SdkAsyncHttpClient mockClient = Mockito.mock(SdkAsyncHttpClient.class);
    when(mockClient.execute(Mockito.any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
        AsyncExecuteRequest request = invocationOnMock.getArgument(0);
        SdkAsyncHttpResponseHandler handler = request.responseHandler();
        handler.onHeaders(response);
        handler.onStream(new EmptyPublisher<>());
        return CompletableFuture.completedFuture(null);
    });
    return mockClient;
}
Also used : MethodSorters(org.junit.runners.MethodSorters) AWSXRay(com.amazonaws.xray.AWSXRay) Subsegment(com.amazonaws.xray.entities.Subsegment) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) AwsSessionCredentials(software.amazon.awssdk.auth.credentials.AwsSessionCredentials) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Segment(com.amazonaws.xray.entities.Segment) Context(software.amazon.awssdk.core.interceptor.Context) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) Answer(org.mockito.stubbing.Answer) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) After(org.junit.After) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) Emitter(com.amazonaws.xray.emitters.Emitter) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Region(software.amazon.awssdk.regions.Region) Before(org.junit.Before) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) EmptyPublisher(software.amazon.awssdk.core.async.EmptyPublisher) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Test(org.junit.Test) LambdaAsyncClient(software.amazon.awssdk.services.lambda.LambdaAsyncClient) Mockito.when(org.mockito.Mockito.when) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) AWSXRayRecorderBuilder(com.amazonaws.xray.AWSXRayRecorderBuilder) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Mockito(org.mockito.Mockito) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) InvokeRequest(software.amazon.awssdk.services.lambda.model.InvokeRequest) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Cause(com.amazonaws.xray.entities.Cause) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) CompletableFuture(java.util.concurrent.CompletableFuture) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) EmptyPublisher(software.amazon.awssdk.core.async.EmptyPublisher) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient)

Aggregations

SdkHttpResponse (software.amazon.awssdk.http.SdkHttpResponse)6 Test (org.junit.Test)4 Segment (com.amazonaws.xray.entities.Segment)2 Subsegment (com.amazonaws.xray.entities.Subsegment)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Mockito.when (org.mockito.Mockito.when)2 Answer (org.mockito.stubbing.Answer)2 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)2 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)2 AsyncExecuteRequest (software.amazon.awssdk.http.async.AsyncExecuteRequest)2 SdkAsyncHttpResponseHandler (software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler)2 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)2 AWSXRay (com.amazonaws.xray.AWSXRay)1 AWSXRayRecorderBuilder (com.amazonaws.xray.AWSXRayRecorderBuilder)1 Emitter (com.amazonaws.xray.emitters.Emitter)1 Cause (com.amazonaws.xray.entities.Cause)1 ImmutableList (com.google.common.collect.ImmutableList)1