Search in sources :

Example 16 with ColumnFamily

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

the class SSTableExportTest method testExportCounterCf.

@Test
public void testExportCounterCf() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Counter1");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(null, new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis()));
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("Counter1", ".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 colA = (JSONArray) rowA.get(0);
    assert hexToBytes((String) colA.get(0)).equals(ByteBufferUtil.bytes("colA"));
    assert ((String) colA.get(3)).equals("c");
    assert (Long) colA.get(4) == Long.MIN_VALUE;
}
Also used : PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) CounterColumn(org.apache.cassandra.db.CounterColumn) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 17 with ColumnFamily

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

the class SSTableImportTest method testImportSimpleCf.

@Test
public void testImportSimpleCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("SimpleCF.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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) DeletedColumn(org.apache.cassandra.db.DeletedColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 18 with ColumnFamily

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

the class CacheProviderTest method createCF.

private ColumnFamily createCF() {
    ColumnFamily cf = ColumnFamily.create(tableName, cfName);
    cf.addColumn(column("vijay", "great", 1));
    cf.addColumn(column("awesome", "vijay", 1));
    return cf;
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 19 with ColumnFamily

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

the class CacheProviderTest method testHeapCache.

@Test
public void testHeapCache() throws InterruptedException {
    ICache<String, ColumnFamily> cache = ConcurrentLinkedHashCache.create(CAPACITY);
    ColumnFamily cf = createCF();
    simpleCase(cf, cache);
    concurrentCase(cf, cache);
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 20 with ColumnFamily

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

the class CacheProviderTest method testSerializingCache.

@Test
public void testSerializingCache() throws InterruptedException {
    ICache<String, ColumnFamily> cache = new SerializingCache<String, ColumnFamily>(CAPACITY, false, ColumnFamily.serializer());
    ColumnFamily cf = createCF();
    simpleCase(cf, cache);
    concurrentCase(cf, cache);
}
Also used : ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

ColumnFamily (org.apache.cassandra.db.ColumnFamily)36 Test (org.junit.Test)26 QueryPath (org.apache.cassandra.db.filter.QueryPath)14 File (java.io.File)11 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)11 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 IColumn (org.apache.cassandra.db.IColumn)8 TableTest (org.apache.cassandra.db.TableTest)7 PrintStream (java.io.PrintStream)6 RowMutation (org.apache.cassandra.db.RowMutation)6 Table (org.apache.cassandra.db.Table)6 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)6 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)6 FileReader (java.io.FileReader)5 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ByteBuffer (java.nio.ByteBuffer)3