Search in sources :

Example 1 with SampleServiceBlocking

use of com.palantir.dialogue.example.SampleServiceBlocking in project dialogue by palantir.

the class DialogueClientsIntegrationTest method building_non_reloading_clients_always_gives_the_same_instance.

@Test
void building_non_reloading_clients_always_gives_the_same_instance() {
    AtomicInteger statusCode = new AtomicInteger(200);
    Set<String> requestPaths = ConcurrentHashMap.newKeySet();
    undertowHandler = exchange -> {
        requestPaths.add(exchange.getRequestPath());
        exchange.setStatusCode(statusCode.get());
    };
    serviceConfig = ServiceConfiguration.builder().security(TestConfigurations.SSL_CONFIG).addUris(IntStream.range(0, 100).mapToObj(i -> getUri(undertow) + "/api" + i).toArray(String[]::new)).maxNumRetries(0).build();
    DialogueClients.ReloadingFactory factory = DialogueClients.create(Refreshable.only(null)).withUserAgent(TestConfigurations.AGENT).withNodeSelectionStrategy(NodeSelectionStrategy.PIN_UNTIL_ERROR);
    SampleServiceBlocking instance = factory.getNonReloading(SampleServiceBlocking.class, serviceConfig);
    SampleServiceBlocking instance2 = factory.getNonReloading(SampleServiceBlocking.class, serviceConfig);
    SampleServiceBlocking instance3 = factory.getNonReloading(SampleServiceBlocking.class, serviceConfig);
    instance.voidToVoid();
    instance2.voidToVoid();
    instance3.voidToVoid();
    assertThat(requestPaths).describedAs("Out of the hundred urls, each of these clients should start off pinned to the same host").hasSize(1);
    statusCode.set(503);
    assertThatThrownBy(instance::voidToVoid).isInstanceOf(QosException.Unavailable.class);
    assertThatThrownBy(instance2::voidToVoid).isInstanceOf(QosException.Unavailable.class);
    assertThatThrownBy(instance3::voidToVoid).isInstanceOf(QosException.Unavailable.class);
    assertThat(requestPaths).hasSize(3);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SSLContext(javax.net.ssl.SSLContext) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BiFunction(java.util.function.BiFunction) Undertow(io.undertow.Undertow) SettableRefreshable(com.palantir.refreshable.SettableRefreshable) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Splitter(com.google.common.base.Splitter) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) Refreshable(com.palantir.refreshable.Refreshable) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) QosException(com.palantir.conjure.java.api.errors.QosException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SslSocketFactories(com.palantir.conjure.java.config.ssl.SslSocketFactories) Test(org.junit.jupiter.api.Test) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) List(java.util.List) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) StickyChannelFactory2(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory2) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) ClientConfigurations(com.palantir.conjure.java.client.config.ClientConfigurations) BlockingHandler(io.undertow.server.handlers.BlockingHandler) TestConfigurations(com.palantir.dialogue.TestConfigurations) HttpHandler(io.undertow.server.HttpHandler) Futures(com.google.common.util.concurrent.Futures) AfterEach(org.junit.jupiter.api.AfterEach) X509TrustManager(javax.net.ssl.X509TrustManager) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Collections(java.util.Collections) Preconditions(com.palantir.logsafe.Preconditions) QosException(com.palantir.conjure.java.api.errors.QosException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) DialogueClients(com.palantir.dialogue.clients.DialogueClients) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Example 2 with SampleServiceBlocking

use of com.palantir.dialogue.example.SampleServiceBlocking in project dialogue by palantir.

the class DialogueClientsIntegrationTest method test_conn_timeout_with_unlimited_socket_timeout.

