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();
}
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]}");
}
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();
}
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));
}
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]"));
}
Aggregations