for (int i = 0; i < 5; i++)
{
ByteBuffer name = ByteBuffer.wrap(new byte[] { (byte)i });
indexes.put(name, new ColumnDefinition(name, null, IndexType.KEYS, Integer.toString(i)));
}
CFMetaData cfm = new CFMetaData("Keyspace1",
"TestApplyCFM_CF",
ColumnFamilyType.Standard,
BytesType.instance,
null,
"No comment",
1.0,
1.0,
0.5,
100000,
null,
500,
500,
500,
500,
500,
500,
500.0,
indexes);
// we'll be adding this one later. make sure it's not already there.
assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 5 })) == null;
org.apache.cassandra.avro.CfDef cfDef = CFMetaData.convertToAvro(cfm);
// add one.
org.apache.cassandra.avro.ColumnDef addIndexDef = new org.apache.cassandra.avro.ColumnDef();
addIndexDef.index_name = "5";
addIndexDef.index_type = org.apache.cassandra.avro.IndexType.KEYS;
addIndexDef.name = ByteBuffer.wrap(new byte[] { 5 });
addIndexDef.validation_class = BytesType.class.getName();
cfDef.column_metadata.add(addIndexDef);
// remove one.
org.apache.cassandra.avro.ColumnDef removeIndexDef = new org.apache.cassandra.avro.ColumnDef();
removeIndexDef.index_name = "0";
removeIndexDef.index_type = org.apache.cassandra.avro.IndexType.KEYS;
removeIndexDef.name = ByteBuffer.wrap(new byte[] { 0 });
removeIndexDef.validation_class = BytesType.class.getName();
assert cfDef.column_metadata.remove(removeIndexDef);
cfm.apply(cfDef);
for (int i = 1; i < indexes.size(); i++)
assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 1 })) != null;
assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 0 })) == null;
assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 5 })) != null;
}