@Override public int fetchBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::fetchBatchCount, config.fetchBatchCount()); }
@Override public Integer sweepReadThreads() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::sweepReadThreads, config.sweepReadThreads()); }
@Override public int mutationBatchCount() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::mutationBatchCount, config.mutationBatchCount()); }
@Override public KeyValueServiceConfig getKeyValueServiceConfig(InetSocketAddress addr) { return ImmutableCassandraKeyValueServiceConfig.builder() .addServers(addr) .poolSize(20) .keyspace("atlasdb") .credentials(ImmutableCassandraCredentialsConfig.builder() .username("cassandra") .password("cassandra") .build()) .ssl(false) .replicationFactor(1) .mutationBatchCount(10000) .mutationBatchSizeBytes(10000000) .fetchBatchCount(1000) .autoRefreshNodes(false) .build(); }
@Override public int unresponsiveHostBackoffTimeSeconds() { return chooseConfig(CassandraKeyValueServiceRuntimeConfig::unresponsiveHostBackoffTimeSeconds, config.unresponsiveHostBackoffTimeSeconds()); }
@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 boolean isQuorumAvailable(int countUnreachableNodes) { int replicationFactor = config.replicationFactor(); return countUnreachableNodes < (replicationFactor + 1) / 2; }
/** * This is the maximum number of times we'll accept connection failures to one host before blacklisting it. Note * that subsequent hosts we try in the same call will actually be blacklisted after one connection failure */ @VisibleForTesting static int getMaxRetriesPerHost() { return CassandraKeyValueServiceRuntimeConfig.getDefault().numberOfRetriesOnSameHost(); }
public static FunctionCheckedException<CassandraClient, List<TokenRange>, Exception> getDescribeRing( CassandraKeyValueServiceConfig config) { return client -> client.describe_ring(config.getKeyspaceOrThrow()); } }
private CassandraReloadableKvsConfig getReloadableConfigWithEmptyRuntimeConfig() { return new CassandraReloadableKvsConfig(config, Optional::empty); }
@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)); }
public static CassandraMutationTimestampProvider getMutationProviderWithStartingTimestamp(long timestamp) { InMemoryTimestampService timestampService = new InMemoryTimestampService(); timestampService.fastForwardTimestamp(timestamp); return CassandraMutationTimestampProviders.singleLongSupplierBacked(timestampService::getFreshTimestamp); } }
@Override protected int getMultiPutBatchCount() { return config.mutationBatchCount(); }
private <T> T chooseConfig(Function<CassandraKeyValueServiceRuntimeConfig, T> runtimeConfig, T installConfig) { return MoreObjects.firstNonNull( unwrapRuntimeConfig(runtimeConfig), installConfig); }
private static ImmutableCassandraKeyValueServiceConfig getConfigWithGcGraceSeconds(int gcGraceSeconds) { return ImmutableCassandraKeyValueServiceConfig .copyOf(CASSANDRA.getConfig()) .withGcGraceSeconds(gcGraceSeconds); }
private CassandraContainer(String dockerComposeFile, String name) { String keyspace = UUID.randomUUID().toString().replace("-", "_"); this.config = ImmutableCassandraKeyValueServiceConfig.builder() .addServers(forService(name)) .keyspace(keyspace) .credentials(ImmutableCassandraCredentialsConfig.builder() .username(USERNAME) .password(PASSWORD) .build()) .poolSize(20) .mutationBatchCount(10000) .mutationBatchSizeBytes(10000000) .fetchBatchCount(1000) .replicationFactor(1) .build(); this.dockerComposeFile = dockerComposeFile; this.name = name; }