Search in sources :

Example 1 with ServicesConfigBlock

use of com.palantir.conjure.java.api.config.service.ServicesConfigBlock in project atlasdb by palantir.

the class DialogueClientOptionsTest method serviceConfigBlockGeneration.

@Test
public void serviceConfigBlockGeneration() {
    ServicesConfigBlock servicesConfigBlock = DialogueClientOptions.toServicesConfigBlock(ImmutableMap.of(SERVICE_NAME, REMOTE_SERVICE_CONFIGURATION_EXTENDED_TIMEOUT));
    assertThat(servicesConfigBlock.services()).containsOnlyKeys(SERVICE_NAME);
    PartialServiceConfiguration partialServiceConfiguration = servicesConfigBlock.services().get(SERVICE_NAME);
    assertThat(partialServiceConfiguration.uris()).hasSameElementsAs(SERVERS);
    assertThat(partialServiceConfiguration.security()).contains(SSL_CONFIGURATION);
    assertThat(partialServiceConfiguration.proxyConfiguration()).isEmpty();
    assertThat(partialServiceConfiguration.backoffSlotSize()).contains(ClientOptionsConstants.STANDARD_BACKOFF_SLOT_SIZE);
    assertThat(partialServiceConfiguration.connectTimeout()).contains(ClientOptionsConstants.CONNECT_TIMEOUT);
    assertThat(partialServiceConfiguration.maxNumRetries()).contains(ClientOptionsConstants.STANDARD_MAX_RETRIES);
    assertThat(partialServiceConfiguration.readTimeout()).contains(ClientOptionsConstants.LONG_READ_TIMEOUT);
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) Test(org.junit.Test)

Example 2 with ServicesConfigBlock

use of com.palantir.conjure.java.api.config.service.ServicesConfigBlock in project atlasdb by palantir.

the class DialogueClientOptionsTest method differentlyKeyedServicesTreatedDifferently.

@Test
public void differentlyKeyedServicesTreatedDifferently() {
    String otherServiceName = "tom";
    ServicesConfigBlock servicesConfigBlock = DialogueClientOptions.toServicesConfigBlock(ImmutableMap.of(SERVICE_NAME, REMOTE_SERVICE_CONFIGURATION_EXTENDED_TIMEOUT, otherServiceName, REMOTE_SERVICE_CONFIGURATION_SHORT_TIMEOUT));
    assertThat(servicesConfigBlock.services()).containsOnlyKeys(SERVICE_NAME, otherServiceName);
    PartialServiceConfiguration partialServiceConfiguration = servicesConfigBlock.services().get(SERVICE_NAME);
    assertThat(partialServiceConfiguration.readTimeout()).contains(ClientOptionsConstants.LONG_READ_TIMEOUT);
    assertThat(partialServiceConfiguration.writeTimeout()).contains(ClientOptionsConstants.LONG_READ_TIMEOUT);
    PartialServiceConfiguration otherPartialServiceConfiguration = servicesConfigBlock.services().get(otherServiceName);
    assertThat(otherPartialServiceConfiguration.readTimeout()).contains(ClientOptionsConstants.SHORT_READ_TIMEOUT);
    assertThat(otherPartialServiceConfiguration.writeTimeout()).contains(ClientOptionsConstants.SHORT_READ_TIMEOUT);
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) Test(org.junit.Test)

Example 3 with ServicesConfigBlock

use of com.palantir.conjure.java.api.config.service.ServicesConfigBlock in project dialogue by palantir.

the class DialogueClientsIntegrationTest method testSticky.

