Search in sources :

Example 11 with Response

use of com.palantir.dialogue.Response in project dialogue by palantir.

the class ErrorDecoderTest method testQos429_retryAfter_invalid.

@Test
public void testQos429_retryAfter_invalid() {
    Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(429).withHeader(HttpHeaders.RETRY_AFTER, "bad");
    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 12 with Response

use of com.palantir.dialogue.Response in project dialogue by palantir.

the class ErrorDecoderTest method testQos308_noLocation.

@Test
public void testQos308_noLocation() {
    Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(308);
    assertThat(decoder.isError(response)).isTrue();
    RuntimeException result = decoder.decode(response);
    assertThat(result).isInstanceOfSatisfying(UnknownRemoteException.class, exception -> assertThat(exception.getStatus()).isEqualTo(308));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test)

Example 13 with Response

use of com.palantir.dialogue.Response in project dialogue by palantir.

the class ErrorDecoderTest method extractsRemoteExceptionForAllErrorCodes.

@Test
public void extractsRemoteExceptionForAllErrorCodes() {
    for (int code : ImmutableList.of(300, 400, 404, 500)) {
        Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(code).contentType("application/json");
        assertThat(decoder.isError(response)).isTrue();
        RuntimeException result = decoder.decode(response);
        assertThat(result).isInstanceOfSatisfying(RemoteException.class, exception -> {
            assertThat(exception.getCause()).isNull();
            assertThat(exception.getStatus()).isEqualTo(code);
            assertThat(exception.getError().errorCode()).isEqualTo(ErrorType.FAILED_PRECONDITION.code().name());
            assertThat(exception.getError().errorName()).isEqualTo(ErrorType.FAILED_PRECONDITION.name());
            assertThat(exception.getMessage()).isEqualTo("RemoteException: " + ErrorType.FAILED_PRECONDITION.code().name() + " (" + ErrorType.FAILED_PRECONDITION.name() + ") with instance ID " + SERVICE_EXCEPTION.getErrorInstanceId() + ": {key=value}");
            assertThat(exception.getLogMessage()).isEqualTo("RemoteException: " + ErrorType.FAILED_PRECONDITION.code().name() + " (" + ErrorType.FAILED_PRECONDITION.name() + ")");
        });
    }
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test)

Example 14 with Response

use of com.palantir.dialogue.Response in project dialogue by palantir.

the class ErrorDecoderTest method testQos503.

@Test
public void testQos503() {
    Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(503);
    assertThat(decoder.isError(response)).isTrue();
    RuntimeException result = decoder.decode(response);
    assertThat(result).isInstanceOf(QosException.Unavailable.class);
}
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 15 with Response

use of com.palantir.dialogue.Response in project dialogue by palantir.

the class ErrorDecoderTest method testQos308_invalidLocation.

@Test
public void testQos308_invalidLocation() {
    Response response = TestResponse.withBody(SERIALIZED_EXCEPTION).code(308).withHeader(HttpHeaders.LOCATION, "invalid");
    assertThat(decoder.isError(response)).isTrue();
    RuntimeException result = decoder.decode(response);
    assertThat(result).isInstanceOfSatisfying(UnknownRemoteException.class, exception -> assertThat(exception.getStatus()).isEqualTo(308));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test)

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