Skip to content

Commit

Permalink
handle uri removal in pin until error update (#497)
Browse files Browse the repository at this point in the history
handle uri removal in pin until error update
  • Loading branch information
ferozco authored Mar 6, 2020
1 parent 3622cdd commit a52ac9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-497.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: handle uri removal in pin until error update
links:
- https://github.com/palantir/dialogue/pull/497
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ final class PinUntilErrorChannel implements LimitedChannel {
nodeList.size() >= 2,
"PinUntilError is pointless if you have zero or 1 channels."
+ " Use an always throwing channel or just pick the only channel in the list.");
Preconditions.checkArgument(
0 <= initialHost && initialHost < nodeList.size(),
"initialHost must be a valid index into nodeList",
SafeArg.of("initialHost", initialHost));
}

static PinUntilErrorChannel of(
Expand All @@ -100,6 +104,7 @@ static PinUntilErrorChannel from(
ImmutableList<LimitedChannel> initialShuffle = shuffleImmutableList(channels, random);
// We only rely on reference equality since we expect LimitedChannels to be reused across updates
int initialHost = initialShuffle.indexOf(initialChannel);
initialHost = initialHost == -1 ? 0 : initialHost;

switch (strategy) {
case PIN_UNTIL_ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.palantir.conjure.java.client.config.NodeSelectionStrategy;
import com.palantir.dialogue.Response;
import com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry;
import java.time.Duration;
Expand Down Expand Up @@ -169,6 +170,12 @@ public void finds_first_non_limited_channel() {
assertThat(pinUntilError.maybeExecute(null, null)).isPresent();
}

@Test
void handles_reconstruction_from_stale_state() {
PinUntilErrorChannel.from(
null, NodeSelectionStrategy.PIN_UNTIL_ERROR, ImmutableList.of(channel1, channel2), metrics, pseudo);
}

private static int getCode(PinUntilErrorChannel channel) {
try {
ListenableFuture<Response> future = channel.maybeExecute(null, null).get();
Expand Down

0 comments on commit a52ac9b

Please sign in to comment.