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));
}
}
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));
}
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);
}
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);
}
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);
}
Aggregations