runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
public void testExpirationOrder_access() {
// test lru within a single segment
FakeTicker ticker = new FakeTicker();
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.expireAfterAccess(11, MILLISECONDS)
.ticker(ticker)
.build(loader);
for (int i = 0; i < 10; i++) {
cache.getUnchecked(i);
ticker.advance(1, MILLISECONDS);
}
Set<Integer> keySet = cache.asMap().keySet();
assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
// 0 expires
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9);
// reorder
getAll(cache, asList(0, 1, 2));
CacheTesting.drainRecencyQueues(cache);
ticker.advance(2, MILLISECONDS);
assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2);
// 3 expires
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(4, 5, 6, 7, 8, 9, 0, 1, 2);
// reorder
getAll(cache, asList(5, 7, 9));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(4, 6, 8, 0, 1, 2, 5, 7, 9);
// 4 expires
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(6, 8, 0, 1, 2, 5, 7, 9);
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(6, 8, 0, 1, 2, 5, 7, 9);
// 6 expires
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(8, 0, 1, 2, 5, 7, 9);
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(8, 0, 1, 2, 5, 7, 9);
// 8 expires
ticker.advance(1, MILLISECONDS);
assertThat(keySet).containsExactly(0, 1, 2, 5, 7, 9);
}