use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class RowResolverTest method testResolveSupersetDisjoint.
@Test
public void testResolveSupersetDisjoint() {
ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
cf1.addColumn(column("c1", "v1", 0));
ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
cf2.addColumn(column("c2", "v2", 1));
ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2));
assertColumns(resolved, "c1", "c2");
assertColumns(ColumnFamily.diff(cf1, resolved), "c2");
assertColumns(ColumnFamily.diff(cf2, resolved), "c1");
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class RowResolverTest method testResolveDeleted.
@Test
public void testResolveDeleted() {
// one CF with columns timestamped before a delete in another cf
ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1");
cf1.addColumn(column("one", "A", 0));
ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1");
cf2.delete((int) (System.currentTimeMillis() / 1000), 1);
ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2));
// no columns in the cf
assertColumns(resolved);
assertTrue(resolved.isMarkedForDelete());
assertEquals(1, resolved.getMarkedForDeleteAt());
ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1");
scf1.addColumn(superColumn(scf1, "super-foo", column("one", "A", 0)));
ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1");
scf2.delete((int) (System.currentTimeMillis() / 1000), 1);
ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2));
// no columns in the cf
assertColumns(superResolved);
assertTrue(superResolved.isMarkedForDelete());
assertEquals(1, superResolved.getMarkedForDeleteAt());
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class RowResolverTest method testResolveDeletedSuper.
@Test
public void testResolveDeletedSuper() {
// subcolumn is newer than a tombstone on its parent, but not newer than the row deletion
ColumnFamily scf1 = ColumnFamily.create("Keyspace1", "Super1");
SuperColumn sc = superColumn(scf1, "super-foo", column("one", "A", 1));
sc.delete((int) (System.currentTimeMillis() / 1000), 0);
scf1.addColumn(sc);
ColumnFamily scf2 = ColumnFamily.create("Keyspace1", "Super1");
scf2.delete((int) (System.currentTimeMillis() / 1000), 2);
ColumnFamily superResolved = RowRepairResolver.resolveSuperset(Arrays.asList(scf1, scf2));
// no columns in the cf
assertColumns(superResolved);
assertTrue(superResolved.isMarkedForDelete());
assertEquals(2, superResolved.getMarkedForDeleteAt());
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class SSTableExportTest method testEnumeratekeys.
@Test
public void testEnumeratekeys() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "Standard1");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
// Add rowB
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
writer.append(Util.dk("rowB"), cfamily);
cfamily.clear();
writer.closeAndOpenReader();
// Enumerate and verify
File temp = File.createTempFile("Standard1", ".txt");
SSTableExport.enumeratekeys(writer.getFilename(), new PrintStream(temp.getPath()));
FileReader file = new FileReader(temp);
char[] buf = new char[(int) temp.length()];
file.read(buf);
String output = new String(buf);
String sep = System.getProperty("line.separator");
assert output.equals(asHex("rowA") + sep + asHex("rowB") + sep) : output;
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class SSTableExportTest method testEscapingDoubleQuotes.
@Test
public void testEscapingDoubleQuotes() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
JSONArray data = (JSONArray) rowA.get(0);
assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
assert data.get(1).equals("{\"foo\":\"bar\"}");
}
Aggregations