Search in sources :

Example 6 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class BlockingStreamingToStreamingServiceTest method throwAfterSendMetaData.

@Test
void throwAfterSendMetaData() throws Exception {
    CountDownLatch onErrorLatch = new CountDownLatch(1);
    AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    BlockingStreamingHttpService syncService = (ctx, request, response) -> {
        response.sendMetaData();
        throw DELIBERATE_EXCEPTION;
    };
    StreamingHttpService asyncService = toStreamingHttpService(syncService, offloadNone()).adaptor();
    StreamingHttpResponse asyncResponse = asyncService.handle(mockCtx, reqRespFactory.get("/"), reqRespFactory).subscribeOn(executorExtension.executor()).toFuture().get();
    assertMetaData(OK, asyncResponse);
    toSource(asyncResponse.payloadBody()).subscribe(new Subscriber<Buffer>() {

        @Override
        public void onSubscribe(final Subscription s) {
        }

        @Override
        public void onNext(final Buffer s) {
        }

        @Override
        public void onError(final Throwable t) {
            throwableRef.set(t);
            onErrorLatch.countDown();
        }

        @Override
        public void onComplete() {
        }
    });
    onErrorLatch.await();
    assertThat(throwableRef.get(), is(DELIBERATE_EXCEPTION));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PlatformDependent.throwException(io.servicetalk.utils.internal.PlatformDependent.throwException) BiFunction(java.util.function.BiFunction) SingleSource(io.servicetalk.concurrent.SingleSource) ServiceAdapterHolder(io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executor(io.servicetalk.concurrent.api.Executor) HttpExecutionStrategies.offloadNone(io.servicetalk.http.api.HttpExecutionStrategies.offloadNone) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) PayloadWriter(io.servicetalk.oio.api.PayloadWriter) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.servicetalk.buffer.api.Buffer) Function.identity(java.util.function.Function.identity) Matchers.is(org.hamcrest.Matchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) Publisher(io.servicetalk.concurrent.api.Publisher) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cancellable(io.servicetalk.concurrent.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) Subscriber(io.servicetalk.concurrent.PublisherSource.Subscriber) ArrayList(java.util.ArrayList) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Nullable(javax.annotation.Nullable) TRAILER(io.servicetalk.http.api.HttpHeaderNames.TRAILER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) NO_CONTENT(io.servicetalk.http.api.HttpResponseStatus.NO_CONTENT) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) OK(io.servicetalk.http.api.HttpResponseStatus.OK) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) ExecutionException(java.util.concurrent.ExecutionException) Publisher.failed(io.servicetalk.concurrent.api.Publisher.failed) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) InputStream(java.io.InputStream) Buffer(io.servicetalk.buffer.api.Buffer) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) Test(org.junit.jupiter.api.Test)

Example 7 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class BlockingStreamingToStreamingServiceTest method throwBeforeSendMetaData.

@Test
void throwBeforeSendMetaData() throws Exception {
    CountDownLatch onErrorLatch = new CountDownLatch(1);
    AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    BlockingStreamingHttpService syncService = (ctx, request, response) -> {
        throw DELIBERATE_EXCEPTION;
    };
    StreamingHttpService asyncService = toStreamingHttpService(syncService, offloadNone()).adaptor();
    toSource(asyncService.handle(mockCtx, reqRespFactory.get("/"), reqRespFactory).subscribeOn(executorExtension.executor())).subscribe(new SingleSource.Subscriber<StreamingHttpResponse>() {

        @Override
        public void onSubscribe(final Cancellable cancellable) {
        }

        @Override
        public void onSuccess(@Nullable final StreamingHttpResponse result) {
        }

        @Override
        public void onError(final Throwable t) {
            throwableRef.set(t);
            onErrorLatch.countDown();
        }
    });
    onErrorLatch.await();
    assertThat(throwableRef.get(), is(DELIBERATE_EXCEPTION));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PlatformDependent.throwException(io.servicetalk.utils.internal.PlatformDependent.throwException) BiFunction(java.util.function.BiFunction) SingleSource(io.servicetalk.concurrent.SingleSource) ServiceAdapterHolder(io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executor(io.servicetalk.concurrent.api.Executor) HttpExecutionStrategies.offloadNone(io.servicetalk.http.api.HttpExecutionStrategies.offloadNone) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) PayloadWriter(io.servicetalk.oio.api.PayloadWriter) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.servicetalk.buffer.api.Buffer) Function.identity(java.util.function.Function.identity) Matchers.is(org.hamcrest.Matchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) Publisher(io.servicetalk.concurrent.api.Publisher) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cancellable(io.servicetalk.concurrent.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) Subscriber(io.servicetalk.concurrent.PublisherSource.Subscriber) ArrayList(java.util.ArrayList) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Nullable(javax.annotation.Nullable) TRAILER(io.servicetalk.http.api.HttpHeaderNames.TRAILER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) NO_CONTENT(io.servicetalk.http.api.HttpResponseStatus.NO_CONTENT) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) OK(io.servicetalk.http.api.HttpResponseStatus.OK) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) ExecutionException(java.util.concurrent.ExecutionException) Publisher.failed(io.servicetalk.concurrent.api.Publisher.failed) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) InputStream(java.io.InputStream) SingleSource(io.servicetalk.concurrent.SingleSource) Cancellable(io.servicetalk.concurrent.Cancellable) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 8 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class NettyPipelinedConnectionTest method writeThrowsClosesConnection.

