use of com.palantir.dialogue.TestResponse 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.TestResponse in project dialogue by palantir.
the class RetryingChannelTest method doesnt_retry_500s_for_post.
@Test
public void doesnt_retry_500s_for_post() throws Exception {
when(channel.execute(any())).thenReturn(Futures.immediateFuture(new TestResponse().code(500)));
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().code()).isEqualTo(500);
verify(channel, times(1)).execute(REQUEST);
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class RetryingChannelTest method retries_500s_for_delete.
@Test
public void retries_500s_for_delete() 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.DELETE, "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.TestResponse in project dialogue by palantir.
the class RetryingChannelTest method final_exhausted_failure_response_body_is_not_closed.
@Test
public void final_exhausted_failure_response_body_is_not_closed() throws Exception {
TestResponse response1 = new TestResponse().code(503);
TestResponse response2 = new TestResponse().code(503);
TestResponse response3 = new TestResponse().code(503);
when(channel.execute(any())).thenReturn(Futures.immediateFuture(response1)).thenReturn(Futures.immediateFuture(response2)).thenReturn(Futures.immediateFuture(response3));
EndpointChannel retryer = new RetryingChannel(channel, TestEndpoint.POST, "my-channel", 2, Duration.ZERO, ClientConfiguration.ServerQoS.AUTOMATIC_RETRY, ClientConfiguration.RetryOnTimeout.DISABLED);
ListenableFuture<Response> response = retryer.execute(REQUEST);
assertThat(response.get(1, TimeUnit.SECONDS).code()).isEqualTo(503);
assertThat(response1.isClosed()).isTrue();
assertThat(response2.isClosed()).isTrue();
assertThat(response3.isClosed()).describedAs("The last response must be left open so we can read the body" + " and deserialize it into a structured error").isFalse();
}
use of com.palantir.dialogue.TestResponse in project dialogue by palantir.
the class StickyAttachmentsTest method validate_throws_and_closes_response_if_attachments_are_not_present.
@Test
public void validate_throws_and_closes_response_if_attachments_are_not_present() {
Request request = Request.builder().build();
StickyAttachments.requestStickyToken(request);
when(delegate.maybeExecute(TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED)).thenReturn(Optional.of(responseSettableFuture));
ListenableFuture<Response> responseListenableFuture = StickyAttachments.maybeExecuteAndValidateRequestStickyToken(delegate, TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED).get();
TestResponse response = TestResponse.withBody(null);
responseSettableFuture.set(response);
assertThatThrownBy(() -> Futures.getDone(responseListenableFuture)).isInstanceOf(ExecutionException.class).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("Requested sticky token on request but token not present on response");
assertThat(response.isClosed()).isTrue();
}
Aggregations