use of com.palantir.dialogue.Request in project dialogue by palantir.
the class DefaultClientsTest method testCallClosesRequestOnCompletion_success.
@ParameterizedTest
@EnumSource(CallType.class)
public void testCallClosesRequestOnCompletion_success(CallType callType) {
RequestBody body = mock(RequestBody.class);
Request request = Request.builder().body(body).build();
when(stringDeserializer.deserialize(eq(response))).thenReturn("value");
when(channel.execute(eq(endpoint), eq(request))).thenReturn(responseFuture);
ListenableFuture<String> result = call(callType, request);
// The request has been sent, but not yet completed
verifyExecutionStarted(request);
verify(body, never()).close();
// Upon completion the request should be closed
responseFuture.set(response);
assertStringResult(callType, result);
verify(body).close();
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class DefaultClientsTest method testCallBlockingPropagatesCallingThreadExecutor.
@Test
@Execution(ExecutionMode.SAME_THREAD)
public void testCallBlockingPropagatesCallingThreadExecutor() {
Request request = Request.builder().build();
when(stringDeserializer.deserialize(eq(response))).thenReturn(VALUE);
when(channel.execute(eq(endpoint), requestCaptor.capture())).thenReturn(responseFuture);
ListenableFuture<String> result = call(CallType.Blocking, request);
assertThat(result).isNotDone();
responseFuture.set(response);
assertStringResult(CallType.Blocking, result);
CallingThreadExecutorAssert.assertUsingCallingThreadExecutor(requestCaptor.getValue()).isNotNull();
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class DefaultClientsTest method testCall.
@ParameterizedTest
@EnumSource(CallType.class)
public void testCall(CallType callType) {
Request request = Request.builder().build();
when(stringDeserializer.deserialize(eq(response))).thenReturn(VALUE);
when(channel.execute(eq(endpoint), eq(request))).thenReturn(responseFuture);
ListenableFuture<String> result = call(callType, request);
assertThat(result).isNotDone();
responseFuture.set(response);
assertStringResult(callType, result);
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class ContentEncodingChannelTest method testChannelCreationWithTag.
@Test
void testChannelCreationWithTag() {
EndpointChannel delegate = _req -> Futures.immediateCancelledFuture();
EndpointChannel result = ContentEncodingChannel.of(delegate, new Endpoint() {
@Override
public HttpMethod httpMethod() {
return HttpMethod.POST;
}
@Override
public String serviceName() {
return "service";
}
@Override
public String endpointName() {
return "endpoint";
}
@Override
public String version() {
return "1.2.3";
}
@Override
public Set<String> tags() {
return ImmutableSet.of("compress-request");
}
});
assertThat(result).isNotSameAs(delegate);
}
use of com.palantir.dialogue.Request 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);
}
Aggregations