use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ContentDecodingChannelTest method testDecoding_delayedFailure.
@Test
public void testDecoding_delayedFailure() throws Exception {
Response response = new ContentDecodingChannel(_request -> Futures.immediateFuture(// Will fail because it's not valid gzip content
new TestResponse(new byte[] { 1, 2, 3, 4 }).withHeader("content-encoding", "gzip"))).execute(Request.builder().build()).get();
assertThat(response.headers().get("content-encoding")).isEmpty();
assertThatThrownBy(response.body()::read).isInstanceOf(IOException.class);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method test_can_use_sticky_attachments_impl.
private void test_can_use_sticky_attachments_impl(NodeSelectionStrategy nodeSelectionStrategy, ImmutableList<String> uris) throws ExecutionException {
String uriHeader = "uri";
DialogueChannelFactory factory = args -> {
mockChannel = Mockito.mock(Channel.class);
lenient().when(mockChannel.execute(eq(endpoint), any())).thenAnswer((Answer<ListenableFuture<Response>>) _invocation -> Futures.immediateFuture(TestResponse.withBody(null).withHeader(uriHeader, args.uri())));
return mockChannel;
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(ClientConfiguration.builder().uris(uris).from(stubConfig).nodeSelectionStrategy(nodeSelectionStrategy).build()).factory(factory).random(new Random(1L)).build();
request = createRequestWithAddExecutedOnAttachment();
response = Futures.getDone(channel.execute(endpoint, request));
String expectedUri = response.getFirstHeader(uriHeader).get();
Consumer<Request> stickyTarget = StickyAttachments.copyStickyTarget(response);
request = Request.builder().build();
stickyTarget.accept(request);
response = Futures.getDone(channel.execute(endpoint, request));
assertThat(response.getFirstHeader(uriHeader)).hasValue(expectedUri);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method when_thread_is_interrupted_no_calls_to_delegate.
@Test
public void when_thread_is_interrupted_no_calls_to_delegate() {
Channel delegate = mock(Channel.class);
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> delegate).build();
Thread.currentThread().interrupt();
ListenableFuture<Response> future = channel.execute(endpoint, request);
assertThat(future).isDone();
assertThat(future).isNotCancelled();
verifyNoInteractions(delegate);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method test_serialization_socket_error_is_retried.
@Test
void test_serialization_socket_error_is_retried() {
ListenableFuture<Response> result = makeStructuredRequestToClosedConnection(() -> new SocketException("broken pipe"));
assertThat(result).succeedsWithin(Duration.ofSeconds(2)).satisfies(res -> {
assertThat(res.code()).isEqualTo(204);
assertThat(res.getFirstHeader("Interactions")).as("Expected retries").hasValue("2");
});
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueClientsTest method getStickyChannels_behaves_when_service_doesnt_exist.
@Test
void getStickyChannels_behaves_when_service_doesnt_exist() {
StickyChannelFactory stickyChannels = DialogueClients.create(Refreshable.only(scb)).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("asldjaslkdjslad");
ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get).describedAs("Nice error message when services doesn't exist").hasCauseInstanceOf(SafeIllegalStateException.class).hasMessageContaining("Service not configured");
}
Aggregations