use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class StreamingTransferTest method testTransferTableCounter.
@Test
public void testTransferTableCounter() throws Exception {
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
final CounterContext cc = new CounterContext();
final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();
List<String> keys = createAndTransfer(table, cfs, new Mutator() {
/**
* Creates a new SSTable per key: all will be merged before streaming.
*/
public void mutate(String key, String col, long timestamp) throws Exception {
Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
ColumnFamily cf = ColumnFamily.create(cfs.metadata);
ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
state.writeElement(NodeId.fromInt(2), 9L, 3L, true);
state.writeElement(NodeId.fromInt(4), 4L, 2L);
state.writeElement(NodeId.fromInt(6), 3L, 3L);
state.writeElement(NodeId.fromInt(8), 2L, 4L);
cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col), state.context, timestamp));
cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col), cc.clearAllDelta(state.context), timestamp));
entries.put(key, cf);
cleanedEntries.put(key, cfCleaned);
cfs.addSSTable(SSTableUtils.prepare().ks(table.name).cf(cfs.columnFamily).generation(0).write(entries));
}
});
// filter pre-cleaned entries locally, and ensure that the end result is equal
cleanedEntries.keySet().retainAll(keys);
SSTableReader cleaned = SSTableUtils.prepare().ks(table.name).cf(cfs.columnFamily).generation(0).write(cleanedEntries);
SSTableReader streamed = cfs.getSSTables().iterator().next();
SSTableUtils.assertContentEquals(cleaned, streamed);
// Retransfer the file, making sure it is now idempotent (see CASSANDRA-3481)
cfs.clearUnsafe();
transfer(table, streamed);
SSTableReader restreamed = cfs.getSSTables().iterator().next();
SSTableUtils.assertContentEquals(streamed, restreamed);
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class SSTableImportTest method testImportSuperCf.
@Test
public void testImportSuperCf() throws IOException, ParseException, URISyntaxException {
String jsonUrl = resourcePath("SuperCF.json");
File tempSS = tempSSTableFile("Keyspace1", "Super4");
SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath());
// Verify results
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA"));
ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA"));
assert superCol != null;
assert superCol.getSubColumns().size() > 0;
IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141"));
assert subColumn.value().equals(hexToBytes("76616c75654141"));
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class SSTableImportTest method testImportCounterCf.
@Test
public void testImportCounterCf() throws IOException, URISyntaxException {
// Import JSON to temp SSTable file
String jsonUrl = resourcePath("CounterCF.json");
File tempSS = tempSSTableFile("Keyspace1", "Counter1");
SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
// Verify results
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1"));
IColumnIterator iter = qf.getSSTableColumnIterator(reader);
ColumnFamily cf = iter.getColumnFamily();
while (iter.hasNext()) cf.addColumn(iter.next());
IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA"));
assert c instanceof CounterColumn : c;
assert ((CounterColumn) c).total() == 42;
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class SSTableImportTest method testImportSimpleCfOldFormat.
@Test
public void testImportSimpleCfOldFormat() throws IOException, URISyntaxException {
// Import JSON to temp SSTable file
String jsonUrl = resourcePath("SimpleCF.oldformat.json");
File tempSS = tempSSTableFile("Keyspace1", "Standard1");
SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath());
// Verify results
SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1"));
IColumnIterator iter = qf.getSSTableColumnIterator(reader);
ColumnFamily cf = iter.getColumnFamily();
while (iter.hasNext()) cf.addColumn(iter.next());
assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141"));
assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn);
IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC"));
assert expCol.value().equals(hexToBytes("76616c4143"));
assert expCol instanceof ExpiringColumn;
assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000;
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class LazilyCompactedRowTest method assertDigest.
private void assertDigest(ColumnFamilyStore cfs, int gcBefore) throws IOException, NoSuchAlgorithmException {
Collection<SSTableReader> sstables = cfs.getSSTables();
AbstractCompactionIterable ci1 = new CompactionIterable(OperationType.UNKNOWN, sstables, new PreCompactingController(cfs, sstables, gcBefore, false));
AbstractCompactionIterable ci2 = new CompactionIterable(OperationType.UNKNOWN, sstables, new LazilyCompactingController(cfs, sstables, gcBefore, false));
CloseableIterator<AbstractCompactedRow> iter1 = ci1.iterator();
CloseableIterator<AbstractCompactedRow> iter2 = ci2.iterator();
while (true) {
if (!iter1.hasNext()) {
assert !iter2.hasNext();
break;
}
AbstractCompactedRow row1 = iter1.next();
AbstractCompactedRow row2 = iter2.next();
MessageDigest digest1 = MessageDigest.getInstance("MD5");
MessageDigest digest2 = MessageDigest.getInstance("MD5");
row1.update(digest1);
row2.update(digest2);
assert MessageDigest.isEqual(digest1.digest(), digest2.digest());
}
}
Aggregations