Search in sources :

Example 31 with Response

use of com.palantir.dialogue.Response 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)

Example 32 with Response

use of com.palantir.dialogue.Response 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);
}
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 33 with Response

use of com.palantir.dialogue.Response 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");
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SafeIoException(com.palantir.logsafe.exceptions.SafeIoException) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 34 with Response

use of com.palantir.dialogue.Response 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);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SocketTimeoutException(java.net.SocketTimeoutException) EndpointChannel(com.palantir.dialogue.EndpointChannel) Test(org.junit.jupiter.api.Test)

Example 35 with Response

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

the class RetryingChannelTest method mockResponse.

private static Response mockResponse(int status) {
    Response response = mock(Response.class);
    when(response.code()).thenReturn(status);
    return response;
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response)

Aggregations

Response (com.palantir.dialogue.Response)93 Test (org.junit.jupiter.api.Test)72 TestResponse (com.palantir.dialogue.TestResponse)56 EndpointChannel (com.palantir.dialogue.EndpointChannel)27 Channel (com.palantir.dialogue.Channel)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 Endpoint (com.palantir.dialogue.Endpoint)16 Request (com.palantir.dialogue.Request)15 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 TestEndpoint (com.palantir.dialogue.TestEndpoint)10 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)9 Duration (java.time.Duration)9 Meter (com.codahale.metrics.Meter)8 IOException (java.io.IOException)8 Optional (java.util.Optional)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 QosException (com.palantir.conjure.java.api.errors.QosException)5 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5