@Test
void writeThrowsClosesConnection() {
    TestPublisher<Integer> mockReadPublisher2 = new TestPublisher<>();
    @SuppressWarnings("unchecked") NettyConnection<Integer, Integer> mockConnection = mock(NettyConnection.class);
    doAnswer((Answer<Publisher<Integer>>) invocation -> mockReadPublisher2).when(mockConnection).read();
    doAnswer((Answer<Completable>) invocation -> {
        throw DELIBERATE_EXCEPTION;
    }).when(mockConnection).write(eq(writePublisher1), any(), any());
    doAnswer((Answer<Completable>) invocation -> {
        Publisher<Integer> writePub = invocation.getArgument(0);
        return writePub.ignoreElements();
    }).when(mockConnection).write(eq(writePublisher2), any(), any());
    when(mockConnection.closeAsync()).thenReturn(completed());
    requester = new NettyPipelinedConnection<>(mockConnection, 2);
    toSource(requester.write(writePublisher1)).subscribe(readSubscriber);
    toSource(requester.write(writePublisher2)).subscribe(readSubscriber2);
    Subscription readSubscription = readSubscriber.awaitSubscription();
    readSubscription.request(1);
    assertThat(readSubscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
    assertFalse(writePublisher1.isSubscribed());
    verify(mockConnection).closeAsync();
}
Also used : UNSUPPORTED_PROTOCOL_CLOSE_HANDLER(io.servicetalk.transport.netty.internal.CloseHandler.UNSUPPORTED_PROTOCOL_CLOSE_HANDLER) BeforeEach(org.junit.jupiter.api.BeforeEach) Protocol(io.servicetalk.transport.api.ConnectionInfo.Protocol) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) MAX_VALUE(java.lang.Integer.MAX_VALUE) Future(java.util.concurrent.Future) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Executor(io.servicetalk.concurrent.api.Executor) Executors.immediate(io.servicetalk.concurrent.api.Executors.immediate) TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) CyclicBarrier(java.util.concurrent.CyclicBarrier) SynchronousQueue(java.util.concurrent.SynchronousQueue) PublisherSource(io.servicetalk.concurrent.PublisherSource) Collection(java.util.Collection) DefaultNettyConnection(io.servicetalk.transport.netty.internal.DefaultNettyConnection) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SubscriberUtils.deliverCompleteFromSource(io.servicetalk.concurrent.internal.SubscriberUtils.deliverCompleteFromSource) RetryableException(io.servicetalk.transport.api.RetryableException) WriteDemandEstimators(io.servicetalk.transport.netty.internal.WriteDemandEstimators) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FlushStrategies.defaultFlushStrategy(io.servicetalk.transport.netty.internal.FlushStrategies.defaultFlushStrategy) Matchers.is(org.hamcrest.Matchers.is) CloseHandler(io.servicetalk.transport.netty.internal.CloseHandler) NoopConnectionObserver(io.servicetalk.transport.netty.internal.NoopTransportObserver.NoopConnectionObserver) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FlushStrategy(io.servicetalk.transport.netty.internal.FlushStrategy) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Publisher(io.servicetalk.concurrent.api.Publisher) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Answer(org.mockito.stubbing.Answer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) ExecutorService(java.util.concurrent.ExecutorService) ClosedChannelException(java.nio.channels.ClosedChannelException) Single(io.servicetalk.concurrent.api.Single) Completable(io.servicetalk.concurrent.api.Completable) EmbeddedDuplexChannel(io.servicetalk.transport.netty.internal.EmbeddedDuplexChannel) Mockito.when(org.mockito.Mockito.when) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) WriteDemandEstimator(io.servicetalk.transport.netty.internal.WriteDemandEstimator) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Executors(io.servicetalk.concurrent.api.Executors) NettyConnection(io.servicetalk.transport.netty.internal.NettyConnection) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Completable(io.servicetalk.concurrent.api.Completable) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) Publisher(io.servicetalk.concurrent.api.Publisher) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) Test(org.junit.jupiter.api.Test)