private <F> void testSticky(BiFunction<ReloadingFactory, String, F> factoryFactory, BiFunction<F, Class<SampleServiceAsync>, SampleServiceAsync> clientFactory) {
    List<StringToVoidRequestPath> requestPaths = Collections.synchronizedList(new ArrayList<>());
    int maxConcurrentRequestsPerServer = 10;
    Map<String, Integer> activeRequestsPerServer = new ConcurrentHashMap<>();
    undertowHandler = exchange -> {
        String requestPath = exchange.getRequestPath();
        StringToVoidRequestPath path = parse(requestPath);
        String server = path.requestPath();
        try {
            int activeRequests = activeRequestsPerServer.compute(server, (_ignore, activeRequests1) -> {
                if (activeRequests1 == null) {
                    return 1;
                } else {
                    return activeRequests1 + 1;
                }
            });
            if (activeRequests > maxConcurrentRequestsPerServer) {
                exchange.setStatusCode(200);
            } else {
                exchange.setStatusCode(429);
            }
        } finally {
            activeRequestsPerServer.compute(server, (_ignore, activeRequests12) -> {
                Preconditions.checkNotNull(activeRequests12, "activeRequests");
                Preconditions.checkState(activeRequests12 > 0, "activeRequests");
                return activeRequests12 - 1;
            });
            requestPaths.add(path);
        }
    };
    SettableRefreshable<ServicesConfigBlock> refreshable = Refreshable.create(ServicesConfigBlock.builder().from(scb).putServices(FOO_SERVICE, threeFoos).build());
    DialogueClients.ReloadingFactory factory = DialogueClients.create(refreshable).withUserAgent(TestConfigurations.AGENT);
    F stickyChannels = factoryFactory.apply(factory, FOO_SERVICE);
    int numClients = 3;
    int numRequestPerClient = 1000;
    List<ListenableFuture<?>> requests = new ArrayList<>();
    for (int i = 0; i < numClients; i++) {
        SampleServiceAsync client = clientFactory.apply(stickyChannels, SampleServiceAsync.class);
        String clientId = Integer.toString(i);
        IntStream.range(0, numRequestPerClient).forEach(_ignore -> requests.add(client.stringToVoid(clientId)));
    }
    assertThat(Futures.whenAllComplete(requests).run(() -> {
    }, MoreExecutors.directExecutor())).succeedsWithin(Duration.ofMinutes(1));
    assertThat(requestPaths).hasSizeGreaterThanOrEqualTo(numClients * numRequestPerClient);
    Set<StringToVoidRequestPath> uniquePaths = new HashSet<>(requestPaths);
    assertThat(uniquePaths).hasSize(numClients);
    // *I think* this technically has a chance to flake, but let's see how it goes. I am trying to make sure the
    // requests are actually being pinned and not just because all the requests went to a single node.
    assertThat(uniquePaths.stream().map(StringToVoidRequestPath::server)).hasSizeGreaterThanOrEqualTo(2);
    List<String> clientIds = uniquePaths.stream().map(StringToVoidRequestPath::client).collect(Collectors.toList());
    assertThat(clientIds).containsExactlyInAnyOrder("0", "1", "2");
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DialogueClients(com.palantir.dialogue.clients.DialogueClients) HashSet(java.util.HashSet)

Example 4 with ServicesConfigBlock

use of com.palantir.conjure.java.api.config.service.ServicesConfigBlock 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");
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) 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 5 with ServicesConfigBlock

use of com.palantir.conjure.java.api.config.service.ServicesConfigBlock in project dialogue by palantir.

the class DialogueClientsTest method getStickyChannels_live_reloads_nicely.

@Test
void getStickyChannels_live_reloads_nicely() {
    SettableRefreshable<ServicesConfigBlock> refreshable = Refreshable.create(scb);
    StickyChannelFactory stickyChannels = DialogueClients.create(refreshable).withUserAgent(TestConfigurations.AGENT).withMaxNumRetries(0).getStickyChannels("zero-uris-service");
    ListenableFuture<Response> future = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
    assertThatThrownBy(future::get).describedAs("Nice error message when service exists but has zero uris").hasCauseInstanceOf(SafeIllegalStateException.class).hasMessageContaining("Service not configured");
    refreshable.update(ServicesConfigBlock.builder().from(scb).putServices("zero-uris-service", PartialServiceConfiguration.builder().addUris("https://live-reloaded-uri-appeared").build()).build());
    ListenableFuture<Response> future2 = stickyChannels.getStickyChannel().execute(TestEndpoint.POST, Request.builder().build());
    assertThatThrownBy(future2::get).describedAs("Made a real network call").hasCauseInstanceOf(UnknownHostException.class);
}
Also used : Response(com.palantir.dialogue.Response) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Test(org.junit.jupiter.api.Test)

Aggregations

ServicesConfigBlock (com.palantir.conjure.java.api.config.service.ServicesConfigBlock)5 PartialServiceConfiguration (com.palantir.conjure.java.api.config.service.PartialServiceConfiguration)2 DialogueClients (com.palantir.dialogue.clients.DialogueClients)2 ReloadingFactory (com.palantir.dialogue.clients.DialogueClients.ReloadingFactory)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Response (com.palantir.dialogue.Response)1 StickyChannelFactory (com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory)1 SampleServiceAsync (com.palantir.dialogue.example.SampleServiceAsync)1 SampleServiceBlocking (com.palantir.dialogue.example.SampleServiceBlocking)1 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1