mirror of https://github.com/apache/cassandra
additional test to check if a CF can be added to an empty KS after creation. patch by Erik Onnen, reviewed by Gary Dusbabek. CASSANDRA-1082
git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@949210 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd02495654
commit
0c1986e53e
|
|
@ -25,8 +25,6 @@ import org.apache.cassandra.config.CFMetaData;
|
|||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.config.KSMetaData;
|
||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||
import org.apache.cassandra.db.commitlog.CommitLogSegment;
|
||||
import org.apache.cassandra.db.filter.QueryFilter;
|
||||
import org.apache.cassandra.db.filter.QueryPath;
|
||||
import org.apache.cassandra.db.marshal.BytesType;
|
||||
|
|
@ -42,7 +40,6 @@ import org.apache.cassandra.utils.FBUtilities;
|
|||
import org.apache.cassandra.db.marshal.UTF8Type;
|
||||
import org.apache.cassandra.utils.UUIDGen;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
|
@ -165,10 +162,8 @@ public class DefsTest extends CleanupHelper
|
|||
KSMetaData original = DatabaseDescriptor.getTableDefinition(ks);
|
||||
|
||||
CFMetaData newCf = new CFMetaData(original.name, cf, ColumnFamilyType.Standard, ClockType.Timestamp, new UTF8Type(), null, "A New Column Family", 0, false, 0);
|
||||
int clSegments = CommitLog.instance().getSegmentCount();
|
||||
assert !DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
new AddColumnFamily(newCf).apply();
|
||||
assert CommitLog.instance().getSegmentCount() == clSegments + 1;
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().containsKey(newCf.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(ks).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
|
|
@ -283,9 +278,7 @@ public class DefsTest extends CleanupHelper
|
|||
CFMetaData newCf = new CFMetaData("NewKeyspace1", "AddedStandard1", ColumnFamilyType.Standard, ClockType.Timestamp, new UTF8Type(), null, "A new cf for a new ks", 0, false, 0);
|
||||
KSMetaData newKs = new KSMetaData(newCf.tableName, RackUnawareStrategy.class, 5, newCf);
|
||||
|
||||
int segmentCount = CommitLog.instance().getSegmentCount();
|
||||
new AddKeyspace(newKs).apply();
|
||||
assert CommitLog.instance().getSegmentCount() == segmentCount + 1;
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(newCf.tableName) != null;
|
||||
assert DatabaseDescriptor.getTableDefinition(newCf.tableName) == newKs;
|
||||
|
|
@ -427,4 +420,40 @@ public class DefsTest extends CleanupHelper
|
|||
// tests old write.
|
||||
assert Arrays.equals(cfam.getColumn("col1".getBytes()).value(), "value".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEmptyKsAddNewCf() throws ConfigurationException, IOException, ExecutionException, InterruptedException
|
||||
{
|
||||
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") == null;
|
||||
|
||||
KSMetaData newKs = new KSMetaData("EmptyKeyspace", RackUnawareStrategy.class, 5, new CFMetaData[]{});
|
||||
|
||||
new AddKeyspace(newKs).apply();
|
||||
assert DatabaseDescriptor.getTableDefinition("EmptyKeyspace") != null;
|
||||
|
||||
CFMetaData newCf = new CFMetaData("EmptyKeyspace", "AddedLater", ColumnFamilyType.Standard, ClockType.Timestamp, new UTF8Type(), null, "A new CF to add to an empty KS", 0, false, 0);
|
||||
|
||||
//should not exist until apply
|
||||
assert !DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
|
||||
//add the new CF to the empty space
|
||||
new AddColumnFamily(newCf).apply();
|
||||
|
||||
assert DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().containsKey(newCf.cfName);
|
||||
assert DatabaseDescriptor.getTableDefinition(newKs.name).cfMetaData().get(newCf.cfName).equals(newCf);
|
||||
|
||||
// now read and write to it.
|
||||
DecoratedKey dk = Util.dk("key0");
|
||||
RowMutation rm = new RowMutation(newKs.name, dk.key);
|
||||
rm.add(new QueryPath(newCf.cfName, null, "col0".getBytes()), "value0".getBytes(), new TimestampClock(1L));
|
||||
rm.apply();
|
||||
ColumnFamilyStore store = Table.open(newKs.name).getColumnFamilyStore(newCf.cfName);
|
||||
assert store != null;
|
||||
store.forceBlockingFlush();
|
||||
|
||||
ColumnFamily cfam = store.getColumnFamily(QueryFilter.getNamesFilter(dk, new QueryPath(newCf.cfName), "col0".getBytes()));
|
||||
assert cfam.getColumn("col0".getBytes()) != null;
|
||||
IColumn col = cfam.getColumn("col0".getBytes());
|
||||
assert Arrays.equals("value0".getBytes(), col.value());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue