Search in sources :

Example 1 with ContextAwareRetryingHttpClientFilter

use of io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter in project servicetalk by apple.

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method defaultForNoAvailableHostWhenServiceDiscovererTerminated.

@Test
void defaultForNoAvailableHostWhenServiceDiscovererTerminated() {
    final ContextAwareRetryingHttpClientFilter filter = newFilter(new RetryingHttpRequesterFilter.Builder());
    Completable retry = applyRetry(filter, 1, NO_AVAILABLE_HOST);
    toSource(retry).subscribe(retrySubscriber);
    assertThat(retrySubscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    sdStatus.onComplete();
    verifyRetryResultCompleted();
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) Test(org.junit.jupiter.api.Test)

Example 2 with ContextAwareRetryingHttpClientFilter

use of io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter in project servicetalk by apple.

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method defaultForNoAvailableHostOnUnknownHostException.

@Test
void defaultForNoAvailableHostOnUnknownHostException() {
    final ContextAwareRetryingHttpClientFilter filter = newFilter(new RetryingHttpRequesterFilter.Builder());
    Completable retry = applyRetry(filter, 1, NO_AVAILABLE_HOST);
    toSource(retry).subscribe(retrySubscriber);
    assertThat(retrySubscriber.pollTerminal(10, MILLISECONDS), is(nullValue()));
    sdStatus.onError(UNKNOWN_HOST_EXCEPTION);
    verifyRetryResultError(UNKNOWN_HOST_EXCEPTION);
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) Test(org.junit.jupiter.api.Test)

Example 3 with ContextAwareRetryingHttpClientFilter

use of io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter in project servicetalk by apple.

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method defaultForNoAvailableHostMaxRetries.

@Test
void defaultForNoAvailableHostMaxRetries() {
    final ContextAwareRetryingHttpClientFilter filter = newFilter(new RetryingHttpRequesterFilter.Builder().ignoreServiceDiscovererErrors(true));
    lbEvents.onComplete();
    for (int i = 1; i <= 5; i++) {
        Completable retry = applyRetry(filter, i, NO_AVAILABLE_HOST);
        TestCompletableSubscriber subscriber = new TestCompletableSubscriber();
        toSource(retry).subscribe(subscriber);
        if (i < 5) {
            assertThat(subscriber.awaitOnError(), instanceOf(IllegalStateException.class));
        } else {
            // ambWith operator could return either error back.
            assertThat(subscriber.awaitOnError(), anyOf(instanceOf(NoAvailableHostException.class), instanceOf(IllegalStateException.class)));
        }
    }
}
Also used : Completable(io.servicetalk.concurrent.api.Completable) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Test(org.junit.jupiter.api.Test)

Example 4 with ContextAwareRetryingHttpClientFilter

use of io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter in project servicetalk by apple.

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method defaultForNoAvailableHostOnServiceDiscovererError.

@Test
void defaultForNoAvailableHostOnServiceDiscovererError() {
    final ContextAwareRetryingHttpClientFilter filter = newFilter(new RetryingHttpRequesterFilter.Builder());
    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) Test(org.junit.jupiter.api.Test)

Example 5 with ContextAwareRetryingHttpClientFilter

use of io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter in project servicetalk by apple.

the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method newFilter.

private ContextAwareRetryingHttpClientFilter newFilter(final RetryingHttpRequesterFilter filter) {
    final FilterableStreamingHttpClient client = mock(FilterableStreamingHttpClient.class);
    final HttpExecutionContext executionContext = mock(HttpExecutionContext.class);
    when(executionContext.executor()).then((Answer<Executor>) invocation -> immediate());
    when(client.executionContext()).then(__ -> executionContext);
    final ContextAwareRetryingHttpClientFilter f = (ContextAwareRetryingHttpClientFilter) filter.create(client);
    f.inject(lbEvents, sdStatus);
    return f;
}
Also used : FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestCompletableSubscriber(io.servicetalk.concurrent.test.internal.TestCompletableSubscriber) Answer(org.mockito.stubbing.Answer) BackOffPolicy.ofNoRetries(io.servicetalk.http.netty.RetryingHttpRequesterFilter.BackOffPolicy.ofNoRetries) Executor(io.servicetalk.concurrent.Executor) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Nonnull(javax.annotation.Nonnull) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) Executors.immediate(io.servicetalk.concurrent.api.Executors.immediate) RetryableConnectException(io.servicetalk.client.api.RetryableConnectException) Completable(io.servicetalk.concurrent.api.Completable) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) LOAD_BALANCER_READY_EVENT(io.servicetalk.client.api.LoadBalancerReadyEvent.LOAD_BALANCER_READY_EVENT) NoAvailableHostException(io.servicetalk.client.api.NoAvailableHostException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) GET(io.servicetalk.http.api.HttpRequestMethod.GET) StreamingHttpRequests.newRequest(io.servicetalk.http.api.StreamingHttpRequests.newRequest) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) RetryingHttpRequesterFilter.disableAutoRetries(io.servicetalk.http.netty.RetryingHttpRequesterFilter.disableAutoRetries) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) TestCompletable(io.servicetalk.concurrent.api.TestCompletable) Matchers.is(org.hamcrest.Matchers.is) Matchers.anyOf(org.hamcrest.Matchers.anyOf) INSTANCE(io.servicetalk.http.api.DefaultHttpHeadersFactory.INSTANCE) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) Mockito.mock(org.mockito.Mockito.mock) Executor(io.servicetalk.concurrent.Executor) ContextAwareRetryingHttpClientFilter(io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext)

Aggregations

Completable (io.servicetalk.concurrent.api.Completable)15 TestCompletable (io.servicetalk.concurrent.api.TestCompletable)15 ContextAwareRetryingHttpClientFilter (io.servicetalk.http.netty.RetryingHttpRequesterFilter.ContextAwareRetryingHttpClientFilter)15 Test (org.junit.jupiter.api.Test)15 TestCompletableSubscriber (io.servicetalk.concurrent.test.internal.TestCompletableSubscriber)5 DEFAULT_ALLOCATOR (io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR)4 LOAD_BALANCER_READY_EVENT (io.servicetalk.client.api.LoadBalancerReadyEvent.LOAD_BALANCER_READY_EVENT)4 NoAvailableHostException (io.servicetalk.client.api.NoAvailableHostException)4 RetryableConnectException (io.servicetalk.client.api.RetryableConnectException)4 Executor (io.servicetalk.concurrent.Executor)4 Executors.immediate (io.servicetalk.concurrent.api.Executors.immediate)4 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)4 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)4 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)4 INSTANCE (io.servicetalk.http.api.DefaultHttpHeadersFactory.INSTANCE)4 FilterableStreamingHttpClient (io.servicetalk.http.api.FilterableStreamingHttpClient)4 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)4 HTTP_1_1 (io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1)4 HttpRequestMetaData (io.servicetalk.http.api.HttpRequestMetaData)4 GET (io.servicetalk.http.api.HttpRequestMethod.GET)4