@Test
public void testUpdateKeyspace() throws ConfigurationException, IOException, ExecutionException, InterruptedException
{
// create a keyspace to serve as existing.
CFMetaData cf = addTestCF("UpdatedKeyspace", "AddedStandard1", "A new cf for a new ks");
KSMetaData oldKs = new KSMetaData(cf.tableName, SimpleStrategy.class, null, 5, cf);
new AddKeyspace(oldKs).apply();
assert DatabaseDescriptor.getTableDefinition(cf.tableName) != null;
assert DatabaseDescriptor.getTableDefinition(cf.tableName) == oldKs;
// anything with cf defs should fail.
CFMetaData cf2 = addTestCF(cf.tableName, "AddedStandard2", "A new cf for a new ks");
KSMetaData newBadKs = new KSMetaData(cf.tableName, SimpleStrategy.class, null, 4, cf2);
try
{
new UpdateKeyspace(newBadKs).apply();
throw new AssertionError("Should not have been able to update a KS with a KS that described column families.");
}
catch (ConfigurationException ex)
{
// expected.
}
// names should match.
KSMetaData newBadKs2 = new KSMetaData(cf.tableName + "trash", SimpleStrategy.class, null, 4);
try
{
new UpdateKeyspace(newBadKs2).apply();
throw new AssertionError("Should not have been able to update a KS with an invalid KS name.");
}
catch (ConfigurationException ex)
{
// expected.
}
KSMetaData newKs = new KSMetaData(cf.tableName, OldNetworkTopologyStrategy.class, null, 1);
new UpdateKeyspace(newKs).apply();
KSMetaData newFetchedKs = DatabaseDescriptor.getKSMetaData(newKs.name);
assert newFetchedKs.replicationFactor == newKs.replicationFactor;
assert newFetchedKs.replicationFactor != oldKs.replicationFactor;
assert newFetchedKs.strategyClass.equals(newKs.strategyClass);
assert !newFetchedKs.strategyClass.equals(oldKs.strategyClass);
}