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