use of com.palantir.dialogue.Response in project dialogue by palantir.
the class QueuedChannelTest method testQueuedResponseClosedOnCancel.
@Test
public void testQueuedResponseClosedOnCancel() {
Request queuedRequest = Request.builder().pathParams(ImmutableMap.of("foo", "bar")).build();
when(delegate.maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.empty());
ListenableFuture<Response> result = queuedChannel.maybeExecute(endpoint, queuedRequest).get();
verify(delegate, times(2)).maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS);
when(delegate.maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.of(Futures.immediateFuture(Mockito.mock(Response.class))));
when(delegate.maybeExecute(endpoint, queuedRequest, DO_NOT_SKIP_LIMITS)).thenAnswer((Answer<Optional<ListenableFuture<Response>>>) _invocation -> {
assertThat(result.cancel(true)).isTrue();
return Optional.of(Futures.immediateFuture(mockResponse));
});
// Force scheduling
queuedChannel.maybeExecute(endpoint, request);
assertThat(result).isCancelled();
verify(delegate, times(1)).maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS);
verify(mockResponse, times(1)).close();
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class QueuedChannelTest method testQueuedResponsePropagatesCancel.
@Test
public void testQueuedResponsePropagatesCancel() {
Request queued = Request.builder().putHeaderParams("key", "val").build();
when(delegate.maybeExecute(endpoint, queued, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.empty());
ListenableFuture<Response> result = queuedChannel.maybeExecute(endpoint, queued).get();
verify(delegate, times(2)).maybeExecute(endpoint, queued, DO_NOT_SKIP_LIMITS);
when(delegate.maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS)).thenReturn(Optional.of(Futures.immediateFuture(Mockito.mock(Response.class))));
when(delegate.maybeExecute(endpoint, queued, DO_NOT_SKIP_LIMITS)).thenReturn(maybeResponse);
queuedChannel.maybeExecute(endpoint, request);
result.cancel(true);
assertThat(futureResponse).isCancelled();
verify(delegate, times(1)).maybeExecute(endpoint, request, DO_NOT_SKIP_LIMITS);
verify(delegate, times(3)).maybeExecute(endpoint, queued, DO_NOT_SKIP_LIMITS);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueTracing method responseTranslator.
static TagTranslator<Response> responseTranslator(ImmutableMap<String, String> tags) {
return new TagTranslator<>() {
@Override
public <T> void translate(TagAdapter<T> sink, T target, Response response) {
sink.tag(target, tags);
int status = response.code();
sink.tag(target, "outcome", status / 100 == 2 ? "success" : "failure");
sink.tag(target, TraceTags.HTTP_STATUS_CODE, Integer.toString(status));
}
};
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class HostMetricsChannel method execute.
@Override
public ListenableFuture<Response> execute(Endpoint endpoint, Request request) {
ListenableFuture<Response> result = delegate.execute(endpoint, request);
DialogueFutures.addDirectCallback(result, new Callback());
return result;
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueClientsTest method getStickyChannels_behaves_when_just_one_uri.
@Test
void getStickyChannels_behaves_when_just_one_uri() {
StickyChannelFactory stickyChannels = DialogueClients.create(Refreshable.only(scb)).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("multipass");
ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get).describedAs("Made a real network call").hasCauseInstanceOf(UnknownHostException.class);
}
Aggregations