use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class RetryWhenTest method testMaxRetries.
@Test
void testMaxRetries() {
source.onError(DELIBERATE_EXCEPTION);
// trigger retry
retrySignal.onComplete();
assertThat(subscriberRule.pollTerminal(10, MILLISECONDS), is(nullValue()));
verify(shouldRetry).apply(1, DELIBERATE_EXCEPTION);
source.verifyListenCalled().onError(DELIBERATE_EXCEPTION);
DeliberateException fatal = new DeliberateException();
// stop retry
retrySignal.verifyListenCalled().onError(fatal);
assertThat(subscriberRule.awaitOnError(), is(fatal));
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class RetryWhenTest method exceptionInTerminalCallsOnError.
@Test
void exceptionInTerminalCallsOnError() {
DeliberateException ex = new DeliberateException();
TestSingleSubscriber<Integer> subscriberRule = new TestSingleSubscriber<>();
source = new LegacyTestSingle<>(false, false);
toSource(source.retryWhen((times, cause) -> {
throw ex;
})).subscribe(subscriberRule);
source.onError(DELIBERATE_EXCEPTION);
assertThat(subscriberRule.awaitOnError(), is(ex));
assertEquals(1, ex.getSuppressed().length);
assertSame(DELIBERATE_EXCEPTION, ex.getSuppressed()[0]);
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class RetryWhenTest method testRetryCount.
@Test
void testRetryCount() {
source.onError(DELIBERATE_EXCEPTION);
assertThat(subscriberRule.pollTerminal(10, MILLISECONDS), is(nullValue()));
DeliberateException fatal = new DeliberateException();
// stop retry
retrySignal.onError(fatal);
assertThat(subscriberRule.awaitOnError(), is(fatal));
verify(shouldRetry).apply(1, DELIBERATE_EXCEPTION);
verifyNoMoreInteractions(shouldRetry);
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class RetryTest method exceptionInTerminalCallsOnError.
@Test
void exceptionInTerminalCallsOnError() {
DeliberateException ex = new DeliberateException();
TestSingleSubscriber<Integer> subscriberRule = new TestSingleSubscriber<>();
source = new LegacyTestSingle<>(false, false);
toSource(source.retry((times, cause) -> {
throw ex;
})).subscribe(subscriberRule);
source.onError(DELIBERATE_EXCEPTION);
assertThat(subscriberRule.awaitOnError(), is(ex));
assertEquals(1, ex.getSuppressed().length);
assertSame(DELIBERATE_EXCEPTION, ex.getSuppressed()[0]);
}
use of io.servicetalk.concurrent.internal.DeliberateException in project servicetalk by apple.
the class PublisherAsInputStreamTest method streamErrorShouldBeEmittedPostData.
@Test
void streamErrorShouldBeEmittedPostData() throws IOException {
DeliberateException de = new DeliberateException();
Character[] src = { '1', '2', '3', '4' };
InputStream stream = from(src).concat(Completable.failed(de)).toInputStream(c -> new byte[] { (byte) c.charValue() });
byte[] data = new byte[4];
try {
stream.read(data, 0, 4);
} catch (DeliberateException e) {
assertThat("Unexpected exception.", e, sameInstance(de));
assertThat("Unexpected bytes read.", bytesToCharArray(data, 4), equalTo(src));
}
}
Aggregations