public void testEviction_invalidateAll() { // test that .invalidateAll() resets total weight state correctly IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(10).build(loader); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).isEmpty(); // add 0, 1, 2, 3, 4 getAll(cache, asList(0, 1, 2, 3, 4)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 1, 2, 3, 4); // invalidate all cache.invalidateAll(); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).isEmpty(); // add 5, 6, 7, 8, 9, 10, 11, 12 getAll(cache, asList(5, 6, 7, 8, 9, 10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 10, 11, 12); }
public void testEviction_lru() { // test lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(10).build(loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // re-order getAll(cache, asList(0, 1, 2)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); // evict 3, 4, 5 getAll(cache, asList(10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10, 11, 12); // re-order getAll(cache, asList(6, 7, 8)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 11, 12, 6, 7, 8); // evict 9, 0, 1 getAll(cache, asList(13, 14, 15)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(2, 10, 11, 12, 6, 7, 8, 13, 14, 15); }
public void testEviction_overweight() { // test weighted lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder() .concurrencyLevel(1) .maximumWeight(45) .weigher(intKeyWeigher()) .build(loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // add an at-the-maximum-weight entry getAll(cache, asList(45)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 45); // add an over-the-maximum-weight entry getAll(cache, asList(46)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).contains(0); }
CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 6, 7, 8); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15, 9); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 7, 8, 15, 9, 1);
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 1, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(1, 3, 6, 8); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(6, 8, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 6);
public void testEviction_invalidateAll() { // test that .invalidateAll() resets total weight state correctly IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .maximumSize(10), loader); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).isEmpty(); // add 0, 1, 2, 3, 4 getAll(cache, asList(0, 1, 2, 3, 4)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 1, 2, 3, 4); // invalidate all cache.invalidateAll(); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).isEmpty(); // add 5, 6, 7, 8, 9, 10, 11, 12 getAll(cache, asList(5, 6, 7, 8, 9, 10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 10, 11, 12); }
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 0); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0);
public void disabled_testEviction_lru() { // test lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .maximumSize(10), loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // re-order getAll(cache, asList(0, 1, 2)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); // evict 3, 4, 5 getAll(cache, asList(10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10, 11, 12); // re-order getAll(cache, asList(6, 7, 8)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 11, 12, 6, 7, 8); // evict 9, 0, 1 getAll(cache, asList(13, 14, 15)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(2, 10, 11, 12, 6, 7, 8, 13, 14, 15); }
CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 6, 7, 8); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15, 9); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 7, 8, 15, 9, 1);
public void testEviction_overweight() { // test weighted lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .maximumWeight(45) .weigher(intKeyWeigher()), loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // add an at-the-maximum-weight entry getAll(cache, asList(45)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 45); // add an over-the-maximum-weight entry getAll(cache, asList(46)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).contains(0); }
CacheTesting.drainRecencyQueues(cache); ticker.advance(2, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(4, 6, 8, 0, 1, 2, 5, 7, 9);
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 1, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(1, 3, 6, 8); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(6, 8, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 6);
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 0); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0);
CacheTesting.drainRecencyQueues(cache); ticker.advance(2, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(4, 6, 8, 0, 1, 2, 5, 7, 9);
public void testEviction_invalidateAll() { // test that .invalidateAll() resets total weight state correctly IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder() .concurrencyLevel(1) .maximumSize(10) .build(loader); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).isEmpty(); // add 0, 1, 2, 3, 4 getAll(cache, asList(0, 1, 2, 3, 4)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 1, 2, 3, 4); // invalidate all cache.invalidateAll(); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).isEmpty(); // add 5, 6, 7, 8, 9, 10, 11, 12 getAll(cache, asList(5, 6, 7, 8, 9, 10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 10, 11, 12); }
public void testEviction_lru() { // test lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder() .concurrencyLevel(1) .maximumSize(10) .build(loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // re-order getAll(cache, asList(0, 1, 2)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); // evict 3, 4, 5 getAll(cache, asList(10, 11, 12)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10, 11, 12); // re-order getAll(cache, asList(6, 7, 8)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 11, 12, 6, 7, 8); // evict 9, 0, 1 getAll(cache, asList(13, 14, 15)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(2, 10, 11, 12, 6, 7, 8, 13, 14, 15); }
CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 6, 7, 8); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 6, 7, 8, 15, 9); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 7, 8, 15, 9, 1);
public void testEviction_overweight() { // test weighted lru within a single segment IdentityLoader<Integer> loader = identityLoader(); LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder() .concurrencyLevel(1) .maximumWeight(45) .weigher(intKeyWeigher()) .build(loader); CacheTesting.warmUp(cache, 0, 10); Set<Integer> keySet = cache.asMap().keySet(); assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); // add an at-the-maximum-weight entry getAll(cache, asList(45)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).containsExactly(0, 45); // add an over-the-maximum-weight entry getAll(cache, asList(46)); CacheTesting.drainRecencyQueues(cache); assertThat(keySet).contains(0); }
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 1, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(1, 3, 6, 8); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(6, 8, 3); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 6);
CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 0); CacheTesting.drainRecencyQueues(cache); ticker.advance(1, MILLISECONDS); assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0);