Search in sources :

Example 81 with Response

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();
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) TestResponse(com.palantir.dialogue.TestResponse) Request(com.palantir.dialogue.Request) Test(org.junit.jupiter.api.Test)

Example 82 with Response

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)));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) QosException(com.palantir.conjure.java.api.errors.QosException) Test(org.junit.jupiter.api.Test)

Example 83 with Response

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));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) QosException(com.palantir.conjure.java.api.errors.QosException) Test(org.junit.jupiter.api.Test)

Example 84 with Response

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());
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) QosException(com.palantir.conjure.java.api.errors.QosException) Test(org.junit.jupiter.api.Test)

Example 85 with Response

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);
    }
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Response (com.palantir.dialogue.Response)93 Test (org.junit.jupiter.api.Test)72 TestResponse (com.palantir.dialogue.TestResponse)56 EndpointChannel (com.palantir.dialogue.EndpointChannel)27 Channel (com.palantir.dialogue.Channel)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 Endpoint (com.palantir.dialogue.Endpoint)16 Request (com.palantir.dialogue.Request)15 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 TestEndpoint (com.palantir.dialogue.TestEndpoint)10 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)9 Duration (java.time.Duration)9 Meter (com.codahale.metrics.Meter)8 IOException (java.io.IOException)8 Optional (java.util.Optional)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 QosException (com.palantir.conjure.java.api.errors.QosException)5 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5