Search in sources :

Example 1 with TTLKCVSManager

use of org.janusgraph.diskstorage.keycolumnvalue.ttl.TTLKCVSManager in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testStoreTTL.

@Test
public void testStoreTTL() throws Exception {
    KeyColumnValueStoreManager storeManager = manager;
    // @see TTLKCVSManager
    if (storeManager.getFeatures().hasCellTTL() && !storeManager.getFeatures().hasStoreTTL()) {
        storeManager = new TTLKCVSManager(storeManager);
    } else if (!storeManager.getFeatures().hasStoreTTL()) {
        return;
    }
    assertTrue(storeManager.getFeatures().hasStoreTTL());
    final TimeUnit sec = TimeUnit.SECONDS;
    final int storeTTLSeconds = (int) TestGraphConfigs.getTTL(sec);
    StoreMetaData.Container opts = new StoreMetaData.Container();
    opts.put(StoreMetaData.TTL, storeTTLSeconds);
    KeyColumnValueStore storeWithTTL = storeManager.openDatabase("testStore_with_TTL", opts);
    populateDBWith100Keys(storeWithTTL);
    tx.commit();
    tx = startTx();
    final StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(2);
    StaticBuffer start = KeyColumnValueStoreUtil.stringToByteBuffer("a");
    StaticBuffer end = KeyColumnValueStoreUtil.stringToByteBuffer("d");
    EntryList results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
    assertEquals(3, results.size());
    Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(storeTTLSeconds * 1.25), sec));
    tx.commit();
    tx = startTx();
    results = storeWithTTL.getSlice(new KeySliceQuery(key, new SliceQuery(start, end)), tx);
    // should be empty if TTL was applied properly
    assertEquals(0, results.size());
    storeWithTTL.close();
}
Also used : KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) TTLKCVSManager(org.janusgraph.diskstorage.keycolumnvalue.ttl.TTLKCVSManager) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) TimeUnit(java.util.concurrent.TimeUnit) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)1 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)1 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)1 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)1 TTLKCVSManager (org.janusgraph.diskstorage.keycolumnvalue.ttl.TTLKCVSManager)1 Test (org.junit.jupiter.api.Test)1