Example 9 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class NettyPipelinedConnectionTest method readSubscribeThrowsWritesStillProcessed.

@Test
void readSubscribeThrowsWritesStillProcessed() {
    AtomicBoolean thrownError = new AtomicBoolean();
    Publisher<Integer> mockReadPublisher = new Publisher<Integer>() {

        @Override
        protected void handleSubscribe(final PublisherSource.Subscriber<? super Integer> subscriber) {
            if (thrownError.compareAndSet(false, true)) {
                throw DELIBERATE_EXCEPTION;
            } else {
                deliverCompleteFromSource(subscriber);
            }
        }
    };
    @SuppressWarnings("unchecked") NettyConnection<Integer, Integer> mockConnection = mock(NettyConnection.class);
    when(mockConnection.read()).thenReturn(mockReadPublisher);
    doAnswer((Answer<Completable>) invocation -> {
        Publisher<Integer> writePub = invocation.getArgument(0);
        return writePub.ignoreElements();
    }).when(mockConnection).write(any(), any(), any());
    requester = new NettyPipelinedConnection<>(mockConnection, 2);
    toSource(requester.write(writePublisher1)).subscribe(readSubscriber);
    toSource(requester.write(writePublisher2)).subscribe(readSubscriber2);
    Subscription readSubscription = readSubscriber.awaitSubscription();
    readSubscription.request(1);
    assertTrue(writePublisher1.isSubscribed());
    writePublisher1.onError(newSecondException());
    assertThat(readSubscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
    readSubscriber2.awaitSubscription();
    assertTrue(writePublisher2.isSubscribed());
    writePublisher2.onComplete();
    readSubscriber2.awaitOnComplete();
    verify(mockConnection, never()).closeAsync();
}
Also used : UNSUPPORTED_PROTOCOL_CLOSE_HANDLER(io.servicetalk.transport.netty.internal.CloseHandler.UNSUPPORTED_PROTOCOL_CLOSE_HANDLER) BeforeEach(org.junit.jupiter.api.BeforeEach) Protocol(io.servicetalk.transport.api.ConnectionInfo.Protocol) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) MAX_VALUE(java.lang.Integer.MAX_VALUE) Future(java.util.concurrent.Future) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Executor(io.servicetalk.concurrent.api.Executor) Executors.immediate(io.servicetalk.concurrent.api.Executors.immediate) TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) CyclicBarrier(java.util.concurrent.CyclicBarrier) SynchronousQueue(java.util.concurrent.SynchronousQueue) PublisherSource(io.servicetalk.concurrent.PublisherSource) Collection(java.util.Collection) DefaultNettyConnection(io.servicetalk.transport.netty.internal.DefaultNettyConnection) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SubscriberUtils.deliverCompleteFromSource(io.servicetalk.concurrent.internal.SubscriberUtils.deliverCompleteFromSource) RetryableException(io.servicetalk.transport.api.RetryableException) WriteDemandEstimators(io.servicetalk.transport.netty.internal.WriteDemandEstimators) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FlushStrategies.defaultFlushStrategy(io.servicetalk.transport.netty.internal.FlushStrategies.defaultFlushStrategy) Matchers.is(org.hamcrest.Matchers.is) CloseHandler(io.servicetalk.transport.netty.internal.CloseHandler) NoopConnectionObserver(io.servicetalk.transport.netty.internal.NoopTransportObserver.NoopConnectionObserver) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FlushStrategy(io.servicetalk.transport.netty.internal.FlushStrategy) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Publisher(io.servicetalk.concurrent.api.Publisher) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Answer(org.mockito.stubbing.Answer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) ExecutorService(java.util.concurrent.ExecutorService) ClosedChannelException(java.nio.channels.ClosedChannelException) Single(io.servicetalk.concurrent.api.Single) Completable(io.servicetalk.concurrent.api.Completable) EmbeddedDuplexChannel(io.servicetalk.transport.netty.internal.EmbeddedDuplexChannel) Mockito.when(org.mockito.Mockito.when) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) WriteDemandEstimator(io.servicetalk.transport.netty.internal.WriteDemandEstimator) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Executors(io.servicetalk.concurrent.api.Executors) NettyConnection(io.servicetalk.transport.netty.internal.NettyConnection) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Completable(io.servicetalk.concurrent.api.Completable) TestPublisherSubscriber(io.servicetalk.concurrent.test.internal.TestPublisherSubscriber) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) Publisher(io.servicetalk.concurrent.api.Publisher) TestSubscription(io.servicetalk.concurrent.api.TestSubscription) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) Test(org.junit.jupiter.api.Test)

