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