use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class BalancedNodeSelectionStrategyChannelTest method when_both_channels_are_free_we_get_roughly_fair_tiebreaking.
@Test
void when_both_channels_are_free_we_get_roughly_fair_tiebreaking() {
set200(chan1);
set200(chan2);
for (int i = 0; i < 200; i++) {
channel.maybeExecute(endpoint, request, LimitEnforcement.DEFAULT_ENABLED);
}
verify(chan1, times(99)).maybeExecute(eq(endpoint), any(), eq(LimitEnforcement.DEFAULT_ENABLED));
verify(chan2, times(101)).maybeExecute(eq(endpoint), any(), eq(LimitEnforcement.DEFAULT_ENABLED));
}
use of com.palantir.dialogue.Endpoint 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.Endpoint 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);
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class DialogueChannelTest method makeStructuredRequestToClosedConnection.
private ListenableFuture<Response> makeStructuredRequestToClosedConnection(Supplier<IOException> failure) {
AtomicInteger channelInteractions = new AtomicInteger();
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(stubConfig).factory(_args -> (_endpoint, currentRequest) -> {
int interactions = channelInteractions.incrementAndGet();
if (interactions > 1) {
return Futures.immediateFuture(new TestResponse().code(204).withHeader("Interactions", Integer.toString(interactions)));
}
Optional<RequestBody> body = currentRequest.body();
assertThat(body).isPresent();
try {
body.get().writeTo(new ThrowingOutputStream(failure));
} catch (IOException e) {
return Futures.immediateFailedFuture(e);
}
throw new AssertionError("Expected an exception");
}).random(new Random(123456L)).maxQueueSize(1).build();
RequestBody defaultStructuredBody = DefaultConjureRuntime.builder().build().bodySerDe().serializer(new TypeMarker<List<String>>() {
}).serialize(ImmutableList.of("test"));
return channel.execute(endpoint, Request.builder().body(defaultStructuredBody).build());
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class DialogueChannelTest method bad_channel_throwing_an_error_still_returns_a_future.
@Test
public void bad_channel_throwing_an_error_still_returns_a_future() {
Channel badUserImplementation = new Channel() {
@Override
public ListenableFuture<Response> execute(Endpoint _endpoint, Request _request) {
throw new NoClassDefFoundError("something is broken");
}
};
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(NoClassDefFoundError.class);
}
Aggregations