Search in sources :

Example 16 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_dropsIfResponseIndicatesUnknownServerError_host.

@Test
public void onSuccess_dropsIfResponseIndicatesUnknownServerError_host() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.HOST_LEVEL);
    int code = 599;
    Response response = mock(Response.class);
    when(response.code()).thenReturn(code);
    double max = limiter.getLimit();
    limiter.acquire(LimitEnforcement.DEFAULT_ENABLED).get().onSuccess(response);
    assertThat(limiter.getLimit()).as("For status %d", code).isCloseTo(max * 0.9, Percentage.withPercentage(5));
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_ignoresIfResponseIndicatesUnknownServerError_sticky.

@Test
public void onSuccess_ignoresIfResponseIndicatesUnknownServerError_sticky() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.STICKY);
    int code = 599;
    Response response = mock(Response.class);
    when(response.code()).thenReturn(code);
    double max = limiter.getLimit();
    limiter.acquire(LimitEnforcement.DEFAULT_ENABLED).get().onSuccess(response);
    assertThat(limiter.getLimit()).isEqualTo(max);
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_dropsIfResponseIndicatesQosOrError_endpoint.

@Test
public void onSuccess_dropsIfResponseIndicatesQosOrError_endpoint() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.ENDPOINT_LEVEL);
    int code = 429;
    Response response = mock(Response.class);
    when(response.code()).thenReturn(code);
    double max = limiter.getLimit();
    limiter.acquire(LimitEnforcement.DEFAULT_ENABLED).get().onSuccess(response);
    assertThat(limiter.getLimit()).as("For status %d", code).isCloseTo(max * 0.9, Percentage.withPercentage(5));
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_dropsIfResponseIndicatesQosOrError_host_308.

@Test
public void onSuccess_dropsIfResponseIndicatesQosOrError_host_308() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.HOST_LEVEL);
    Response response = mock(Response.class);
    when(response.getFirstHeader(eq("Location"))).thenReturn(Optional.of("https://localhost"));
    when(response.code()).thenReturn(308);
    double max = limiter.getLimit();
    limiter.acquire(LimitEnforcement.DEFAULT_ENABLED).get().onSuccess(response);
    assertThat(limiter.getLimit()).as("For status %d", 308).isCloseTo(max * 0.9, Percentage.withPercentage(5));
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with Response

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

the class ContentDecodingChannelTest method testDecoding.

@Test
public void testDecoding() throws Exception {
    byte[] expected = new byte[] { 1, 2, 3, 4 };
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (GZIPOutputStream compressor = new GZIPOutputStream(out)) {
        compressor.write(expected);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    Response response = new ContentDecodingChannel(_request -> Futures.immediateFuture(new TestResponse(out.toByteArray()).withHeader("content-encoding", "gzip").withHeader("content-length", Integer.toString(out.size())))).execute(Request.builder().build()).get();
    assertThat(response.headers().get("content-encoding")).isEmpty();
    assertThat(ByteStreams.toByteArray(response.body())).containsExactly(expected);
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) GZIPOutputStream(java.util.zip.GZIPOutputStream) TestResponse(com.palantir.dialogue.TestResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) 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