Search in sources :

Example 11 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class TTLExpiryTest method testNoExpire.

@Test
public void testNoExpire() throws InterruptedException, IOException {
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Standard1");
    cfs.truncateBlocking();
    cfs.disableAutoCompaction();
    MigrationManager.announceTableUpdate(cfs.metadata().unbuild().gcGraceSeconds(0).build(), true);
    long timestamp = System.currentTimeMillis();
    String key = "ttl";
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col", ByteBufferUtil.EMPTY_BYTE_BUFFER).add("col7", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col2", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key).add("col3", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    String noTTLKey = "nottl";
    new RowUpdateBuilder(cfs.metadata(), timestamp, noTTLKey).add("col311", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
    cfs.forceBlockingFlush();
    // wait for ttl to expire
    Thread.sleep(2000);
    assertEquals(4, cfs.getLiveSSTables().size());
    cfs.enableAutoCompaction(true);
    assertEquals(1, cfs.getLiveSSTables().size());
    SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
    ISSTableScanner scanner = sstable.getScanner(ColumnFilter.all(cfs.metadata()), DataRange.allData(cfs.getPartitioner()));
    assertTrue(scanner.hasNext());
    while (scanner.hasNext()) {
        UnfilteredRowIterator iter = scanner.next();
        assertEquals(Util.dk(noTTLKey), iter.partitionKey());
    }
    scanner.close();
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Test(org.junit.Test)

Aggregations

ISSTableScanner (org.apache.cassandra.io.sstable.ISSTableScanner)11 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)9 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)5 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 Collectors (java.util.stream.Collectors)2 UpdateBuilder (org.apache.cassandra.UpdateBuilder)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1