@VisibleForTesting static CassandraKeyValueServiceConfig preprocessKvsConfig( KeyValueServiceConfig config, Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig, Optional<String> namespace) { Preconditions.checkArgument(config instanceof CassandraKeyValueServiceConfig, "Invalid KeyValueServiceConfig. Expected a KeyValueServiceConfig of type" + " CassandraKeyValueServiceConfig, found %s.", config.getClass()); CassandraKeyValueServiceConfig cassandraConfig = (CassandraKeyValueServiceConfig) config; String desiredKeyspace = OptionalResolver.resolve(namespace, cassandraConfig.keyspace()); CassandraKeyValueServiceConfig configWithNamespace = CassandraKeyValueServiceConfigs .copyWithKeyspace(cassandraConfig, desiredKeyspace); return new CassandraReloadableKvsConfig(configWithNamespace, runtimeConfig); }
@Test public void throwsOnTwoUnequalOptionals() { assertThatThrownBy(() -> OptionalResolver.resolve(PRESENT_OPTIONAL_1, PRESENT_OPTIONAL_2)) .isInstanceOf(IllegalArgumentException.class); } }
@Test public void throwsOnOneEmptyAndOneNullOptional() { assertThatThrownBy(() -> OptionalResolver.resolve(null, Optional.empty())) .isInstanceOf(IllegalArgumentException.class); }
@Test public void throwsOnTwoNullOptionals() { assertThatThrownBy(() -> OptionalResolver.resolve(null, null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void throwsOnTwoEmptyOptionals() { assertThatThrownBy(() -> OptionalResolver.resolve(EMPTY_OPTIONAL, EMPTY_OPTIONAL)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void resolvesToValueOnTwoEqualOptionals() { assertThat(OptionalResolver.resolve(PRESENT_OPTIONAL_1, Optional.of(STRING_1))).isEqualTo(STRING_1); }
@Test public void resolvesToValueIfOneOptionalPresentAndOneIsNull() { assertThat(OptionalResolver.resolve(PRESENT_OPTIONAL_1, null)).isEqualTo(STRING_1); }
private static Supplier<ServerListConfig> getServerListConfigSupplierForTimeLock( AtlasDbConfig config, Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier) { Preconditions.checkState(!remoteTimestampAndLockOrLeaderBlocksPresent(config), "Cannot create raw services from timelock with another source of timestamps/locks configured!"); TimeLockClientConfig clientConfig = config.timelock().orElse(ImmutableTimeLockClientConfig.builder().build()); String resolvedClient = OptionalResolver.resolve(clientConfig.client(), config.namespace()); return () -> ServerListConfigs.parseInstallAndRuntimeConfigs( clientConfig, () -> runtimeConfigSupplier.get().timelockRuntime(), resolvedClient); }
@VisibleForTesting static CassandraKeyValueServiceConfig preprocessKvsConfig( KeyValueServiceConfig config, Supplier<Optional<KeyValueServiceRuntimeConfig>> runtimeConfig, Optional<String> namespace) { Preconditions.checkArgument(config instanceof CassandraKeyValueServiceConfig, "Invalid KeyValueServiceConfig. Expected a KeyValueServiceConfig of type" + " CassandraKeyValueServiceConfig, found %s.", config.getClass()); CassandraKeyValueServiceConfig cassandraConfig = (CassandraKeyValueServiceConfig) config; String desiredKeyspace = OptionalResolver.resolve(namespace, cassandraConfig.keyspace()); CassandraKeyValueServiceConfig configWithNamespace = CassandraKeyValueServiceConfigs .copyWithKeyspace(cassandraConfig, desiredKeyspace); return new CassandraReloadableKvsConfig(configWithNamespace, runtimeConfig); }
private static Supplier<ServerListConfig> getServerListConfigSupplierForTimeLock( AtlasDbConfig config, Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier) { Preconditions.checkState(!remoteTimestampAndLockOrLeaderBlocksPresent(config), "Cannot create raw services from timelock with another source of timestamps/locks configured!"); TimeLockClientConfig clientConfig = config.timelock().orElse(ImmutableTimeLockClientConfig.builder().build()); String resolvedClient = OptionalResolver.resolve(clientConfig.client(), config.namespace()); return () -> ServerListConfigs.parseInstallAndRuntimeConfigs( clientConfig, () -> runtimeConfigSupplier.get().timelockRuntime(), resolvedClient); }