Search in sources :

Example 6 with SampleServiceBlocking

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

the class DialogueClientsIntegrationTest method test_unlimited_timeouts.

@Test
void test_unlimited_timeouts() {
    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.ZERO).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 7 with SampleServiceBlocking

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

the class DialogueClientsTest method sensible_errors_if_service_does_not_exist_in_scb.

@Test
void sensible_errors_if_service_does_not_exist_in_scb() {
    DialogueClients.ReloadingFactory factory = DialogueClients.create(Refreshable.only(scb)).withUserAgent(TestConfigurations.AGENT);
    SampleServiceBlocking unknown = factory.get(SampleServiceBlocking.class, "borf");
    assertThatThrownBy(unknown::voidToVoid).hasMessageContaining("Service not configured (config block not present): " + "{serviceName=borf, available=[multipass, email-service, zero-uris-service]}");
}
Also used : 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 8 with SampleServiceBlocking

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

the class ChannelCacheTest method new_config_evicts_client_but_old_one_is_still_usable.

@Test
void new_config_evicts_client_but_old_one_is_still_usable() {
    ChannelCache.ApacheCacheEntry cacheResult = cache.getApacheClient(ImmutableApacheClientRequest.builder().serviceConf(serviceConf).channelName("channelName").build());
    ChannelCache.ApacheCacheEntry cacheResult2 = cache.getApacheClient(ImmutableApacheClientRequest.builder().serviceConf(ServiceConfiguration.builder().from(serviceConf).enableHttp2(false).build()).channelName("channelName").build());
    assertThat(cacheResult).isNotSameAs(cacheResult2);
    assertThat(cache.toString()).contains("apacheCache.size=1");
    undertowHandler = exchange -> {
        exchange.setStatusCode(200);
    };
    // Some clients might still be using this channel even though we're evicting it from the cache, so it's
    // important that the evicted client is still usable. Otherwise, we get support tickets like PDS-118523
    // where outgoing requests fail with 'Connection pool shut down'
    SampleServiceBlocking evictedClient = sampleServiceBlocking(cacheResult.client());
    evictedClient.voidToVoid();
    SampleServiceBlocking client2 = sampleServiceBlocking(cacheResult2.client());
    client2.voidToVoid();
}
Also used : SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Example 9 with SampleServiceBlocking

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

the class IntegrationTest method stream_3_gigabytes.

@Test
public void stream_3_gigabytes() throws IOException {
    long oneMegabyte = 1000_000;
    int megabytes = 3000;
    long limit = megabytes * oneMegabyte;
    assertThat(limit).isGreaterThan(Integer.MAX_VALUE);
    byte[] sample = new byte[8192];
    Arrays.fill(sample, (byte) 'A');
    undertowHandler = exchange -> {
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/octet-stream");
        InputStream bigInputStream = repeat(sample, limit);
        ByteStreams.copy(bigInputStream, exchange.getOutputStream());
    };
    Stopwatch sw = Stopwatch.createStarted();
    SampleServiceBlocking service = blocking;
    InputStream maybeBinary = service.getOptionalBinary().get();
    assertThat(ByteStreams.exhaust(maybeBinary)).describedAs("Should receive exactly the number of bytes we sent!").isEqualTo(limit);
    System.out.printf("%d MB took %d millis%n", megabytes, sw.elapsed(TimeUnit.MILLISECONDS));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Stopwatch(com.google.common.base.Stopwatch) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Test(org.junit.jupiter.api.Test)

Example 10 with SampleServiceBlocking

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

the class StickyEndpointChannelsTest method all_calls_on_a_sticky_channel_go_to_one_host.

@Test
void all_calls_on_a_sticky_channel_go_to_one_host() {
    StickyEndpointChannels channels = builder().channels(ImmutableList.of(miniServer("one", serve204), miniServer("two", serve204), miniServer("three", serve204))).build();
    Channel sticky1 = channels.get();
    SampleServiceAsync async1 = SampleServiceAsync.of(sticky1, runtime);
    async1.voidToVoid();
    async1.getMyAlias();
    async1.getOptionalBinary();
    SampleServiceBlocking blocking1 = SampleServiceBlocking.of(sticky1, runtime);
    blocking1.voidToVoid();
    blocking1.voidToVoid();
    assertThat(requests).describedAs("All requests should go to the same randomly chosen host, in this case 'three'").allSatisfy(string -> assertThat(string).startsWith("[three]"));
    requests.clear();
    Channel sticky2 = channels.get();
    SampleServiceAsync async2 = SampleServiceAsync.of(sticky2, runtime);
    async2.voidToVoid();
    async2.getMyAlias();
    async2.getOptionalBinary();
    assertThat(requests).describedAs("Second batch of requests should all go to another randomly chosen host").allSatisfy(string -> assertThat(string).startsWith("[two]"));
}
Also used : SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) Channel(com.palantir.dialogue.Channel) 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