use of com.palantir.dialogue.Response in project dialogue by palantir.
the class RetryingChannelTest method doesNotRetrySocketTimeout.
@Test
public void doesNotRetrySocketTimeout() {
when(channel.execute(any())).thenReturn(Futures.immediateFailedFuture(new SocketTimeoutException())).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(SocketTimeoutException.class);
}
use of com.palantir.dialogue.Response 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);
}
use of com.palantir.dialogue.Response 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);
}
use of com.palantir.dialogue.Response 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);
}
use of com.palantir.dialogue.Response 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);
}
Aggregations