Search in sources :

Example 11 with DeliberateException

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

the class SingleZipWithTest method delayErrorAllFail.

@Test
void delayErrorAllFail() {
    toSource(first.zipWithDelayError(second, SingleZipWithTest::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);
    assertThat(subscriber.awaitOnError(), is(e1));
    assertThat(asList(e1.getSuppressed()), contains(e2));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 12 with DeliberateException

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

the class AfterFinallyTest method testCallbackThrowsErrorOnError.

@Test
@Override
void testCallbackThrowsErrorOnError() {
    TerminalSignalConsumer mock = throwableMock(new DeliberateException());
    toSource(doFinally(Completable.failed(DELIBERATE_EXCEPTION), mock)).subscribe(listener);
    assertThat(listener.awaitOnError(), is(DELIBERATE_EXCEPTION));
    verify(mock).onError(DELIBERATE_EXCEPTION);
    verifyNoMoreInteractions(mock);
}
Also used : TerminalSignalConsumer(io.servicetalk.concurrent.api.TerminalSignalConsumer) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 13 with DeliberateException

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

the class BeforeFinallyTest method testCallbackThrowsErrorOnError.

@Override
@Test
void testCallbackThrowsErrorOnError() {
    DeliberateException exception = new DeliberateException();
    TerminalSignalConsumer mock = throwableMock(exception);
    doFinally(publisher, mock).subscribe(subscriber);
    publisher.onError(DELIBERATE_EXCEPTION);
    Throwable receivedError = subscriber.awaitOnError();
    assertThat(receivedError, is(notNullValue()));
    assertThat(receivedError, sameInstance(exception));
    assertThat(receivedError.getSuppressed()[0], sameInstance(DELIBERATE_EXCEPTION));
    verify(mock).onError(DELIBERATE_EXCEPTION);
    verifyNoMoreInteractions(mock);
    assertFalse(subscription.isCancelled());
}
Also used : TerminalSignalConsumer(io.servicetalk.concurrent.api.TerminalSignalConsumer) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 14 with DeliberateException

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

the class BeforeFinallyTest method testCallbackThrowsErrorOnError.

@Test
@Override
void testCallbackThrowsErrorOnError() {
    DeliberateException exception = new DeliberateException();
    TerminalSignalConsumer mock = throwableMock(exception);
    toSource(doFinally(Completable.failed(DELIBERATE_EXCEPTION), mock)).subscribe(listener);
    assertThat(listener.awaitOnError(), is(exception));
    assertThat(listener.awaitOnError().getSuppressed()[0], is(DELIBERATE_EXCEPTION));
    verify(mock).onError(DELIBERATE_EXCEPTION);
    verifyNoMoreInteractions(mock);
}
Also used : TerminalSignalConsumer(io.servicetalk.concurrent.api.TerminalSignalConsumer) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 15 with DeliberateException

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

the class AbstractWhenCancelTest method testCallbackThrowsError.

@Test
void testCallbackThrowsError() {
    LegacyTestCompletable completable = new LegacyTestCompletable();
    DeliberateException e = assertThrows(DeliberateException.class, () -> {
        try {
            toSource(doCancel(completable, () -> {
                throw DELIBERATE_EXCEPTION;
            })).subscribe(listener);
            listener.awaitSubscription().cancel();
        } finally {
            completable.verifyCancelled();
        }
    });
    assertThat(e, is(sameInstance(DELIBERATE_EXCEPTION)));
}
Also used : LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) 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