Search in sources :

Example 1 with DeliberateException

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));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 2 with DeliberateException

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]);
}
Also used : TestSingleSubscriber(io.servicetalk.concurrent.test.internal.TestSingleSubscriber) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 3 with DeliberateException

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);
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 4 with DeliberateException

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]);
}
Also used : TestSingleSubscriber(io.servicetalk.concurrent.test.internal.TestSingleSubscriber) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 5 with DeliberateException

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));
    }
}
Also used : InputStream(java.io.InputStream) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Aggregations

DeliberateException (io.servicetalk.concurrent.internal.DeliberateException)80 Test (org.junit.jupiter.api.Test)77 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)6 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 TestPublisherSubscriber (io.servicetalk.concurrent.test.internal.TestPublisherSubscriber)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)5 PublisherSource (io.servicetalk.concurrent.PublisherSource)4 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)4 TerminalSignalConsumer (io.servicetalk.concurrent.api.TerminalSignalConsumer)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Subscriber (io.servicetalk.concurrent.PublisherSource.Subscriber)3 SourceAdapters.fromSource (io.servicetalk.concurrent.api.SourceAdapters.fromSource)3 PlatformDependent.throwException (io.servicetalk.utils.internal.PlatformDependent.throwException)3 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)3