use of com.palantir.dialogue.Endpoint in project conjure-java-runtime by palantir.
the class JaxRsClientDialogueEndpointTest method testEmptyStringPathParameter.
@Test
public void testEmptyStringPathParameter() {
Channel channel = stubNoContentResponseChannel();
StubService service = JaxRsClient.create(StubService.class, channel, runtime);
service.innerPath("");
ArgumentCaptor<Endpoint> endpointCaptor = ArgumentCaptor.forClass(Endpoint.class);
ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
verify(channel).execute(endpointCaptor.capture(), requestCaptor.capture());
UrlBuilder urlBuilder = mock(UrlBuilder.class);
endpointCaptor.getValue().renderPath(ImmutableMap.of(), urlBuilder);
// context path
verify(urlBuilder).pathSegment("foo");
verify(urlBuilder).pathSegment("begin");
verify(urlBuilder).pathSegment("");
verify(urlBuilder).pathSegment("end");
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class BalancedNodeSelectionStrategyChannel method maybeExecute.
@Override
public Optional<ListenableFuture<Response>> maybeExecute(Endpoint endpoint, Request request, LimitEnforcement limitEnforcement) {
ScoreSnapshot[] snapshotsByScore = tracker.getSnapshotsInOrderOfIncreasingScore();
int giveUpThreshold = Integer.MAX_VALUE;
for (ScoreSnapshot snapshot : snapshotsByScore) {
/*
* If we're considering a channel that has a *drastically* higher score than the last one (i.e. we
* think it's much worse), then we can often get better outcomes by just refusing to send a
* request (and queueing) rather than sending something to this known-bad channel.
*
* This allows us to avoid sending requests to an unhealthy channel after a node has failed while
* the concurrency limit on the healthy channel is slowly expanded to meet increased load. Otherwise
* the assumed concurrency limit base don lower request load on the healthy channel may result in requests
* being sent to a node that's no longer alive.
*
* Note that this functionality is not safe if the preferred channel had zero inflight requests (as this
* could result in infinite queuing).
*/
if (snapshot.getScore() > giveUpThreshold) {
if (log.isDebugEnabled()) {
log.debug("Giving up and queueing because channel score ({}) for channel {} is not worth sending a " + "request to ({})", SafeArg.of("score", snapshot.getScore()), SafeArg.of("hostIndex", snapshot.getDelegate().channelIndex()), SafeArg.of("giveUpScore", giveUpThreshold));
}
return Optional.empty();
}
if (snapshot.getInflight() > INFLIGHT_COMPARISON_THRESHOLD) {
int newThreshold = IntMath.saturatedMultiply(snapshot.getScore(), UNHEALTHY_SCORE_MULTIPLIER);
if (log.isDebugEnabled()) {
log.debug("When considering channel {}, giveUpThreshold {} -> {}", SafeArg.of("hostIndex", snapshot.getDelegate().channelIndex()), SafeArg.of("old", giveUpThreshold), SafeArg.of("new", newThreshold));
}
giveUpThreshold = newThreshold;
}
BalancedChannel channel = channels.get(snapshot.getDelegate().channelIndex());
Optional<ListenableFuture<Response>> maybe = StickyAttachments.maybeAddStickyToken(channel, endpoint, request, limitEnforcement);
if (maybe.isPresent()) {
return maybe;
}
}
return Optional.empty();
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class ResponseLeakDetectorTest method testNotLeaked_streamReferenceHeld.
@Test
public void testNotLeaked_streamReferenceHeld() throws Exception {
ResponseLeakDetector detector = new ResponseLeakDetector(CLIENT, metrics);
Meter leaks = metrics.responseLeak().clientName(CLIENT).serviceName(SERVICE).endpoint(ENDPOINT).build();
assertThat(leaks.getCount()).isZero();
// Result is intentionally ignored to cause a leak
try (InputStream ignored = detector.wrap(response, mockEndpoint).body()) {
// GC and test enough times to be confident no leaks were recorded
for (int i = 0; i < 100; i++) {
System.gc();
Thread.sleep(1);
assertThat(leaks.getCount()).isZero();
}
}
}
use of com.palantir.dialogue.Endpoint in project dialogue by palantir.
the class ResponseLeakDetectorTest method before.
@BeforeEach
public void before() {
mockEndpoint = mock(Endpoint.class);
response = mock(Response.class);
metrics = DialogueClientMetrics.of(new DefaultTaggedMetricRegistry());
lenient().when(mockEndpoint.serviceName()).thenReturn(SERVICE);
lenient().when(mockEndpoint.endpointName()).thenReturn(ENDPOINT);
lenient().when(response.body()).thenReturn(new ByteArrayInputStream(new byte[0]));
}
use of com.palantir.dialogue.Endpoint 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));
}
Aggregations