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();
}
Aggregations