static void drainRecencyQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> map = toLocalCache(cache); for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); } } }
static void expireEntries(LocalCache<?, ?> cchm, long expiringTime, FakeTicker ticker) { for (Segment<?, ?> segment : cchm.segments) { drainRecencyQueue(segment); } ticker.advance(2 * expiringTime, TimeUnit.MILLISECONDS); long now = ticker.read(); for (Segment<?, ?> segment : cchm.segments) { expireEntries(segment, now); assertEquals("Expiration queue must be empty by now", 0, writeQueueSize(segment)); assertEquals("Expiration queue must be empty by now", 0, accessQueueSize(segment)); assertEquals("Segments must be empty by now", 0, segmentSize(segment)); } cchm.processPendingNotifications(); }
/** * Assuming the given cache has maximum size {@code maxSize}, this method populates the cache (by * getting a bunch of different keys), then makes sure all the items in the cache are also in the * eviction queue. It will invoke the given {@code operation} on the first element in the eviction * queue, and then reverify that all items in the cache are in the eviction queue, and verify that * the head of the eviction queue has changed as a result of the operation. */ static void checkRecency( LoadingCache<Integer, Integer> cache, int maxSize, Receiver<ReferenceEntry<Integer, Integer>> operation) { checkNotNull(operation); if (hasLocalCache(cache)) { warmUp(cache, 0, 2 * maxSize); LocalCache<Integer, Integer> cchm = toLocalCache(cache); Segment<?, ?> segment = cchm.segments[0]; drainRecencyQueue(segment); assertEquals(maxSize, accessQueueSize(cache)); assertEquals(maxSize, cache.size()); ReferenceEntry<?, ?> originalHead = segment.accessQueue.peek(); @SuppressWarnings("unchecked") ReferenceEntry<Integer, Integer> entry = (ReferenceEntry) originalHead; operation.accept(entry); drainRecencyQueue(segment); assertNotSame(originalHead, segment.accessQueue.peek()); assertEquals(cache.size(), accessQueueSize(cache)); } }
static void checkEviction(LocalCache<?, ?> map) { if (map.evictsBySize()) { for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); assertEquals(0, segment.recencyQueue.size()); assertEquals(0, segment.readCount.get()); ReferenceEntry<?, ?> prev = null; for (ReferenceEntry<?, ?> current : segment.accessQueue) { if (prev != null) { assertSame(prev, current.getPreviousInAccessQueue()); assertSame(prev.getNextInAccessQueue(), current); } Object key = current.getKey(); if (key != null) { assertSame(current, segment.getEntry(key, current.getHash())); } prev = current; } } } else { for (Segment<?, ?> segment : map.segments) { assertEquals(0, segment.recencyQueue.size()); } } }
static void drainRecencyQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> map = toLocalCache(cache); for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); } } }
/** * Assuming the given cache has maximum size {@code maxSize}, this method populates the cache (by * getting a bunch of different keys), then makes sure all the items in the cache are also in the * eviction queue. It will invoke the given {@code operation} on the first element in the * eviction queue, and then reverify that all items in the cache are in the eviction queue, and * verify that the head of the eviction queue has changed as a result of the operation. */ static void checkRecency(LoadingCache<Integer, Integer> cache, int maxSize, Receiver<ReferenceEntry<Integer, Integer>> operation) { checkNotNull(operation); if (hasLocalCache(cache)) { warmUp(cache, 0, 2 * maxSize); LocalCache<Integer, Integer> cchm = toLocalCache(cache); Segment<?, ?> segment = cchm.segments[0]; drainRecencyQueue(segment); assertEquals(maxSize, accessQueueSize(cache)); assertEquals(maxSize, cache.size()); ReferenceEntry<?, ?> originalHead = segment.accessQueue.peek(); @SuppressWarnings("unchecked") ReferenceEntry<Integer, Integer> entry = (ReferenceEntry) originalHead; operation.accept(entry); drainRecencyQueue(segment); assertNotSame(originalHead, segment.accessQueue.peek()); assertEquals(cache.size(), accessQueueSize(cache)); } }
static void expireEntries( LocalCache<?, ?> cchm, long expiringTime, FakeTicker ticker) { for (Segment<?, ?> segment : cchm.segments) { drainRecencyQueue(segment); } ticker.advance(2 * expiringTime, TimeUnit.MILLISECONDS); long now = ticker.read(); for (Segment<?, ?> segment : cchm.segments) { expireEntries(segment, now); assertEquals("Expiration queue must be empty by now", 0, writeQueueSize(segment)); assertEquals("Expiration queue must be empty by now", 0, accessQueueSize(segment)); assertEquals("Segments must be empty by now", 0, segmentSize(segment)); } cchm.processPendingNotifications(); }
static void checkEviction(LocalCache<?, ?> map) { if (map.evictsBySize()) { for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); assertEquals(0, segment.recencyQueue.size()); assertEquals(0, segment.readCount.get()); ReferenceEntry<?, ?> prev = null; for (ReferenceEntry<?, ?> current : segment.accessQueue) { if (prev != null) { assertSame(prev, current.getPreviousInAccessQueue()); assertSame(prev.getNextInAccessQueue(), current); } Object key = current.getKey(); if (key != null) { assertSame(current, segment.getEntry(key, current.getHash())); } prev = current; } } } else { for (Segment<?, ?> segment : map.segments) { assertEquals(0, segment.recencyQueue.size()); } } }