use of com.palantir.dialogue.Response in project dialogue by palantir.
the class StickyAttachmentsTest method validate_throws_and_closes_response_if_attachments_are_not_present.
@Test
public void validate_throws_and_closes_response_if_attachments_are_not_present() {
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(delegate, TestEndpoint.GET, request, LimitEnforcement.DEFAULT_ENABLED).get();
TestResponse response = TestResponse.withBody(null);
responseSettableFuture.set(response);
assertThatThrownBy(() -> Futures.getDone(responseListenableFuture)).isInstanceOf(ExecutionException.class).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("Requested sticky token on request but token not present on response");
assertThat(response.isClosed()).isTrue();
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos429_retryAfter.
@Test
public void testQos429_retryAfter() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(429).withHeader(HttpHeaders.RETRY_AFTER, "3");
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(QosException.Throttle.class, exception -> assertThat(exception.getRetryAfter()).hasValue(Duration.ofSeconds(3)));
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos308.
@Test
public void testQos308() {
String expectedLocation = "https://localhost";
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(308).withHeader(HttpHeaders.LOCATION, expectedLocation);
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOf(UnknownRemoteException.class).getRootCause().isInstanceOfSatisfying(QosException.RetryOther.class, exception -> assertThat(exception.getRedirectTo()).asString().isEqualTo(expectedLocation));
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class ErrorDecoderTest method testQos429.
@Test
public void testQos429() {
Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(429);
assertThat(decoder.isError(response)).isTrue();
RuntimeException result = decoder.decode(response);
assertThat(result).isInstanceOfSatisfying(QosException.Throttle.class, exception -> assertThat(exception.getRetryAfter()).isEmpty());
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class PinUntilErrorNodeSelectionStrategyChannelTest method getCode.
private static int getCode(PinUntilErrorNodeSelectionStrategyChannel channel, Request request) {
try {
ListenableFuture<Response> future = StickyAttachments.maybeExecuteOnSticky(channel, null, request, LimitEnforcement.DEFAULT_ENABLED).get();
Response response = future.get(1, TimeUnit.MILLISECONDS);
return response.code();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations