private CassandraReloadableKvsConfig getReloadableConfigWithEmptyRuntimeConfig() { return new CassandraReloadableKvsConfig(config, Optional::empty); }
@Override public int unresponsiveHostBackoffTimeSeconds() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::unresponsiveHostBackoffTimeSeconds, config.unresponsiveHostBackoffTimeSeconds()); }
private <T> T chooseConfig(Function<CassandraKeyValueServiceRuntimeConfig, T> runtimeConfig, T installConfig) { return MoreObjects.firstNonNull( unwrapRuntimeConfig(runtimeConfig), installConfig); }
@Test public void ifRuntimeConfigIsModified_reloadableConfigIsAlsoModified() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithRuntimeConfig(); int firstValue = 1; int secondValue = 2; when(runtimeConfig.sweepReadThreads()).thenReturn(firstValue, secondValue); assertThat(reloadableConfig.sweepReadThreads(), is(firstValue)); assertThat(reloadableConfig.sweepReadThreads(), is(secondValue)); }
@Test public void ifNoRuntimeConfig_resolvesToInstallConfig() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithEmptyRuntimeConfig(); boolean installConfigParam = true; when(config.autoRefreshNodes()).thenReturn(installConfigParam); assertThat(reloadableConfig.autoRefreshNodes(), is(installConfigParam)); }
@Test public void ifInstallAndRuntimeConfig_resolvesToRuntimeConfig() { CassandraReloadableKvsConfig reloadableConfig = getReloadableConfigWithRuntimeConfig(); int installConfigParam = 1; when(config.sweepReadThreads()).thenReturn(installConfigParam); int runtimeConfigParam = 2; when(runtimeConfig.sweepReadThreads()).thenReturn(runtimeConfigParam); assertThat(reloadableConfig.sweepReadThreads(), is(runtimeConfigParam)); }
@Override public int mutationBatchSizeBytes() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::mutationBatchSizeBytes, config.mutationBatchSizeBytes()); }
private CassandraReloadableKvsConfig getReloadableConfigWithRuntimeConfig() { return new CassandraReloadableKvsConfig(config, () -> Optional.of(runtimeConfig)); } }
private <T> T chooseConfig(Function<CassandraKeyValueServiceRuntimeConfig, T> runtimeConfig, T installConfig) { return MoreObjects.firstNonNull( unwrapRuntimeConfig(runtimeConfig), installConfig); }
@Override public int fetchBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::fetchBatchCount, config.fetchBatchCount()); }
@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); }
@Override public int mutationBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::mutationBatchCount, config.mutationBatchCount()); }
@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); }
@Override public Integer sweepReadThreads() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::sweepReadThreads, config.sweepReadThreads()); }
@Override public int fetchBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::fetchBatchCount, config.fetchBatchCount()); }
@Override public int unresponsiveHostBackoffTimeSeconds() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::unresponsiveHostBackoffTimeSeconds, config.unresponsiveHostBackoffTimeSeconds()); }
@Override public int mutationBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::mutationBatchCount, config.mutationBatchCount()); }
@Override public int mutationBatchSizeBytes() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::mutationBatchSizeBytes, config.mutationBatchSizeBytes()); }
@Override public Integer sweepReadThreads() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::sweepReadThreads, config.sweepReadThreads()); }