Search in sources :

Example 1 with NodeSelectionStrategy

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();
}
Also used : SSLContext(javax.net.ssl.SSLContext) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Provider(java.security.Provider) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) SslSocketFactories(com.palantir.conjure.java.config.ssl.SslSocketFactories) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Value(org.immutables.value.Value) Optional(java.util.Optional) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) SharedTaggedMetricRegistries(com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries) ClientConfigurations(com.palantir.conjure.java.client.config.ClientConfigurations) SSLContext(javax.net.ssl.SSLContext) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration)

Example 2 with NodeSelectionStrategy

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SslConfiguration(com.palantir.conjure.java.api.config.ssl.SslConfiguration) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Random(java.util.Random) SettableFuture(com.google.common.util.concurrent.SettableFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) RequestBody(com.palantir.dialogue.RequestBody) Channel(com.palantir.dialogue.Channel) Test(org.junit.jupiter.api.Test) TestResponse(com.palantir.dialogue.TestResponse) List(java.util.List) Optional(java.util.Optional) TypeMarker(com.palantir.dialogue.TypeMarker) Response(com.palantir.dialogue.Response) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Mock(org.mockito.Mock) EnumSource(org.junit.jupiter.params.provider.EnumSource) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) Mockito.lenient(org.mockito.Mockito.lenient) TestEndpoint(com.palantir.dialogue.TestEndpoint) Supplier(java.util.function.Supplier) Answer(org.mockito.stubbing.Answer) SocketException(java.net.SocketException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) SocketTimeoutException(java.net.SocketTimeoutException) DefaultConjureRuntime(com.palantir.conjure.java.dialogue.serde.DefaultConjureRuntime) Endpoint(com.palantir.dialogue.Endpoint) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) Request(com.palantir.dialogue.Request) ClientConfigurations(com.palantir.conjure.java.client.config.ClientConfigurations) OutputStream(java.io.OutputStream) SafeRuntimeException(com.palantir.logsafe.exceptions.SafeRuntimeException) TestTracing(com.palantir.tracing.TestTracing) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Futures(com.google.common.util.concurrent.Futures) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) Collections(java.util.Collections) TestResponse(com.palantir.dialogue.TestResponse) Response(com.palantir.dialogue.Response) Answer(org.mockito.stubbing.Answer) Random(java.util.Random) Request(com.palantir.dialogue.Request)

Aggregations

ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)2 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)2 ClientConfiguration (com.palantir.conjure.java.client.config.ClientConfiguration)2 ClientConfigurations (com.palantir.conjure.java.client.config.ClientConfigurations)2 NodeSelectionStrategy (com.palantir.conjure.java.client.config.NodeSelectionStrategy)2 Optional (java.util.Optional)2 ImmutableList (com.google.common.collect.ImmutableList)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 SslConfiguration (com.palantir.conjure.java.api.config.ssl.SslConfiguration)1 HostEventsSink (com.palantir.conjure.java.client.config.HostEventsSink)1 SslSocketFactories (com.palantir.conjure.java.config.ssl.SslSocketFactories)1 DefaultConjureRuntime (com.palantir.conjure.java.dialogue.serde.DefaultConjureRuntime)1 Channel (com.palantir.dialogue.Channel)1 Endpoint (com.palantir.dialogue.Endpoint)1 Request (com.palantir.dialogue.Request)1 RequestBody (com.palantir.dialogue.RequestBody)1 Response (com.palantir.dialogue.Response)1 TestEndpoint (com.palantir.dialogue.TestEndpoint)1