use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method test_serialization_socket_timeout_is_not_retried.
@Test
void test_serialization_socket_timeout_is_not_retried() {
ListenableFuture<Response> result = makeStructuredRequestToClosedConnection(() -> new SocketTimeoutException("oops"));
assertThat(result).as("Socket timeouts should not be retried").failsWithin(Duration.ofSeconds(2));
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method bad_channel_throwing_an_error_still_returns_a_future.
@Test
public void bad_channel_throwing_an_error_still_returns_a_future() {
Channel badUserImplementation = new Channel() {
@Override
public ListenableFuture<Response> execute(Endpoint _endpoint, Request _request) {
throw new NoClassDefFoundError("something is broken");
}
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> badUserImplementation).build();
// this should never throw
ListenableFuture<Response> future = channel.execute(endpoint, request);
// only when we access things do we allow exceptions
assertThatThrownBy(() -> Futures.getUnchecked(future)).hasCauseInstanceOf(NoClassDefFoundError.class);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class RetryingChannelTest method nonRetryableRequestBodyIsNotRetried.
@Test
public void nonRetryableRequestBodyIsNotRetried() throws ExecutionException, InterruptedException {
when(channel.execute(any())).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.builder().body(new RequestBody() {
@Override
public void writeTo(OutputStream _output) {
}
@Override
public String contentType() {
return "application/octet-stream";
}
@Override
public boolean repeatable() {
return false;
}
@Override
public void close() {
}
}).build());
assertThat(response).isDone();
assertThat(response).as("non-repeatable request bodies should not be retried").isEqualTo(FAILED);
verify(channel, times(1)).execute(any());
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class RetryingChannelTest method retries_500s_when_method_is_safe_and_idempotent.
@Test
public void retries_500s_when_method_is_safe_and_idempotent() 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.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);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class RetryingChannelTest method retries_503s.
@Test
public void retries_503s() 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.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThat(response).isDone();
assertThat(response.get()).as("After retries are exhausted the 503 response should be returned").isSameAs(mockResponse);
verify(channel, times(4)).execute(REQUEST);
}
Aggregations