Search in sources :

Example 6 with DeliberateException

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

the class AbstractWhenOnErrorTest method testCallbackThrowsError.

@Test
void testCallbackThrowsError() {
    DeliberateException srcEx = new DeliberateException();
    toSource(doError(Single.<String>failed(srcEx), t -> {
        throw DELIBERATE_EXCEPTION;
    })).subscribe(listener);
    assertThat(listener.awaitOnError(), is(srcEx));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 7 with DeliberateException

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

the class BeforeErrorTest method testCallbackThrowsError.

@Override
@Test
void testCallbackThrowsError() {
    DeliberateException srcEx = new DeliberateException();
    this.<String>doError(Publisher.failed(srcEx), t1 -> {
        throw DELIBERATE_EXCEPTION;
    }).subscribe(subscriber);
    subscriber.awaitSubscription().request(1);
    assertThat(subscriber.awaitOnError(), sameInstance(srcEx));
    verifySuppressed(subscriber.awaitOnError(), DELIBERATE_EXCEPTION);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) VerificationTestUtils.verifySuppressed(io.servicetalk.concurrent.api.VerificationTestUtils.verifySuppressed) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Publisher(io.servicetalk.concurrent.api.Publisher) PublisherSource(io.servicetalk.concurrent.PublisherSource) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 8 with DeliberateException

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

the class RetryTest method testMaxRetries.

@Test
void testMaxRetries() {
    shouldRetryValue = true;
    subscriber.awaitSubscription().request(3);
    source.onNext(1, 2);
    source.onError(DELIBERATE_EXCEPTION);
    assertThat(subscriber.takeOnNext(2), contains(1, 2));
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    verify(shouldRetry).test(1, DELIBERATE_EXCEPTION);
    shouldRetryValue = false;
    DeliberateException fatal = new DeliberateException();
    source.onError(fatal);
    assertThat(subscriber.awaitOnError(), sameInstance(fatal));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 9 with DeliberateException

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

the class SingleZip4Test method delayErrorOneFail.

@Test
void delayErrorOneFail() {
    toSource(zipDelayError(first, second, third, fourth, SingleZip4Test::combine)).subscribe(subscriber);
    subscriber.awaitSubscription();
    DeliberateException e1 = new DeliberateException();
    second.onError(e1);
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), nullValue());
    first.onSuccess(1);
    third.onSuccess((short) 22);
    fourth.onSuccess((byte) 5);
    assertThat(subscriber.awaitOnError(), is(e1));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 10 with DeliberateException

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

the class SingleZip4Test method delayErrorAllFail.

@Test
void delayErrorAllFail() {
    toSource(zipDelayError(first, second, third, fourth, SingleZip4Test::combine)).subscribe(subscriber);
    subscriber.awaitSubscription();
    DeliberateException e1 = new DeliberateException();
    second.onError(e1);
    assertThat(subscriber.pollTerminal(10, MILLISECONDS), nullValue());
    DeliberateException e2 = new DeliberateException();
    first.onError(e2);
    DeliberateException e3 = new DeliberateException();
    third.onError(e3);
    DeliberateException e4 = new DeliberateException();
    fourth.onError(e4);
    assertThat(subscriber.awaitOnError(), is(e1));
    assertThat(asList(e1.getSuppressed()), contains(e2, e3, e4));
}
Also used : 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