use of com.palantir.dialogue.Response in project dialogue by palantir.
the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_dropsIfResponseIndicatesQosOrError_host_503.
@Test
public void onSuccess_dropsIfResponseIndicatesQosOrError_host_503() {
CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(Behavior.HOST_LEVEL);
Response response = mock(Response.class);
when(response.code()).thenReturn(503);
double max = limiter.getLimit();
limiter.acquire(LimitEnforcement.DEFAULT_ENABLED).get().onSuccess(response);
assertThat(limiter.getLimit()).as("For status %d", 503).isCloseTo(max * 0.9, Percentage.withPercentage(5));
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class CautiousIncreaseAggressiveDecreaseConcurrencyLimiterTest method onSuccess_releasesSuccessfully.
@ParameterizedTest
@EnumSource(Behavior.class)
public void onSuccess_releasesSuccessfully(Behavior behavior) {
CautiousIncreaseAggressiveDecreaseConcurrencyLimiter limiter = limiter(behavior);
Response response = mock(Response.class);
when(response.code()).thenReturn(200);
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 ContentDecodingChannelTest method testOnlyDecodesGzip.
@Test
public void testOnlyDecodesGzip() throws Exception {
byte[] content = new byte[] { 1, 2, 3, 4 };
Response response = new ContentDecodingChannel(_request -> Futures.immediateFuture(new TestResponse(content).withHeader("content-encoding", "unknown"))).execute(Request.builder().build()).get();
assertThat(response.headers()).containsAllEntriesOf(ImmutableListMultimap.of("content-encoding", "unknown"));
assertThat(ByteStreams.toByteArray(response.body())).isEqualTo(content);
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method test_queue_rejection_is_not_retried.
@Test
void test_queue_rejection_is_not_retried() {
when(mockChannel.execute(any(), any())).thenReturn(SettableFuture.create());
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> mockChannel).random(new Random(123456L)).maxQueueSize(1).build();
// Saturate the concurrency limiter
int initialConcurrencyLimit = 20;
for (int i = 0; i < initialConcurrencyLimit; i++) {
ListenableFuture<Response> running = channel.execute(endpoint, request);
assertThat(running).isNotDone();
}
// Queue a request
ListenableFuture<Response> queued = channel.execute(endpoint, request);
assertThat(queued).isNotDone();
// Next request should be rejected.
ListenableFuture<Response> rejected = channel.execute(endpoint, request);
assertThat(rejected).isDone();
assertThatThrownBy(rejected::get).hasRootCauseExactlyInstanceOf(SafeRuntimeException.class).hasMessageContaining("queue is full");
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class DialogueChannelTest method bad_channel_throwing_an_exception_still_returns_a_future.
@Test
public void bad_channel_throwing_an_exception_still_returns_a_future() {
Channel badUserImplementation = new Channel() {
@Override
public ListenableFuture<Response> execute(Endpoint _endpoint, Request _request) {
throw new IllegalStateException("Always throw");
}
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> badUserImplementation).build();
// this should never throw
ListenableFuture<Response> future = channel.execute(endpoint, request);
// only when we access things do we allow exceptions
assertThatThrownBy(() -> Futures.getUnchecked(future)).hasCauseInstanceOf(IllegalStateException.class);
}
Aggregations