use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherConcatMapIterableTest method exceptionFromOnErrorIsPropagated.
@Test
void exceptionFromOnErrorIsPropagated() {
toSource(publisher.flatMapConcatIterable(identity()).afterOnError(t -> {
throw DELIBERATE_EXCEPTION;
})).subscribe(subscriber);
subscriber.awaitSubscription();
DeliberateException exception = assertThrows(DeliberateException.class, () -> publisher.onError(DELIBERATE_EXCEPTION));
assertThat(exception, is(DELIBERATE_EXCEPTION));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherConcatMapIterableTest method testExceptionFromBufferedOnNextThenTerminalIsPropagated.
@Test
void testExceptionFromBufferedOnNextThenTerminalIsPropagated() {
final DeliberateException ex2 = new DeliberateException();
final AtomicBoolean errored = new AtomicBoolean();
toSource(publisher.flatMapConcatIterable(identity()).map((Function<String, String>) s -> {
if (!errored.getAndSet(true)) {
publisher.onError(DELIBERATE_EXCEPTION);
}
throw ex2;
})).subscribe(subscriber);
subscriber.awaitSubscription().request(3);
publisher.onNext(asList("one", "two", "three"));
assertThat(subscriber.awaitOnError(), is(ex2));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherConcatMapIterableTest method upstreamRecoverWithMakesProgress.
@Test
void upstreamRecoverWithMakesProgress() throws Exception {
@SuppressWarnings("unchecked") Subscriber<String> mockSubscriber = mock(Subscriber.class);
CountDownLatch latchOnSubscribe = new CountDownLatch(1);
CountDownLatch latchOnError = new CountDownLatch(1);
AtomicReference<Throwable> causeRef = new AtomicReference<>();
AtomicInteger nextCount = new AtomicInteger();
List<String> results = new ArrayList<>();
doAnswer(a -> {
Subscription s = a.getArgument(0);
s.request(Long.MAX_VALUE);
latchOnSubscribe.countDown();
return null;
}).when(mockSubscriber).onSubscribe(any(Subscription.class));
doAnswer(a -> {
causeRef.set(a.getArgument(0));
latchOnError.countDown();
return null;
}).when(mockSubscriber).onError(eq(DELIBERATE_EXCEPTION));
doAnswer(a -> {
results.add(a.getArgument(0));
if (nextCount.getAndIncrement() == 0) {
throw new DeliberateException();
}
// final exception
throw DELIBERATE_EXCEPTION;
}).when(mockSubscriber).onNext(any());
Processor<List<String>, List<String>> processor = newPublisherProcessor();
toSource(fromSource(processor).onErrorResume(cause -> {
if (cause != DELIBERATE_EXCEPTION) {
// recover!
return from(singletonList("two"));
}
return failed(cause);
}).flatMapConcatIterable(identity())).subscribe(mockSubscriber);
latchOnSubscribe.await();
processor.onNext(asList("one", "ignored!"));
latchOnError.await();
assertThat(results, contains("one", "two"));
assertThat(causeRef.get(), is(DELIBERATE_EXCEPTION));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherFlatMapSingleTest method testMultipleSingleErrors.
@Test
void testMultipleSingleErrors() {
Queue<DeliberateException> errors = new ArrayDeque<>();
toSource(source.flatMapMergeSingleDelayError(integer -> {
DeliberateException de = new DeliberateException();
errors.add(de);
return Single.<Integer>failed(de);
}, 2, 2)).subscribe(subscriber);
subscriber.awaitSubscription().request(3);
source.onNext(1, 1);
source.onComplete();
Throwable cause = subscriber.awaitOnError();
assertThat(errors, hasSize(2));
assertThat(asList(cause.getSuppressed()), hasSize(1));
assertThat(cause, is(errors.poll()));
assertThat(cause.getSuppressed()[0], is(errors.poll()));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class OnErrorCompletableTest method onErrorResumePredicateMatch.
@Test
void onErrorResumePredicateMatch() {
toSource(first.onErrorResume(t -> t instanceof DeliberateException, t -> failed(DELIBERATE_EXCEPTION))).subscribe(subscriber);
subscriber.awaitSubscription();
first.onError(new DeliberateException());
assertThat(subscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
}
Aggregations