Search in sources :

Example 56 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_dropsIfResponseIndicatesQosOrError_host.

@Test
public void onSuccess_dropsIfResponseIndicatesQosOrError_host() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.HOST_LEVEL);
    for (int code : new int[] { 308, 503 }) {
        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 57 with Response

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

the class BalancedNodeSelectionStrategyChannelTest method when_one_channel_is_in_use_prefer_the_other.

@Test
void when_one_channel_is_in_use_prefer_the_other() {
    set200(chan1);
    SettableFuture<Response> settableFuture = SettableFuture.create();
    when(chan2.maybeExecute(any(), any(), eq(LimitEnforcement.DEFAULT_ENABLED))).thenReturn(Optional.of(settableFuture));
    for (int i = 0; i < 200; i++) {
        channel.maybeExecute(endpoint, request, LimitEnforcement.DEFAULT_ENABLED);
    }
    verify(chan1, times(199)).maybeExecute(eq(endpoint), any(), eq(LimitEnforcement.DEFAULT_ENABLED));
    verify(chan2, times(1)).maybeExecute(eq(endpoint), any(), eq(LimitEnforcement.DEFAULT_ENABLED));
}
Also used : TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) TestEndpoint(com.palantir.dialogue.TestEndpoint) Endpoint(com.palantir.dialogue.Endpoint) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_successIfResponseIndicatesNonQos308.

@Test
public void onSuccess_successIfResponseIndicatesNonQos308() {
    // This represents google chunked-upload APIs which respond '308 Resume Incomplete' to indicate
    // a successful chunk upload request.
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.HOST_LEVEL);
    Response response = mock(Response.class);
    when(response.code()).thenReturn(308);
    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 59 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_releasesSuccessfullyIfResponseIndicatesQosOrError_sticky.

@Test
public void onSuccess_releasesSuccessfullyIfResponseIndicatesQosOrError_sticky() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.STICKY);
    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()).isEqualTo(max);
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with Response

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

the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_ignoresIfResponseIndicatesUnknownServerError_endpoint.

@Test
public void onSuccess_ignoresIfResponseIndicatesUnknownServerError_endpoint() {
    CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.ENDPOINT_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()).isEqualTo(max);
}
Also used : Response(com.palantir.dialogue.Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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