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