@Test public void simpleStrategyOneDcHighRfThrows() throws TException { KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "3")); assertThatThrownBy(() -> CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config)) .isInstanceOf(IllegalStateException.class); }
@Test public void simpleStrategyOneDcOneRfSucceedsAndUpdatesKsDef() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1)); when(config.replicationFactor()).thenReturn(1); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap .of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_class).isEqualTo(CassandraConstants.NETWORK_STRATEGY); assertThat(ksDef.strategy_options).isEqualTo(ImmutableMap.of(DC_1, "1")); }
@Test public void returnSameKsDefIfNodeTopologyChecksIgnored() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1)); when(config.replicationFactor()).thenReturn(7); when(config.ignoreNodeTopologyChecks()).thenReturn(true); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap .of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1", DC_1, "7"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_class).isEqualTo(CassandraConstants.SIMPLE_STRATEGY); assertThat(ksDef.strategy_options).isEqualTo(strategyOptions); }
@Test public void simpleStrategyMultipleDcsThrows() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1), createDetails(DC_1, RACK_1, HOST_2), createDetails(DC_1, RACK_1, HOST_3), createDetails(DC_2, RACK_1, HOST_4)); when(config.replicationFactor()).thenReturn(1); KsDef ksDef = new KsDef("test", CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()); ksDef.setStrategy_options(ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1")); assertThatThrownBy(() -> CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config)) .isInstanceOf(IllegalStateException.class); }
private static void updateExistingKeyspace(CassandraClientPool clientPool, CassandraKeyValueServiceConfig config) throws TException { clientPool.runWithRetry((FunctionCheckedException<CassandraClient, Void, TException>) client -> { KsDef originalKsDef = client.describe_keyspace(config.getKeyspaceOrThrow()); // there was an existing keyspace // check and make sure it's definition is up to date with our config KsDef modifiedKsDef = originalKsDef.deepCopy(); checkAndSetReplicationFactor( client, modifiedKsDef, config); if (!modifiedKsDef.equals(originalKsDef)) { // Can't call system_update_keyspace to update replication factor if CfDefs are set modifiedKsDef.setCf_defs(ImmutableList.of()); client.system_update_keyspace(modifiedKsDef); CassandraKeyValueServices.waitForSchemaVersions(config, client, "after updating the existing keyspace"); } return null; }); }
@Test public void networkStrategyMultipleDcsSucceeds() throws TException { setTopology(createDetails(DC_1, RACK_1, HOST_1), createDetails(DC_1, RACK_1, HOST_2), createDetails(DC_1, RACK_1, HOST_3), createDetails(DC_2, RACK_1, HOST_4)); when(config.replicationFactor()).thenReturn(3); KsDef ksDef = new KsDef("test", CassandraConstants.NETWORK_STRATEGY, ImmutableList.of()); ImmutableMap<String, String> strategyOptions = ImmutableMap.of( CassandraConstants.REPLICATION_FACTOR_OPTION, "3", DC_1, "3", DC_2, "3"); ksDef.setStrategy_options(strategyOptions); ksDef = CassandraVerifier.checkAndSetReplicationFactor(client, ksDef, config); assertThat(ksDef.strategy_options).isEqualTo(strategyOptions); }
private static void updateExistingKeyspace(CassandraClientPool clientPool, CassandraKeyValueServiceConfig config) throws TException { clientPool.runWithRetry((FunctionCheckedException<CassandraClient, Void, TException>) client -> { KsDef originalKsDef = client.describe_keyspace(config.getKeyspaceOrThrow()); // there was an existing keyspace // check and make sure it's definition is up to date with our config KsDef modifiedKsDef = originalKsDef.deepCopy(); checkAndSetReplicationFactor( client, modifiedKsDef, config); if (!modifiedKsDef.equals(originalKsDef)) { // Can't call system_update_keyspace to update replication factor if CfDefs are set modifiedKsDef.setCf_defs(ImmutableList.of()); client.system_update_keyspace(modifiedKsDef); CassandraKeyValueServices.waitForSchemaVersions(config, client, "after updating the existing keyspace"); } return null; }); }