private void assertTimeLockConfigDeserializedCorrectly(TimeLockClientConfig timeLockClientConfig) { assertThat(timeLockClientConfig.getClientOrThrow()).isEqualTo("brian"); assertThat(timeLockClientConfig.serversList().servers()).containsExactlyInAnyOrder( "timelock1:8080", "timelock2:8080", "timelock3:8080"); assertThat(timeLockClientConfig.serversList().sslConfiguration().isPresent()).isTrue(); SslConfiguration sslConfiguration = timeLockClientConfig.serversList().sslConfiguration().get(); assertSslConfigDeserializedCorrectly(sslConfiguration); }
private static void checkServersListHasAtLeastOneServerIfPresent(Optional<ServerListConfig> serverListOptional) { serverListOptional.ifPresent( serverList -> Preconditions.checkState(serverList.hasAtLeastOneServer(), "Server list must have at least one server.")); }
configPollingRefreshable.getRefreshable(), serverListConfig -> { if (serverListConfig.hasAtLeastOneServer()) { return createProxyWithFailover( serverListConfig.sslConfiguration().map(trustContextCreator), serverListConfig.proxyConfiguration().map(proxySelectorCreator), serverListConfig.servers(), feignConnectTimeout, feignReadTimeout,
default boolean hasAtLeastOneServer() { return servers().size() >= 1; } }
private static Function<ServerListConfig, ServerListConfig> addSslConfigurationToServerListFunction( Optional<SslConfiguration> sslConfiguration) { return serverList -> ImmutableServerListConfig.builder() .from(serverList) .sslConfiguration(getFirstPresentOptional(serverList.sslConfiguration(), sslConfiguration)) .build(); }
configPollingRefreshable.getRefreshable(), serverListConfig -> { if (serverListConfig.hasAtLeastOneServer()) { return createProxyWithFailover( serverListConfig.sslConfiguration().map(trustContextCreator), serverListConfig.proxyConfiguration().map(proxySelectorCreator), serverListConfig.servers(), feignConnectTimeout, feignReadTimeout,
public static ServerListConfig namespaceUris(ServerListConfig config, String namespace) { Set<String> serversWithNamespaces = config .servers() .stream() .map(serverAddress -> serverAddress.replaceAll("/$", "") + "/" + namespace) .collect(Collectors.toSet()); return ImmutableServerListConfig.builder() .from(config) .servers(serversWithNamespaces) .build(); } }
@Test public void preservesSslOnConversionToNamespacedServerListIfPresent() { ServerListConfig namespacedConfig = CLIENT_CONFIG.toNamespacedServerList(); assertThat(namespacedConfig.sslConfiguration(), equalTo(Optional.of(SSL_CONFIGURATION))); }
@Test public void canDeserializeRuntimeConfigWithZeroServers() throws IOException { AtlasDbRuntimeConfig runtimeConfig = AtlasDbConfigs.OBJECT_MAPPER.readValue(TEST_RUNTIME_CONFIG_NO_SERVERS_FILE, AtlasDbRuntimeConfig.class); assertThat(runtimeConfig.timestampClient().enableTimestampBatching()).isTrue(); assertThat(runtimeConfig.timelockRuntime()).isPresent(); assertThat(runtimeConfig.timelockRuntime().get().serversList().servers()).isEmpty(); assertThat(runtimeConfig.timelockRuntime().get().serversList().sslConfiguration()).isEmpty(); } }
@Test public void prioritisesRuntimeConfigIfAvailable() { ServerListConfig resolvedConfig = ServerListConfigs.parseInstallAndRuntimeConfigs( INSTALL_CONFIG, () -> Optional.of(RUNTIME_CONFIG), CLIENT); assertThat(resolvedConfig.servers()).containsExactlyInAnyOrder("one/client", "two/client"); }
@Test public void preservesAbsenceOfSslOnConversionToNamespacedServerListIfAbsent() { ImmutableServerListConfig serversListWithoutSsl = ImmutableServerListConfig.copyOf(SERVERS_LIST) .withSslConfiguration(Optional.empty()); TimeLockClientConfig config = ImmutableTimeLockClientConfig.copyOf(CLIENT_CONFIG) .withServersList(serversListWithoutSsl); assertThat(config.toNamespacedServerList().sslConfiguration(), equalTo(Optional.empty())); }
private static void checkServersListHasAtLeastOneServerIfPresent(Optional<ServerListConfig> serverListOptional) { serverListOptional.ifPresent( serverList -> Preconditions.checkState(serverList.hasAtLeastOneServer(), "Server list must have at least one server.")); }
@Test public void canDeserializeRuntimeConfig() throws IOException { AtlasDbRuntimeConfig runtimeConfig = AtlasDbConfigs.OBJECT_MAPPER.readValue(TEST_RUNTIME_CONFIG_FILE, AtlasDbRuntimeConfig.class); assertThat(runtimeConfig.timestampClient().enableTimestampBatching()).isTrue(); assertThat(runtimeConfig.timelockRuntime()).isPresent(); assertThat(runtimeConfig.timelockRuntime().get().serversList().servers()) .containsExactlyInAnyOrder( "https://foo1:12345", "https://foo2:8421", "https://foo3:9421"); assertThat(runtimeConfig.timelockRuntime().get().serversList().sslConfiguration()).satisfies( sslConfiguration -> sslConfiguration.ifPresent(this::assertSslConfigDeserializedCorrectly)); assertThat(runtimeConfig.streamStorePersistence()).satisfies( persistenceConfig -> { assertThat(persistenceConfig.numBlocksToWriteBeforePause()).isEqualTo(7); assertThat(persistenceConfig.writePauseDurationMillis()).isEqualTo(77); }); assertThat(runtimeConfig.sweep().sweepPriorityOverrides()).satisfies( overrides -> { assertThat(overrides.priorityTables()).containsExactlyInAnyOrder("atlas.mission_critical_table"); assertThat(overrides.blacklistTables()).containsExactlyInAnyOrder( "atlas.bad_table", "atlas2.immutable_log"); }); }
@Test public void namespacingCanDealWithTrailingSlash() { ServerListConfig namespacedServersList = ServerListConfigs.namespaceUris(SERVERS_LIST_3, CLIENT); assertThat(namespacedServersList.servers()).containsExactlyInAnyOrder("three/client"); }
@Test public void addingFallbackSslAddsItToTimestampBlock() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .lock(SINGLETON_SERVER_LIST) .timestamp(SINGLETON_SERVER_LIST) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, SSL_CONFIG); assertThat(withSsl.timestamp().get().sslConfiguration(), is(SSL_CONFIG)); }
@Test public void namespacingAddsClientNameCorrectly() { ServerListConfig namespacedServersList = ServerListConfigs.namespaceUris(SERVERS_LIST_1, CLIENT); assertThat(namespacedServersList.servers()).containsExactly("one/client"); }
@Test public void addingFallbackSslAddsItToLockBlock() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .lock(SINGLETON_SERVER_LIST) .timestamp(SINGLETON_SERVER_LIST) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, SSL_CONFIG); assertThat(withSsl.lock().get().sslConfiguration(), is(SSL_CONFIG)); assertThat(withoutSsl.getNamespaceString(), equalTo(TEST_NAMESPACE)); }
@Test public void namespacingAddsClientNameToAllServers() { ServerListConfig namespacedServersList = ServerListConfigs.namespaceUris(SERVERS_LIST_2, CLIENT); assertThat(namespacedServersList.servers()).containsExactlyInAnyOrder("one/client", "two/client"); }
@Test public void addingFallbackSslAddsItToTimelockServersBlock() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .timelock(TIMELOCK_CONFIG) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, SSL_CONFIG); assertThat(withSsl.timelock().get().serversList().sslConfiguration(), is(SSL_CONFIG)); }
@Test public void namespacingCanDealWithServerListConfigsWithZeroNodes() { ServerListConfig namespacedServersList = ServerListConfigs.namespaceUris(SERVERS_LIST_EMPTY, CLIENT); assertThat(namespacedServersList.servers()).isEmpty(); }