use of com.palantir.dialogue.Response 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.Response 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();
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class StickyAttachmentsTest method validate_is_passthrough_if_attachments_present.
@Test
public void validate_is_passthrough_if_attachments_present() throws ExecutionException {
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(stickyTokenHandler, TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED).get();
TestResponse response = TestResponse.withBody(null);
responseSettableFuture.set(response);
assertThat(Futures.getDone(responseListenableFuture)).isEqualTo(response);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class HostMetricsChannelTest method calls_sink_when_response_comes_back.
@Test
void calls_sink_when_response_comes_back() {
AtomicBoolean recorded = new AtomicBoolean();
Channel channel = HostMetricsChannel.create(config(ClientConfiguration.builder().from(TestConfigurations.create("https://unused", "https://unused2")).hostEventsSink(new HostEventsSink() {
@Override
public void record(String serviceName, String hostname, int port, int statusCode, long micros) {
assertThat(serviceName).isEqualTo("channelName");
assertThat(hostname).isEqualTo("foo");
assertThat(port).isEqualTo(1001);
assertThat(statusCode).isEqualTo(200);
assertThat(micros).isEqualTo(TimeUnit.SECONDS.toMicros(3));
recorded.set(true);
}
@Override
public void recordIoException(String _serviceName, String _hostname, int _port) {
Assertions.fail("no IOExceptions expected");
}
}).build()), mockChannel, "https://foo:1001");
SettableFuture<Response> settable = SettableFuture.create();
when(mockChannel.execute(any(), any())).thenReturn(settable);
ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
when(ticker.read()).thenReturn(Duration.ofSeconds(3).toNanos());
settable.set(new TestResponse().code(200));
assertThat(recorded).isTrue();
assertThat(future).isDone();
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class PinUntilErrorNodeSelectionStrategyChannelTest method setResponse.
private static void setResponse(LimitedChannel mockChannel, int status) {
Mockito.clearInvocations(mockChannel);
Mockito.reset(mockChannel);
Response resp = response(status);
lenient().when(mockChannel.maybeExecute(any(), any(), eq(LimitEnforcement.DEFAULT_ENABLED))).thenReturn(Optional.of(Futures.immediateFuture(resp)));
}
Aggregations