Search in sources :

Example 21 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class RetryingChannelTest method doesNotRetryRuntimeException.

@Test
public void doesNotRetryRuntimeException() {
    when(channel.execute(any())).thenReturn(Futures.immediateFailedFuture(new SafeRuntimeException("bug"))).thenReturn(SUCCESS);
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 1, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThatThrownBy(response::get).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("bug");
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 22 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class RetryingChannelTest method retries_308s_when_429_and_503_are_propagated.

@Test
public void retries_308s_when_429_and_503_are_propagated() throws Exception {
    Response mockResponse = mock(Response.class);
    when(mockResponse.code()).thenReturn(308);
    when(mockResponse.getFirstHeader(eq("Location"))).thenReturn(Optional.of("https://localhost"));
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(mockResponse));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, // This does not apply to 308 responses
    ClientConfiguration.ServerQoS.PROPAGATE_429_and_503_TO_CALLER, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get()).as("After retries are exhausted the 308 response should be returned").isSameAs(mockResponse);
    verify(channel, times(4)).execute(REQUEST);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 23 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class RetryingChannelTest method doesnt_retry_500s_for_post.

@Test
public void doesnt_retry_500s_for_post() throws Exception {
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(new TestResponse().code(500)));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get().code()).isEqualTo(500);
    verify(channel, times(1)).execute(REQUEST);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) TestResponse(com.palantir.dialogue.TestResponse) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 24 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class RetryingChannelTest method testNoFailures.

@Test
public void testNoFailures() throws ExecutionException, InterruptedException {
    when(channel.execute(any())).thenReturn(SUCCESS);
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response.get()).isEqualTo(EXPECTED_RESPONSE);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 25 with EndpointChannel

use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.

the class RetryingChannelTest method retries_500s_for_delete.

@Test
public void retries_500s_for_delete() throws Exception {
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(new TestResponse().code(500))).thenReturn(Futures.immediateFuture(new TestResponse().code(200)));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.DELETE, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get().code()).isEqualTo(200);
    verify(channel, times(2)).execute(REQUEST);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) TestResponse(com.palantir.dialogue.TestResponse) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Aggregations

EndpointChannel (com.palantir.dialogue.EndpointChannel)32 Test (org.junit.jupiter.api.Test)28 Response (com.palantir.dialogue.Response)25 TestResponse (com.palantir.dialogue.TestResponse)25 Endpoint (com.palantir.dialogue.Endpoint)6 HttpMethod (com.palantir.dialogue.HttpMethod)4 Request (com.palantir.dialogue.Request)4 Channel (com.palantir.dialogue.Channel)3 RequestBody (com.palantir.dialogue.RequestBody)3 TestEndpoint (com.palantir.dialogue.TestEndpoint)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ByteStreams (com.google.common.io.ByteStreams)2 Futures (com.google.common.util.concurrent.Futures)2 SafeLong (com.palantir.conjure.java.lib.SafeLong)2 ClientEndpoint (com.palantir.conjure.java.lib.internal.ClientEndpoint)2