Search in sources :

Example 6 with EndpointChannel

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

the class RetryingChannelTest method propagates_429s_when_requested.

@Test
public void propagates_429s_when_requested() throws Exception {
    Response mockResponse = mock(Response.class);
    when(mockResponse.code()).thenReturn(429);
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(mockResponse));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.PROPAGATE_429_and_503_TO_CALLER, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get().code()).isEqualTo(429);
    verify(channel, times(1)).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 7 with EndpointChannel

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

the class RetryingChannelTest method returns_503s_when_requested.

@Test
public void returns_503s_when_requested() throws Exception {
    Response mockResponse = mock(Response.class);
    when(mockResponse.code()).thenReturn(503);
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(mockResponse));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.PROPAGATE_429_and_503_TO_CALLER, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get().code()).isEqualTo(503);
    verify(channel, times(1)).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 8 with EndpointChannel

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

the class RetryingChannelTest method retries_308s.

@Test
public void retries_308s() 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));
    long startTime = System.nanoTime();
    Duration backoffSlotSize = Duration.ofSeconds(10);
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, backoffSlotSize, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, 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);
    assertThat(Duration.ofNanos(System.nanoTime() - startTime)).as("308 responses should be immediately retried").isLessThan(backoffSlotSize);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Duration(java.time.Duration) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 9 with EndpointChannel

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

the class RetryingChannelTest method retries_500s_for_put.

@Test
public void retries_500s_for_put() 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.PUT, "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)

Example 10 with EndpointChannel

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

the class RetryingChannelTest method does_not_retry_308_without_location.

@Test
public void does_not_retry_308_without_location() throws Exception {
    Response mockResponse = mock(Response.class);
    when(mockResponse.code()).thenReturn(308);
    when(channel.execute(any())).thenReturn(Futures.immediateFuture(mockResponse));
    EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ofSeconds(1), ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
    ListenableFuture<Response> response = retryer.execute(REQUEST);
    assertThat(response).isDone();
    assertThat(response.get()).isSameAs(mockResponse);
    verify(channel, times(1)).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)

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