Search in sources :

Example 6 with CacheTransaction

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction in project titan by thinkaurelius.

the class ExpirationCacheTest method testGracePeriod.

private void testGracePeriod(Duration graceWait) throws Exception {
    final int minCleanupTriggerCalls = 5;
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys, numCols);
    //Replace cache with proper times
    cache = getCache(store, Duration.ofDays(200), graceWait);
    StaticBuffer key = BufferUtil.getIntBuffer(81);
    List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2, 8);
    verifyResults(key, keys, query, 6);
    //If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    Instant utime = times.getTime();
    store.resetCounter();
    //...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 5);
    assertEquals(2, store.getSliceCalls());
    //however, the key is expired and hence repeated calls need to go through to the store
    verifyResults(key, keys, query, 5);
    assertEquals(4, store.getSliceCalls());
    //however, when we sleep past the grace wait time and trigger a cleanup...
    times.sleepPast(utime.plus(graceWait));
    for (int t = 0; t < minCleanupTriggerCalls; t++) {
        assertEquals(5, cache.getSlice(new KeySliceQuery(key, query), tx).size());
        times.sleepFor(Duration.ofMillis(5));
    }
    //...the cache should cache results again
    store.resetCounter();
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) CacheTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Aggregations

CacheTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.CacheTransaction)6 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)4 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)3 ArrayList (java.util.ArrayList)3 EntryList (com.thinkaurelius.titan.diskstorage.EntryList)2 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)2 Instant (java.time.Instant)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Entry (com.thinkaurelius.titan.diskstorage.Entry)1 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)1 NoKCVSCache (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.NoKCVSCache)1 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)1 Test (org.junit.Test)1