本文整理汇总了Java中com.google.common.cache.TestingRemovalListeners.CountingRemovalListener类的典型用法代码示例。如果您正苦于以下问题:Java CountingRemovalListener类的具体用法?Java CountingRemovalListener怎么用?Java CountingRemovalListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CountingRemovalListener类属于com.google.common.cache.TestingRemovalListeners包,在下文中一共展示了CountingRemovalListener类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testEviction_maxSize
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testEviction_maxSize() {
CountingRemovalListener<Integer, Integer> removalListener = countingRemovalListener();
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.maximumSize(MAX_SIZE)
.removalListener(removalListener)
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertTrue(cache.size() <= MAX_SIZE);
}
assertEquals(MAX_SIZE, CacheTesting.accessQueueSize(cache));
assertEquals(MAX_SIZE, cache.size());
CacheTesting.processPendingNotifications(cache);
assertEquals(MAX_SIZE, removalListener.getCount());
CacheTesting.checkValidState(cache);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:CacheEvictionTest.java
示例2: testEviction_maxWeight
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testEviction_maxWeight() {
CountingRemovalListener<Integer, Integer> removalListener = countingRemovalListener();
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.maximumWeight(2 * MAX_SIZE)
.weigher(constantWeigher(2))
.removalListener(removalListener)
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertTrue(cache.size() <= MAX_SIZE);
}
assertEquals(MAX_SIZE, CacheTesting.accessQueueSize(cache));
assertEquals(MAX_SIZE, cache.size());
CacheTesting.processPendingNotifications(cache);
assertEquals(MAX_SIZE, removalListener.getCount());
CacheTesting.checkValidState(cache);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:CacheEvictionTest.java
示例3: checkExpiration
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
private void checkExpiration(LoadingCache<String, Integer> cache, WatchedCreatorLoader loader,
FakeTicker ticker, CountingRemovalListener<String, Integer> removalListener) {
for (int i = 0; i < 10; i++) {
assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
}
for (int i = 0; i < 10; i++) {
loader.reset();
assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
assertFalse("Creator should not have been called @#" + i, loader.wasCalled());
}
CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
assertEquals("Map must be empty by now", 0, cache.size());
assertEquals("Eviction notifications must be received", 10,
removalListener.getCount());
CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
// ensure that no new notifications are sent
assertEquals("Eviction notifications must be received", 10,
removalListener.getCount());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:CacheExpirationTest.java
示例4: testEviction_maxSize
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testEviction_maxSize() {
CountingRemovalListener<Integer, Integer> removalListener = countingRemovalListener();
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder()
.maximumSize(MAX_SIZE)
.removalListener(removalListener)
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertTrue(cache.size() <= MAX_SIZE);
}
assertEquals(MAX_SIZE, CacheTesting.accessQueueSize(cache));
assertEquals(MAX_SIZE, cache.size());
CacheTesting.processPendingNotifications(cache);
assertEquals(MAX_SIZE, removalListener.getCount());
CacheTesting.checkValidState(cache);
}
开发者ID:google,项目名称:guava,代码行数:20,代码来源:CacheEvictionTest.java
示例5: testEviction_maxWeight
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testEviction_maxWeight() {
CountingRemovalListener<Integer, Integer> removalListener = countingRemovalListener();
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder()
.maximumWeight(2 * MAX_SIZE)
.weigher(constantWeigher(2))
.removalListener(removalListener)
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertTrue(cache.size() <= MAX_SIZE);
}
assertEquals(MAX_SIZE, CacheTesting.accessQueueSize(cache));
assertEquals(MAX_SIZE, cache.size());
CacheTesting.processPendingNotifications(cache);
assertEquals(MAX_SIZE, removalListener.getCount());
CacheTesting.checkValidState(cache);
}
开发者ID:google,项目名称:guava,代码行数:21,代码来源:CacheEvictionTest.java
示例6: checkExpiration
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
private void checkExpiration(
LoadingCache<String, Integer> cache,
WatchedCreatorLoader loader,
FakeTicker ticker,
CountingRemovalListener<String, Integer> removalListener) {
for (int i = 0; i < 10; i++) {
assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
}
for (int i = 0; i < 10; i++) {
loader.reset();
assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
assertFalse("Creator should not have been called @#" + i, loader.wasCalled());
}
CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
assertEquals("Map must be empty by now", 0, cache.size());
assertEquals("Eviction notifications must be received", 10, removalListener.getCount());
CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
// ensure that no new notifications are sent
assertEquals("Eviction notifications must be received", 10, removalListener.getCount());
}
开发者ID:google,项目名称:guava,代码行数:26,代码来源:CacheExpirationTest.java
示例7: testReloadAfterFailure
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testReloadAfterFailure() throws ExecutionException {
final AtomicInteger count = new AtomicInteger();
final Exception e = new IllegalStateException("exception to trigger failure on first load()");
CacheLoader<Integer, String> failOnceFunction = new CacheLoader<Integer, String>() {
@Override
public String load(Integer key) throws Exception {
if (count.getAndIncrement() == 0) {
throw e;
}
return key.toString();
}
};
CountingRemovalListener<Integer, String> removalListener = countingRemovalListener();
LoadingCache<Integer, String> cache = CacheBuilder.newBuilder()
.removalListener(removalListener)
.build(failOnceFunction);
try {
cache.getUnchecked(1);
fail();
} catch (UncheckedExecutionException ue) {
assertSame(e, ue.getCause());
}
assertEquals("1", cache.getUnchecked(1));
assertEquals(0, removalListener.getCount());
count.set(0);
cache.refresh(2);
checkLoggedCause(e);
assertEquals("2", cache.getUnchecked(2));
assertEquals(0, removalListener.getCount());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:37,代码来源:CacheLoadingTest.java
示例8: testEviction_overflow
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testEviction_overflow() {
CountingRemovalListener<Object, Object> removalListener = countingRemovalListener();
IdentityLoader<Object> loader = identityLoader();
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(1L << 31)
.weigher(constantWeigher(Integer.MAX_VALUE))
.removalListener(removalListener)
.build(loader);
cache.getUnchecked(objectWithHash(0));
cache.getUnchecked(objectWithHash(0));
CacheTesting.processPendingNotifications(cache);
assertEquals(1, removalListener.getCount());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:CacheEvictionTest.java
示例9: testExpiration_expireAfterWrite
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testExpiration_expireAfterWrite() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
checkExpiration(cache, loader, ticker, removalListener);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例10: testExpiration_expireAfterAccess
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testExpiration_expireAfterAccess() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
checkExpiration(cache, loader, ticker, removalListener);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例11: testExpiringGet_expireAfterWrite
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testExpiringGet_expireAfterWrite() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
runExpirationTest(cache, loader, ticker, removalListener);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例12: testExpiringGet_expireAfterAccess
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testExpiringGet_expireAfterAccess() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
runExpirationTest(cache, loader, ticker, removalListener);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例13: testRemovalScheduler_expireAfterWrite
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterWrite() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例14: testRemovalScheduler_expireAfterAccess
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterAccess() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java
示例15: testRemovalScheduler_expireAfterBoth
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterBoth() {
FakeTicker ticker = new FakeTicker();
CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
WatchedCreatorLoader loader = new WatchedCreatorLoader();
LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
.expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
.expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
.removalListener(removalListener)
.ticker(ticker)
.build(loader);
runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:CacheExpirationTest.java
示例16: testNullCache
import com.google.common.cache.TestingRemovalListeners.CountingRemovalListener; //导入依赖的package包/类
@GwtIncompatible // CacheTesting
public void testNullCache() {
CountingRemovalListener<Object, Object> listener = countingRemovalListener();
LoadingCache<Object, Object> nullCache = new CacheBuilder<Object, Object>()
.maximumSize(0)
.removalListener(listener)
.build(identityLoader());
assertEquals(0, nullCache.size());
Object key = new Object();
assertSame(key, nullCache.getUnchecked(key));
assertEquals(1, listener.getCount());
assertEquals(0, nullCache.size());
CacheTesting.checkEmpty(nullCache.asMap());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:CacheBuilderTest.java
注:本文中的com.google.common.cache.TestingRemovalListeners.CountingRemovalListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论