use of com.palantir.conjure.java.client.config.NodeSelectionStrategy in project dialogue by palantir.
the class AugmentClientConfig method getClientConf.
static ClientConfiguration getClientConf(ServiceConfiguration serviceConfig, AugmentClientConfig augment) {
ClientConfiguration.Builder builder = ClientConfiguration.builder().from(ClientConfigurations.of(serviceConfig));
SSLContext context = augment.securityProvider().map(provider -> SslSocketFactories.createSslContext(serviceConfig.security(), provider)).orElseGet(() -> SslSocketFactories.createSslContext(serviceConfig.security()));
// Reduce the session cache size for clients. We expect TLS connections to be reused, thus the cache isn't
// terribly important.
context.getClientSessionContext().setSessionCacheSize(100);
builder.sslSocketFactory(context.getSocketFactory());
if (!serviceConfig.maxNumRetries().isPresent()) {
augment.maxNumRetries().ifPresent(builder::maxNumRetries);
}
if (augment.securityProvider().isPresent()) {
// Opt into GCM when custom providers (Conscrypt) is used.
builder.enableGcmCipherSuites(true);
}
builder.userAgent(augment.userAgent());
builder.taggedMetricRegistry(augment.taggedMetrics());
augment.nodeSelectionStrategy().ifPresent(builder::nodeSelectionStrategy);
augment.clientQoS().ifPresent(builder::clientQoS);
augment.serverQoS().ifPresent(builder::serverQoS);
augment.retryOnTimeout().ifPresent(builder::retryOnTimeout);
augment.hostEventsSink().ifPresent(builder::hostEventsSink);
return builder.build();
}
use of com.palantir.conjure.java.client.config.NodeSelectionStrategy in project dialogue by palantir.
the class DialogueChannelTest method test_can_use_sticky_attachments_impl.
private void test_can_use_sticky_attachments_impl(NodeSelectionStrategy nodeSelectionStrategy, ImmutableList<String> uris) throws ExecutionException {
String uriHeader = "uri";
DialogueChannelFactory factory = args -> {
mockChannel = Mockito.mock(Channel.class);
lenient().when(mockChannel.execute(eq(endpoint), any())).thenAnswer((Answer<ListenableFuture<Response>>) _invocation -> Futures.immediateFuture(TestResponse.withBody(null).withHeader(uriHeader, args.uri())));
return mockChannel;
};
channel = DialogueChannel.builder().channelName("my-channel").clientConfiguration(ClientConfiguration.builder().uris(uris).from(stubConfig).nodeSelectionStrategy(nodeSelectionStrategy).build()).factory(factory).random(new Random(1L)).build();
request = createRequestWithAddExecutedOnAttachment();
response = Futures.getDone(channel.execute(endpoint, request));
String expectedUri = response.getFirstHeader(uriHeader).get();
Consumer<Request> stickyTarget = StickyAttachments.copyStickyTarget(response);
request = Request.builder().build();
stickyTarget.accept(request);
response = Futures.getDone(channel.execute(endpoint, request));
assertThat(response.getFirstHeader(uriHeader)).hasValue(expectedUri);
}
Aggregations