Search in sources :

Example 1 with DefaultStreamedHttpResponse

use of software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse in project aws-sdk-java-v2 by aws.

the class PublisherAdapterTest method errorOccurred_shouldInvokeResponseHandler.

@Test
public void errorOccurred_shouldInvokeResponseHandler() {
    RuntimeException exception = new RuntimeException("boom");
    Flowable<HttpContent> testPublisher = Flowable.error(exception);
    StreamedHttpResponse streamedHttpResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED, testPublisher);
    ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse, ctx, requestContext, executeFuture);
    TestSubscriber subscriber = new TestSubscriber();
    publisherAdapter.subscribe(subscriber);
    verify(ctx, times(0)).read();
    verify(ctx).close();
    assertThat(subscriber.errorOccurred).isEqualTo(true);
    verify(channelPool).release(channel);
    assertThat(executeFuture).isCompletedExceptionally();
    verify(responseHandler).onError(exception);
}
Also used : DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) StreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse) DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Test(org.junit.Test)

Example 2 with DefaultStreamedHttpResponse

use of software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse in project aws-sdk-java-v2 by aws.

the class PublisherAdapterTest method successfulStreaming_shouldNotInvokeChannelRead.

@Test
public void successfulStreaming_shouldNotInvokeChannelRead() {
    Flowable<HttpContent> testPublisher = Flowable.just(fullHttpResponse);
    StreamedHttpResponse streamedHttpResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED, testPublisher);
    ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse, ctx, requestContext, executeFuture);
    TestSubscriber subscriber = new TestSubscriber();
    publisherAdapter.subscribe(subscriber);
    verify(ctx, times(0)).read();
    verify(ctx, times(0)).close();
    assertThat(subscriber.isCompleted).isEqualTo(true);
    verify(channelPool).release(channel);
    executeFuture.join();
    assertThat(executeFuture).isCompleted();
}
Also used : DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) StreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse) DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Test(org.junit.Test)

Example 3 with DefaultStreamedHttpResponse

use of software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse in project aws-sdk-java-v2 by aws.

the class PublisherAdapterTest method subscriptionCancelled_upstreamPublisherCallsOnNext_httpContentReleased.

@Test
public void subscriptionCancelled_upstreamPublisherCallsOnNext_httpContentReleased() {
    HttpContent firstContent = mock(HttpContent.class);
    when(firstContent.content()).thenReturn(Unpooled.EMPTY_BUFFER);
    HttpContent[] contentToIgnore = new HttpContent[8];
    for (int i = 0; i < contentToIgnore.length; ++i) {
        contentToIgnore[i] = mock(HttpContent.class);
    }
    Publisher<HttpContent> publisher = subscriber -> subscriber.onSubscribe(new Subscription() {

        @Override
        public void request(long l) {
            // We ignore any cancel signal and just publish all the content
            subscriber.onNext(firstContent);
            for (int i = 0; i < l && i < contentToIgnore.length; ++i) {
                subscriber.onNext(contentToIgnore[i]);
            }
        }

        @Override
        public void cancel() {
        // no-op
        }
    });
    DefaultStreamedHttpResponse streamedResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, publisher);
    Subscriber<ByteBuffer> subscriber = new Subscriber<ByteBuffer>() {

        private Subscription subscription;

        @Override
        public void onSubscribe(Subscription subscription) {
            this.subscription = subscription;
            subscription.request(Long.MAX_VALUE);
        }

        @Override
        public void onNext(ByteBuffer byteBuffer) {
            subscription.cancel();
        }

        @Override
        public void onError(Throwable throwable) {
        }

        @Override
        public void onComplete() {
        }
    };
    ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedResponse, ctx, requestContext, executeFuture);
    publisherAdapter.subscribe(subscriber);
    // First one should be accessed as normal
    verify(firstContent).content();
    verify(firstContent).release();
    for (int i = 0; i < contentToIgnore.length; ++i) {
        verify(contentToIgnore[i]).release();
        verifyNoMoreInteractions(contentToIgnore[i]);
    }
}
Also used : HttpVersion(io.netty.handler.codec.http.HttpVersion) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) RunWith(org.junit.runner.RunWith) Protocol(software.amazon.awssdk.http.Protocol) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) REQUEST_CONTEXT_KEY(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.REQUEST_CONTEXT_KEY) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Flowable(io.reactivex.Flowable) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) URI(java.net.URI) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Subscriber(org.reactivestreams.Subscriber) Before(org.junit.Before) HttpContent(io.netty.handler.codec.http.HttpContent) EventLoopGroup(io.netty.channel.EventLoopGroup) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) EXECUTE_FUTURE_KEY(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.EXECUTE_FUTURE_KEY) Publisher(org.reactivestreams.Publisher) Mockito.times(org.mockito.Mockito.times) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) EmptyHttpHeaders(io.netty.handler.codec.http.EmptyHttpHeaders) PROTOCOL_FUTURE(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.PROTOCOL_FUTURE) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) Subscription(org.reactivestreams.Subscription) StreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) DefaultStreamedHttpResponse(software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) ByteBuffer(java.nio.ByteBuffer) Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Test(org.junit.Test)

Aggregations

DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)3 HttpContent (io.netty.handler.codec.http.HttpContent)3 Test (org.junit.Test)3 SdkAsyncHttpResponseHandler (software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler)3 DefaultStreamedHttpResponse (software.amazon.awssdk.http.nio.netty.internal.nrs.DefaultStreamedHttpResponse)3 StreamedHttpResponse (software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse)3 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 EmptyByteBuf (io.netty.buffer.EmptyByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 EmptyHttpHeaders (io.netty.handler.codec.http.EmptyHttpHeaders)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 HttpVersion (io.netty.handler.codec.http.HttpVersion)1 Flowable (io.reactivex.Flowable)1 URI (java.net.URI)1 ByteBuffer (java.nio.ByteBuffer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1