static void drainRecencyQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> map = toLocalCache(cache); for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); } } }
static void drainReferenceQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { drainReferenceQueues(toLocalCache(cache)); } }
/** * Peeks into the cache's internals to verify that its expiration queue is consistent. Verifies * that the next/prev links in the expiration queue are correct, and that the queue is ordered by * expiration time. */ static void checkExpiration(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkExpiration(toLocalCache(cache)); } }
static void processPendingNotifications(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> cchm = toLocalCache(cache); cchm.processPendingNotifications(); } }
/** * Peeks into the cache's internals to verify that its eviction queue is consistent. Verifies that * the prev/next links are correct, and that all items in each segment are also in that segment's * eviction (recency) queue. */ static void checkEviction(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkEviction(toLocalCache(cache)); } }
/** * Peeks into the cache's internals to check its internal consistency. Verifies that each * segment's count matches its #elements (after cleanup), each segment is unlocked, each entry * contains a non-null key and value, and the eviction and expiration queues are consistent (see * {@link #checkEviction}, {@link #checkExpiration}). */ static void checkValidState(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkValidState(toLocalCache(cache)); } }
/** * 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 drainRecencyQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> map = toLocalCache(cache); for (Segment<?, ?> segment : map.segments) { drainRecencyQueue(segment); } } }
/** * Peeks into the cache's internals to verify that its expiration queue is consistent. Verifies * that the next/prev links in the expiration queue are correct, and that the queue is ordered * by expiration time. */ static void checkExpiration(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkExpiration(toLocalCache(cache)); } }
static void drainReferenceQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { drainReferenceQueues(toLocalCache(cache)); } }
/** * Peeks into the cache's internals to check its internal consistency. Verifies that each * segment's count matches its #elements (after cleanup), each segment is unlocked, each entry * contains a non-null key and value, and the eviction and expiration queues are consistent * (see {@link #checkEviction}, {@link #checkExpiration}). */ static void checkValidState(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkValidState(toLocalCache(cache)); } }
/** * Peeks into the cache's internals to verify that its eviction queue is consistent. Verifies * that the prev/next links are correct, and that all items in each segment are also in that * segment's eviction (recency) queue. */ static void checkEviction(Cache<?, ?> cache) { if (hasLocalCache(cache)) { checkEviction(toLocalCache(cache)); } }
static void processPendingNotifications(Cache<?, ?> cache) { if (hasLocalCache(cache)) { LocalCache<?, ?> cchm = toLocalCache(cache); 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)); } }