public void testGet_expireAfterAccess() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterAccess(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterWrite() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterWrite(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .maximumSize(0) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
assertEquals(1, segment.count); assertSame(value, segment.get(key, hash)); RemovalNotification<Object, Object> notification = listener.remove(); assertEquals(immutableEntry(key, value2), notification); assertEquals(RemovalCause.REPLACED, notification.getCause()); assertSame(value4, segment.get(key, hash)); assertEquals(1, segment.count); notification = listener.remove(); assertEquals(immutableEntry(key, value3), notification); assertEquals(RemovalCause.REPLACED, notification.getCause()); assertSame(value4, segment.get(key, hash)); assertEquals(1, segment.count); notification = listener.remove(); assertEquals(immutableEntry(key, null), notification); assertEquals(RemovalCause.COLLECTED, notification.getCause());
RemovalNotification<String, String> notification = listener.remove(); assertEquals("a", notification.getKey()); assertEquals("a", notification.getValue());
public void testGet_expireAfterWrite() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterWrite(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .maximumSize(0) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterAccess() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterAccess(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
static <K, V> void assertNotified( QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) { RemovalNotification<K, V> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(value, notification.getValue()); assertSame(cause, notification.getCause()); }
RemovalNotification<String, String> notification = listener.remove(); assertEquals("a", notification.getKey()); assertEquals("a", notification.getValue());
public void testGet_expireAfterWrite() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterWrite(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
RemovalNotification<String, String> notification = listener.remove(); assertEquals("a", notification.getKey()); assertEquals("a", notification.getValue());
public void testGet_expireAfterAccess() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterAccess(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
assertEquals(1, segment.count); assertSame(value, segment.get(key, hash)); RemovalNotification<Object, Object> notification = listener.remove(); assertEquals(immutableEntry(key, value2), notification); assertEquals(RemovalCause.REPLACED, notification.getCause()); assertSame(value4, segment.get(key, hash)); assertEquals(1, segment.count); notification = listener.remove(); assertEquals(immutableEntry(key, value3), notification); assertEquals(RemovalCause.REPLACED, notification.getCause()); assertSame(value4, segment.get(key, hash)); assertEquals(1, segment.count); notification = listener.remove(); assertEquals(immutableEntry(key, null), notification); assertEquals(RemovalCause.COLLECTED, notification.getCause());
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .maximumSize(0) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
static <K, V> void assertNotified( QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) { RemovalNotification<K, V> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(value, notification.getValue()); assertSame(cause, notification.getCause()); }