/** * Returns the entries that were added to the map, so they won't fall out of a map with weak or * soft references until the caller drops the reference to the returned entries. */ private List<Entry<Object, Object>> warmUp( LoadingCache<Object, Object> cache, int minimum, int maximum) { List<Entry<Object, Object>> entries = Lists.newArrayList(); for (int i = minimum; i < maximum; i++) { Object key = i; Object value = cache.getUnchecked(key); entries.add(entryOf(key, value)); } return entries; }
/** * Returns the entries that were added to the map, so they won't fall out of a map with weak or * soft references until the caller drops the reference to the returned entries. */ private List<Map.Entry<Object, Object>> warmUp( LoadingCache<Object, Object> cache, int minimum, int maximum) { List<Map.Entry<Object, Object>> entries = Lists.newArrayList(); for (int i = minimum; i < maximum; i++) { Object key = i; Object value = cache.getUnchecked(key); entries.add(entryOf(key, value)); } return entries; }
public void testPut_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().put(entry.getKey(), newValue)); // don't let the new entry get GCed warmed.add(entryOf(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().put(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPutIfAbsent_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().putIfAbsent(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().putIfAbsent(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPut_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().put(entry.getKey(), newValue)); // don't let the new entry get GCed warmed.add(entryOf(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().put(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPutIfAbsent_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().putIfAbsent(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().putIfAbsent(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
/** * Returns the entries that were added to the map, so they won't fall out of a map with weak or * soft references until the caller drops the reference to the returned entries. */ private List<Map.Entry<Object, Object>> warmUp( LoadingCache<Object, Object> cache, int minimum, int maximum) { List<Map.Entry<Object, Object>> entries = Lists.newArrayList(); for (int i = minimum; i < maximum; i++) { Object key = i; Object value = cache.getUnchecked(key); entries.add(entryOf(key, value)); } return entries; }
public void testPut_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().put(entry.getKey(), newValue)); // don't let the new entry get GCed warmed.add(entryOf(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().put(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(newValue, cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }
public void testPutIfAbsent_populated() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object newValue = new Object(); assertSame(entry.getValue(), cache.asMap().putIfAbsent(entry.getKey(), newValue)); Object newKey = new Object(); assertNull(cache.asMap().putIfAbsent(newKey, entry.getValue())); // this getUnchecked() call shouldn't be a cache miss; verified below assertEquals(entry.getValue(), cache.getUnchecked(entry.getKey())); assertEquals(entry.getValue(), cache.getUnchecked(newKey)); // don't let the new entry get GCed warmed.add(entryOf(newKey, entry.getValue())); } assertEquals(WARMUP_SIZE, cache.stats().missCount()); checkValidState(cache); } }