use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.
the class RetryingChannelTest method retries_500s_when_method_is_safe_and_idempotent_when_qos_propagated.
@Test
public void retries_500s_when_method_is_safe_and_idempotent_when_qos_propagated() 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.GET, "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(200);
verify(channel, times(2)).execute(REQUEST);
}
use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.
the class RetryingChannelTest method testRetriesUpToMaxRetriesAndFails.
@Test
public void testRetriesUpToMaxRetriesAndFails() throws ExecutionException, InterruptedException {
when(channel.execute(any())).thenReturn(FAILED).thenReturn(FAILED).thenReturn(SUCCESS);
// One retry allows an initial request (not a retry) and a single retry.
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(SafeIoException.class).hasRootCauseMessage("FAILED");
}
use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.
the class RetryingChannelTest method retriesSocketTimeoutWhenRequested.
@Test
public void retriesSocketTimeoutWhenRequested() throws ExecutionException, InterruptedException {
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.DANGEROUS_ENABLE_AT_RISK_OF_RETRY_STORMS);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThat(response.get()).isEqualTo(EXPECTED_RESPONSE);
}
use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.
the class RetryingChannelTest method retries_429s.
@Test
public void retries_429s() 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.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThat(response).isDone();
assertThat(response.get()).as("After retries are exhausted the 429 response should be returned").isSameAs(mockResponse);
verify(channel, times(4)).execute(REQUEST);
}
use of com.palantir.dialogue.EndpointChannel in project dialogue by palantir.
the class RetryingChannelTest method testPropagatesCancel.
@Test
public void testPropagatesCancel() {
ListenableFuture<Response> delegateResult = SettableFuture.create();
when(channel.execute(any())).thenReturn(delegateResult);
EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 3, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> retryingResult = retryer.execute(REQUEST);
assertThat(retryingResult.cancel(true)).isTrue();
assertThat(delegateResult).as("Failed to cancel the delegate future").isCancelled();
}
Aggregations