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