@Test public void testPutL1() throws ExecutionException { cache.put(KEY, new String(TEST_VALUE_1)); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); assertEquals(TEST_VALUE_1, res); assertEquals(0, counter.get()); }
@Test public void testL1Hit() throws ExecutionException { cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); assertEquals(TEST_VALUE_1, res); assertEquals(1, counter.get()); assertEquals(1, cache.size()); }
@Test public void testEmptyCache() throws ExecutionException { String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); assertEquals(TEST_VALUE_1, res); assertEquals(1, counter.get()); assertEquals(1, cache.size()); }
@Test public void testL2IsNotClearedIfTheItemIsInL1() throws ExecutionException { FakeTicker ticker = new FakeTicker(); cache = new SmallTableCache.SmallTableLocalCache<>(ticker); cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); forceOOMToClearSoftValues(); ticker.advance(60, TimeUnit.SECONDS); cache.cleanup(); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); assertEquals(TEST_VALUE_1, res); assertEquals(1, counter.get()); assertEquals(1, cache.size()); }
@Test public void testL2Miss() throws ExecutionException { FakeTicker ticker = new FakeTicker(); cache = new SmallTableCache.SmallTableLocalCache<>(ticker); cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); ticker.advance(60, TimeUnit.SECONDS); cache.cleanup(); forceOOMToClearSoftValues(); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); assertEquals(TEST_VALUE_2, res); assertEquals(2, counter.get()); assertEquals(1, cache.size()); }
@Test public void testL2Hit() throws ExecutionException { FakeTicker ticker = new FakeTicker(); cache = new SmallTableCache.SmallTableLocalCache<>(ticker); cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); ticker.advance(60, TimeUnit.SECONDS); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); assertEquals(TEST_VALUE_1, res); assertEquals(1, counter.get()); assertEquals(1, cache.size()); }
@Test public void testPutL2() throws ExecutionException { FakeTicker ticker = new FakeTicker(); cache = new SmallTableCache.SmallTableLocalCache<>(ticker); cache.put(KEY, new String(TEST_VALUE_1)); String res = cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_2); }); ticker.advance(60, TimeUnit.SECONDS); cache.cleanup(); assertEquals(TEST_VALUE_1, res); assertEquals(0, counter.get()); }
public static MapJoinTableContainer get(String key, Callable<MapJoinTableContainer> valueLoader) throws ExecutionException { return TABLE_CONTAINER_CACHE.get(key, valueLoader); }
@Test public void testClear() throws ExecutionException { cache.get(KEY, () -> { counter.incrementAndGet(); return new String(TEST_VALUE_1); }); cache.clear((k, v) -> { }); assertEquals(1, counter.get()); assertEquals(0, cache.size()); }