Search in sources :

Example 26 with Completable

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

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method defaultForNoAvailableHostOnServiceDiscovererError.

@ParameterizedTest
@ValueSource(booleans = { false, true })
void defaultForNoAvailableHostOnServiceDiscovererError(boolean offloading) {
    final ContextAwareRetryingHttpClientFilter filter = newFilter(new RetryingHttpRequesterFilter.Builder(), offloading);
    Completable retry = applyRetry(filter, 1, NO_AVAILABLE_HOST);
    toSource(retry).subscribe(retrySubscriber);
    assertThat(retrySubscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    sdStatus.onError(DELIBERATE_EXCEPTION);
    verifyRetryResultError(DELIBERATE_EXCEPTION);
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Completable

use of io.servicetalk.concurrent.api.Completable 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 28 with Completable

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

the class ChannelSetTest method closeAsync.

@Test
void closeAsync() {
    Completable completable = fixture.closeAsync();
    verify(channel, never()).close();
    TestCompletableSubscriber subscriber = new TestCompletableSubscriber();
    toSource(completable).subscribe(subscriber);
    verify(channel).close();
    subscriber.awaitOnComplete();
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Test(org.junit.jupiter.api.Test)

Example 29 with Completable

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

the class ChannelSetTest method testCloseAsyncThenCloseAsyncGracefully.

@Test
void testCloseAsyncThenCloseAsyncGracefully() throws Exception {
    Completable closeCompletable = fixture.closeAsync();
    Completable gracefulCompletable = closeAsyncGracefully(fixture, 100, SECONDS);
    TestCompletableSubscriber subscriber = new TestCompletableSubscriber();
    toSource(closeCompletable).subscribe(subscriber);
    verify(channel).close();
    TestCompletableSubscriber subscriber2 = new TestCompletableSubscriber();
    toSource(gracefulCompletable).subscribe(subscriber2);
    fixture.onClose().toFuture().get();
    subscriber.awaitOnComplete();
    subscriber2.awaitOnComplete();
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Test(org.junit.jupiter.api.Test)

Example 30 with Completable

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

the class ChannelSetTest method closeAsyncGracefullyWithoutNettyConnectionChannelHandler.

@Test
void closeAsyncGracefullyWithoutNettyConnectionChannelHandler() {
    when(mockClosableAttribute.getAndSet(any())).thenReturn(null);
    Completable completable = closeAsyncGracefully(fixture, 100, SECONDS);
    verify(channel, never()).close();
    TestCompletableSubscriber subscriber = new TestCompletableSubscriber();
    toSource(completable).subscribe(subscriber);
    verify(channel).close();
    subscriber.awaitOnComplete();
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Test(org.junit.jupiter.api.Test)

Aggregations

Completable (io.servicetalk.concurrent.api.Completable)73 Test (org.junit.jupiter.api.Test)46 TestCompletable (io.servicetalk.concurrent.api.TestCompletable)31 ContextAwareRetryingHttpClientFilter (io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter)28 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 TestCompletableSubscriber (io.servicetalk.concurrent.test.internal.TestCompletableSubscriber)19 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)17 Matchers.is (org.hamcrest.Matchers.is)16 ValueSource (org.junit.jupiter.params.provider.ValueSource)16 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)15 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)14 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)13 Mockito.mock (org.mockito.Mockito.mock)13 DEFAULT_ALLOCATOR (io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR)12 Answer (org.mockito.stubbing.Answer)12 Executors.immediate (io.servicetalk.concurrent.api.Executors.immediate)11 Single (io.servicetalk.concurrent.api.Single)11 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)11 Mockito.when (org.mockito.Mockito.when)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10