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);
}
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();
}
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]);
}
}
Aggregations