Example 10 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class HttpSerializerErrorTest method serializationMapThrowsPropagatesToClient.

@ParameterizedTest
@MethodSource("executors")
void serializationMapThrowsPropagatesToClient(HttpTestExecutionStrategy serverStrategy) throws Exception {
    serverExecutionStrategy = serverStrategy.executorSupplier.get();
    TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
    };
    HttpStreamingSerializerDeserializer<Map<String, Object>> streamingSerializer = jsonStreamingSerializer(JACKSON.streamingSerializerDeserializer(mapType));
    HttpSerializerDeserializer<Map<String, Object>> serializer = HttpSerializers.jsonSerializer(JACKSON.serializerDeserializer(mapType));
    try (ServerContext srv = HttpServers.forAddress(localAddress(0)).executionStrategy(serverExecutionStrategy).listenAndAwait((ctx, request, responseFactory) -> responseFactory.ok().toStreamingResponse().payloadBody(request.toStreamingRequest().payloadBody(streamingSerializer).map(result -> {
        throw DELIBERATE_EXCEPTION;
    }), streamingSerializer).toResponse());
        BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
        HttpResponse resp = clt.request(clt.post("/foo").payloadBody(emptyMap(), serializer));
        assertEquals(INTERNAL_SERVER_ERROR, resp.status());
    }
}
Also used : HttpSerializers.jsonStreamingSerializer(io.servicetalk.http.api.HttpSerializers.jsonStreamingSerializer) SerializationException(io.servicetalk.serializer.api.SerializationException) BAD_REQUEST(io.servicetalk.http.api.HttpResponseStatus.BAD_REQUEST) HttpPayloadWriter(io.servicetalk.http.api.HttpPayloadWriter) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) MethodSource(org.junit.jupiter.params.provider.MethodSource) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Collections.emptyMap(java.util.Collections.emptyMap) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) JACKSON(io.servicetalk.data.jackson.JacksonSerializerFactory.JACKSON) DEFAULT(io.servicetalk.http.netty.HttpTestExecutionStrategy.DEFAULT) Collection(java.util.Collection) HttpResponse(io.servicetalk.http.api.HttpResponse) BlockingIterable(io.servicetalk.concurrent.BlockingIterable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpStreamingSerializerDeserializer(io.servicetalk.http.api.HttpStreamingSerializerDeserializer) NO_OFFLOAD(io.servicetalk.http.netty.HttpTestExecutionStrategy.NO_OFFLOAD) HttpSerializers(io.servicetalk.http.api.HttpSerializers) HttpSerializerDeserializer(io.servicetalk.http.api.HttpSerializerDeserializer) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)49 Test (org.junit.jupiter.api.Test)46 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)42 Matchers.is (org.hamcrest.Matchers.is)37 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)32 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)28 Mockito.mock (org.mockito.Mockito.mock)27 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)24 Future (java.util.concurrent.Future)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)21 Mockito.verify (org.mockito.Mockito.verify)21 PublisherSource (io.servicetalk.concurrent.PublisherSource)19 Arrays.asList (java.util.Arrays.asList)19 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)19 Mockito.doAnswer (org.mockito.Mockito.doAnswer)19 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)17 DeliberateException (io.servicetalk.concurrent.internal.DeliberateException)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 ExecutionException (java.util.concurrent.ExecutionException)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17