use of com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory in project dialogue by palantir.
the class DialogueClientsTest method getStickyChannels_behaves_when_service_doesnt_exist.
@Test
void getStickyChannels_behaves_when_service_doesnt_exist() {
StickyChannelFactory stickyChannels = DialogueClients.create(Refreshable.only(scb)).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("asldjaslkdjslad");
ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get).describedAs("Nice error message when services doesn't exist").hasCauseInstanceOf(SafeIllegalStateException.class).hasMessageContaining("Service not configured");
}
use of com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory in project dialogue by palantir.
the class DialogueClientsTest method getStickyChannels_behaves_when_just_one_uri.
@Test
void getStickyChannels_behaves_when_just_one_uri() {
StickyChannelFactory stickyChannels = DialogueClients.create(Refreshable.only(scb)).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("multipass");
ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get).describedAs("Made a real network call").hasCauseInstanceOf(UnknownHostException.class);
}
use of com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory in project dialogue by palantir.
the class DialogueClientsTest method getStickyChannels_live_reloads_nicely.
@Test
void getStickyChannels_live_reloads_nicely() {
SettableRefreshable<ServicesConfigBlock> refreshable = Refreshable.create(scb);
StickyChannelFactory stickyChannels = DialogueClients.create(refreshable).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("zero-uris-service");
ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future::get).describedAs("Nice error message when service exists but has zero uris").hasCauseInstanceOf(SafeIllegalStateException.class).hasMessageContaining("Service not configured");
refreshable.update(ServicesConfigBlock.builder().from(scb).putServices("zero-uris-service", PartialServiceConfiguration.builder().addUris("https://live-reloaded-uri-appeared").build()).build());
ListenableFuture<Response> future2 = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
assertThatThrownBy(future2::get).describedAs("Made a real network call").hasCauseInstanceOf(UnknownHostException.class);
}
use of com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory in project dialogue by palantir.
the class ReloadingClientFactory method getStickyChannels.
@Override
public StickyChannelFactory getStickyChannels(String serviceName) {
Refreshable<List<Channel>> perHostChannels = perHost(serviceName).getPerHostChannels();
Refreshable<Supplier<Channel>> bestSupplier = perHostChannels.map(singleHostChannels -> {
if (singleHostChannels.isEmpty()) {
EmptyInternalDialogueChannel alwaysThrowing = new EmptyInternalDialogueChannel(() -> new SafeIllegalStateException("Service not configured", SafeArg.of("serviceName", serviceName)));
return () -> alwaysThrowing;
}
if (singleHostChannels.size() == 1) {
return () -> singleHostChannels.get(0);
}
return StickyEndpointChannels.builder().channels(singleHostChannels.stream().map(c -> (DialogueChannel) c).collect(Collectors.toList())).channelName(ChannelNames.reloading(serviceName, params)).taggedMetricRegistry(params.taggedMetrics()).build();
});
return new StickyChannelFactory() {
@Override
public Channel getStickyChannel() {
return bestSupplier.get().get();
}
@Override
public <T> T getCurrentBest(Class<T> clientInterface) {
return Reflection.callStaticFactoryMethod(clientInterface, getStickyChannel(), params.runtime());
}
@Override
public String toString() {
return "StickyChannelFactory{" + bestSupplier.get() + '}';
}
};
}
Aggregations