@Test
void test_conn_timeout_with_unlimited_socket_timeout() {
    undertowHandler = _exchange -> Thread.sleep(1_000L);
    SampleServiceBlocking client = DialogueClients.create(Refreshable.only(null)).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getNonReloading(SampleServiceBlocking.class, ServiceConfiguration.builder().addUris(getUri(undertow)).security(TestConfigurations.SSL_CONFIG).connectTimeout(Duration.ofMillis(300)).readTimeout(Duration.ZERO).writeTimeout(Duration.ZERO).build());
    assertThatCode(client::voidToVoid).as("initial request should not throw").doesNotThrowAnyException();
    assertThatCode(client::voidToVoid).as("subsequent requests reusing the connection should not throw").doesNotThrowAnyException();
}
Also used : SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Example 3 with SampleServiceBlocking

use of com.palantir.dialogue.example.SampleServiceBlocking in project dialogue by palantir.

the class DialogueClientsIntegrationTest method test_legacy_static_factory.

@Test
void test_legacy_static_factory() {
    List<String> requestPaths = new CopyOnWriteArrayList<>();
    undertowHandler = exchange -> {
        requestPaths.add(exchange.getRequestPath());
        exchange.setStatusCode(200);
    };
    SSLSocketFactory socketFactory = SslSocketFactories.createSslSocketFactory(TestConfigurations.SSL_CONFIG);
    X509TrustManager trustManager = SslSocketFactories.createX509TrustManager(TestConfigurations.SSL_CONFIG);
    ClientConfiguration config = ClientConfigurations.of(ImmutableList.of(getUri(undertow) + foo1Path), socketFactory, trustManager, TestConfigurations.AGENT);
    SampleServiceBlocking client = DialogueClients.create(SampleServiceBlocking.class, config);
    client.voidToVoid();
    assertThat(requestPaths).containsExactly("/foo1/voidToVoid");
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Example 4 with SampleServiceBlocking

use of com.palantir.dialogue.example.SampleServiceBlocking in project dialogue by palantir.

the class DialogueClientsTest method simpleLibrary.

// this is the recommended way to depend on a clientfactory
private void simpleLibrary(DialogueClients.ReloadingFactory factory) {
    SampleServiceBlocking instance = factory.withMaxNumRetries(1).withUserAgent(TestConfigurations.AGENT).getNonReloading(SampleServiceBlocking.class, serviceConf);
    Preconditions.checkNotNull(instance, "instance");
}
Also used : SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking)

Example 5 with SampleServiceBlocking

use of com.palantir.dialogue.example.SampleServiceBlocking in project dialogue by palantir.

the class DialogueClientsIntegrationTest method reload_uris_works.

@Test
void reload_uris_works() {
    List<String> requestPaths = Collections.synchronizedList(new ArrayList<>());
    undertowHandler = exchange -> {
        requestPaths.add(exchange.getRequestPath());
        exchange.setStatusCode(200);
    };
    SettableRefreshable<ServicesConfigBlock> refreshable = Refreshable.create(scb);
    DialogueClients.ReloadingFactory factory = DialogueClients.create(refreshable).withUserAgent(TestConfigurations.AGENT);
    SampleServiceBlocking client = factory.get(SampleServiceBlocking.class, "foo");
    client.voidToVoid();
    refreshable.update(ServicesConfigBlock.builder().from(scb).putServices("foo", foo2).build());
    client.voidToVoid();
    assertThat(requestPaths).containsExactly("/foo1/voidToVoid", "/foo2/voidToVoid");
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) DialogueClients(com.palantir.dialogue.clients.DialogueClients) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Aggregations

SampleServiceBlocking (com.palantir.dialogue.example.SampleServiceBlocking)10 Test (org.junit.jupiter.api.Test)9 DialogueClients (com.palantir.dialogue.clients.DialogueClients)3 ReloadingFactory (com.palantir.dialogue.clients.DialogueClients.ReloadingFactory)3 ServicesConfigBlock (com.palantir.conjure.java.api.config.service.ServicesConfigBlock)2 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)2 SampleServiceAsync (com.palantir.dialogue.example.SampleServiceAsync)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 X509TrustManager (javax.net.ssl.X509TrustManager)2 Splitter (com.google.common.base.Splitter)1 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 PartialServiceConfiguration (com.palantir.conjure.java.api.config.service.PartialServiceConfiguration)1 ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)1 QosException (com.palantir.conjure.java.api.errors.QosException)1