Search in sources :

Example 1 with StickyChannelFactory

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");
}
Also used : Response(com.palantir.dialogue.Response) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Test(org.junit.jupiter.api.Test)

Example 2 with StickyChannelFactory

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);
}
Also used : Response(com.palantir.dialogue.Response) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) Test(org.junit.jupiter.api.Test)

Example 3 with StickyChannelFactory

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);
}
Also used : Response(com.palantir.dialogue.Response) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Test(org.junit.jupiter.api.Test)

Example 4 with StickyChannelFactory

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() + '}';
        }
    };
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Supplier(java.util.function.Supplier) StickyChannelFactory2(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory2) SafeArg(com.palantir.logsafe.SafeArg) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) ConjureRuntime(com.palantir.dialogue.ConjureRuntime) ImmutableList(com.google.common.collect.ImmutableList) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Value(org.immutables.value.Value) Duration(java.time.Duration) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) DefaultConjureRuntime(com.palantir.conjure.java.dialogue.serde.DefaultConjureRuntime) Endpoint(com.palantir.dialogue.Endpoint) ApacheHttpClientChannels(com.palantir.dialogue.hc5.ApacheHttpClientChannels) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) Request(com.palantir.dialogue.Request) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) ExecutorService(java.util.concurrent.ExecutorService) EndpointChannelFactory(com.palantir.dialogue.EndpointChannelFactory) Refreshable(com.palantir.refreshable.Refreshable) ServiceConfigurationFactory(com.palantir.conjure.java.api.config.service.ServiceConfigurationFactory) Clients(com.palantir.dialogue.Clients) PerHostClientFactory(com.palantir.dialogue.clients.DialogueClients.PerHostClientFactory) Channel(com.palantir.dialogue.Channel) Maps(com.google.common.collect.Maps) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Collectors(java.util.stream.Collectors) Provider(java.security.Provider) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) StickyEndpointChannels(com.palantir.dialogue.core.StickyEndpointChannels) Futures(com.google.common.util.concurrent.Futures) EndpointChannel(com.palantir.dialogue.EndpointChannel) List(java.util.List) DialogueChannel(com.palantir.dialogue.core.DialogueChannel) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Response(com.palantir.dialogue.Response) Preconditions(com.palantir.logsafe.Preconditions) DialogueChannel(com.palantir.dialogue.core.DialogueChannel) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Supplier(java.util.function.Supplier) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory)

Aggregations

Response (com.palantir.dialogue.Response)4 StickyChannelFactory (com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory)4 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3 Test (org.junit.jupiter.api.Test)3 ServicesConfigBlock (com.palantir.conjure.java.api.config.service.ServicesConfigBlock)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 PartialServiceConfiguration (com.palantir.conjure.java.api.config.service.PartialServiceConfiguration)1 ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)1 ServiceConfigurationFactory (com.palantir.conjure.java.api.config.service.ServiceConfigurationFactory)1 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)1 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)1 HostEventsSink (com.palantir.conjure.java.client.config.HostEventsSink)1 NodeSelectionStrategy (com.palantir.conjure.java.client.config.NodeSelectionStrategy)1 DefaultConjureRuntime (com.palantir.conjure.java.dialogue.serde.DefaultConjureRuntime)1 Channel (com.palantir.dialogue.Channel)1