Search in sources :

Example 1 with LegacyTestCompletable

use of io.servicetalk.concurrent.api.LegacyTestCompletable in project servicetalk by apple.

the class RetryWhenTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
void setUp() {
    source = new LegacyTestSingle<>(false, false);
    shouldRetry = (BiIntFunction<Throwable, Completable>) mock(BiIntFunction.class);
    retrySignal = new LegacyTestCompletable();
    when(shouldRetry.apply(anyInt(), any())).thenAnswer(invocation -> {
        retrySignal = new LegacyTestCompletable();
        return retrySignal;
    });
    toSource(source.retryWhen(shouldRetry)).subscribe(subscriberRule);
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with LegacyTestCompletable

use of io.servicetalk.concurrent.api.LegacyTestCompletable in project servicetalk by apple.

the class RetryWhenTest method setUp.

@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
    shouldRetry = (BiIntFunction<Throwable, Completable>) mock(BiIntFunction.class);
    retrySignal = new LegacyTestCompletable();
    when(shouldRetry.apply(anyInt(), any())).thenAnswer(invocation -> {
        retrySignal = new LegacyTestCompletable();
        return retrySignal;
    });
    toSource(source.retryWhen(shouldRetry)).subscribe(subscriber);
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with LegacyTestCompletable

use of io.servicetalk.concurrent.api.LegacyTestCompletable 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)

Example 4 with LegacyTestCompletable

use of io.servicetalk.concurrent.api.LegacyTestCompletable in project servicetalk by apple.

the class AbstractWhenCancelTest method testCancelNoEmissions.

@Test
void testCancelNoEmissions() {
    Runnable onCancel = Mockito.mock(Runnable.class);
    LegacyTestCompletable completable = new LegacyTestCompletable();
    toSource(doCancel(completable, onCancel)).subscribe(listener);
    listener.awaitSubscription().cancel();
    verify(onCancel).run();
    completable.verifyCancelled();
}
Also used : LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) Test(org.junit.jupiter.api.Test)

Example 5 with LegacyTestCompletable

use of io.servicetalk.concurrent.api.LegacyTestCompletable in project servicetalk by apple.

the class AbstractWhenFinallyTest method testCallbackThrowsErrorWhenCancel.

@Test
void testCallbackThrowsErrorWhenCancel() {
    TerminalSignalConsumer mock = throwableMock(DELIBERATE_EXCEPTION);
    LegacyTestCompletable completable = new LegacyTestCompletable();
    try {
        toSource(doFinally(completable, mock)).subscribe(listener);
        Exception e = assertThrows(DeliberateException.class, () -> listener.awaitSubscription().cancel());
        assertThat(e, is(sameInstance(DELIBERATE_EXCEPTION)));
    } finally {
        completable.verifyCancelled();
        verify(mock).cancel();
        verifyNoMoreInteractions(mock);
    }
}
Also used : TerminalSignalConsumer(io.servicetalk.concurrent.api.TerminalSignalConsumer) LegacyTestCompletable(io.servicetalk.concurrent.api.LegacyTestCompletable) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Aggregations

LegacyTestCompletable (io.servicetalk.concurrent.api.LegacyTestCompletable)8 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Completable (io.servicetalk.concurrent.api.Completable)3 Test (org.junit.jupiter.api.Test)3 DeliberateException (io.servicetalk.concurrent.internal.DeliberateException)2 TerminalSignalConsumer (io.servicetalk.concurrent.api.TerminalSignalConsumer)1