use of com.palantir.dialogue.Request 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.Request in project dialogue by palantir.
the class PinUntilErrorNodeSelectionStrategyChannelTest method sticky_request_do_not_switch_nodes.
@Test
void sticky_request_do_not_switch_nodes() throws ExecutionException {
setResponse(channel1, 100);
setResponse(channel2, 101);
assertThat(getCode(pinUntilError)).describedAs("On channel2 initially").isEqualTo(101);
Request requestSticky = Request.builder().build();
StickyAttachments.requestStickyToken(requestSticky);
int errorStatus = 500;
setResponse(channel2, errorStatus);
Consumer<Request> requestConsumer = StickyAttachments.copyStickyTarget(Futures.getDone(pinUntilError.maybeExecute(null, requestSticky, LimitEnforcement.DEFAULT_ENABLED).get()));
assertThat(IntStream.range(0, 6).map(_number -> getCode(pinUntilError))).describedAs("A single error code should switch us to channel 1").contains(100, 100, 100, 100, 100, 100);
assertThat(IntStream.range(0, 6).map(_number -> {
Request stickyRequest = Request.builder().build();
requestConsumer.accept(stickyRequest);
return getCode(pinUntilError, stickyRequest);
})).describedAs("sticky request continues being pinned to channel 2").contains(errorStatus, errorStatus, errorStatus, errorStatus, errorStatus, errorStatus);
assertThat(IntStream.range(0, 6).map(_number -> getCode(pinUntilError))).describedAs("unpinned requests stay on channel 1").contains(100, 100, 100, 100, 100, 100);
}
use of com.palantir.dialogue.Request in project dialogue by palantir.
the class QueueOverrideChannelTest method routesToOverride.
@Test
public void routesToOverride() {
Request request = Request.builder().build();
QueueAttachments.setQueueOverride(request, override);
assertThat(queueOverrideChannel.execute(TestEndpoint.GET, request)).isNull();
verify(override).execute(TestEndpoint.GET, request);
}
use of com.palantir.dialogue.Request 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.Request 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);
}
Aggregations