Search in sources :

Example 1 with UpdateKeyspace

use of org.apache.cassandra.db.migration.UpdateKeyspace in project eiger by wlloyd.

the class DefsTest method testUpdateKeyspace.

@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 = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(5), cf);
    new AddKeyspace(oldKs).apply();
    assert Schema.instance.getTableDefinition(cf.ksName) != null;
    assert Schema.instance.getTableDefinition(cf.ksName) == oldKs;
    // anything with cf defs should fail.
    CFMetaData cf2 = addTestCF(cf.ksName, "AddedStandard2", "A new cf for a new ks");
    KSMetaData newBadKs = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(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 = KSMetaData.testMetadata(cf.ksName + "trash", SimpleStrategy.class, KSMetaData.optsWithRF(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 = KSMetaData.testMetadata(cf.ksName, OldNetworkTopologyStrategy.class, KSMetaData.optsWithRF(1));
    new UpdateKeyspace(newKs).apply();
    KSMetaData newFetchedKs = Schema.instance.getKSMetaData(newKs.name);
    assert newFetchedKs.strategyClass.equals(newKs.strategyClass);
    assert !newFetchedKs.strategyClass.equals(oldKs.strategyClass);
}
Also used : AddKeyspace(org.apache.cassandra.db.migration.AddKeyspace) UpdateKeyspace(org.apache.cassandra.db.migration.UpdateKeyspace) Test(org.junit.Test)

Aggregations

AddKeyspace (org.apache.cassandra.db.migration.AddKeyspace)1 UpdateKeyspace (org.apache.cassandra.db.migration.UpdateKeyspace)1 Test (org.junit.Test)1