本文整理汇总了Java中com.google.common.cache.TestingCacheLoaders.IdentityLoader类的典型用法代码示例。如果您正苦于以下问题:Java IdentityLoader类的具体用法?Java IdentityLoader怎么用?Java IdentityLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityLoader类属于com.google.common.cache.TestingCacheLoaders包,在下文中一共展示了IdentityLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEviction_maxSize
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的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);
}
示例2: testEviction_maxWeight
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的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);
}
示例3: testEviction_overweight
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_overweight() {
// test weighted lru within a single segment
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(45)
.weigher(intKeyWeigher())
.build(loader);
CacheTesting.warmUp(cache, 0, 10);
Set<Integer> keySet = cache.asMap().keySet();
assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
// add an at-the-maximum-weight entry
getAll(cache, asList(45));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(0, 45);
// add an over-the-maximum-weight entry
getAll(cache, asList(46));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).contains(0);
}
示例4: testEviction_invalidateAll
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_invalidateAll() {
// test that .invalidateAll() resets total weight state correctly
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumSize(10)
.build(loader);
Set<Integer> keySet = cache.asMap().keySet();
assertThat(keySet).isEmpty();
// add 0, 1, 2, 3, 4
getAll(cache, asList(0, 1, 2, 3, 4));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(0, 1, 2, 3, 4);
// invalidate all
cache.invalidateAll();
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).isEmpty();
// add 5, 6, 7, 8, 9, 10, 11, 12
getAll(cache, asList(5, 6, 7, 8, 9, 10, 11, 12));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 10, 11, 12);
}
示例5: testEviction_maxWeightOneSegment
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_maxWeightOneSegment() {
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(2 * MAX_SIZE)
.weigher(constantWeigher(2))
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertEquals(Math.min(i + 1, MAX_SIZE), cache.size());
}
assertEquals(MAX_SIZE, cache.size());
CacheTesting.checkValidState(cache);
}
示例6: testEviction_maxSize
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的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);
}
示例7: testEviction_maxWeight
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的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);
}
示例8: testEviction_overweight
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_overweight() {
// test weighted lru within a single segment
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(45)
.weigher(intKeyWeigher())
.build(loader);
CacheTesting.warmUp(cache, 0, 10);
Set<Integer> keySet = cache.asMap().keySet();
assertThat(keySet).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
// add an at-the-maximum-weight entry
getAll(cache, asList(45));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(0, 45);
// add an over-the-maximum-weight entry
getAll(cache, asList(46));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).contains(0);
}
示例9: testEviction_invalidateAll
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_invalidateAll() {
// test that .invalidateAll() resets total weight state correctly
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(10).build(loader);
Set<Integer> keySet = cache.asMap().keySet();
assertThat(keySet).isEmpty();
// add 0, 1, 2, 3, 4
getAll(cache, asList(0, 1, 2, 3, 4));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(0, 1, 2, 3, 4);
// invalidate all
cache.invalidateAll();
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).isEmpty();
// add 5, 6, 7, 8, 9, 10, 11, 12
getAll(cache, asList(5, 6, 7, 8, 9, 10, 11, 12));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(5, 6, 7, 8, 9, 10, 11, 12);
}
示例10: testEviction_setMaxSegmentSize
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_setMaxSegmentSize() {
IdentityLoader<Object> loader = identityLoader();
for (int i = 1; i < 1000; i++) {
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.maximumSize(i)
.build(loader);
assertEquals(i, CacheTesting.getTotalSegmentSize(cache));
}
}
示例11: testEviction_setMaxSegmentWeight
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_setMaxSegmentWeight() {
IdentityLoader<Object> loader = identityLoader();
for (int i = 1; i < 1000; i++) {
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.maximumWeight(i)
.weigher(constantWeigher(1))
.build(loader);
assertEquals(i, CacheTesting.getTotalSegmentSize(cache));
}
}
示例12: testEviction_maxSizeOneSegment
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_maxSizeOneSegment() {
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumSize(MAX_SIZE)
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertEquals(Math.min(i + 1, MAX_SIZE), cache.size());
}
assertEquals(MAX_SIZE, cache.size());
CacheTesting.checkValidState(cache);
}
示例13: testEviction_maxWeightOneSegment
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_maxWeightOneSegment() {
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumWeight(2 * MAX_SIZE)
.weigher(constantWeigher(2))
.build(loader);
for (int i = 0; i < 2 * MAX_SIZE; i++) {
cache.getUnchecked(i);
assertEquals(Math.min(i + 1, MAX_SIZE), cache.size());
}
assertEquals(MAX_SIZE, cache.size());
CacheTesting.checkValidState(cache);
}
示例14: testEviction_overflow
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的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());
}
示例15: testUpdateRecency_onGet
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testUpdateRecency_onGet() {
IdentityLoader<Integer> loader = identityLoader();
final LoadingCache<Integer, Integer> cache =
CacheBuilder.newBuilder().maximumSize(MAX_SIZE).build(loader);
CacheTesting.checkRecency(cache, MAX_SIZE,
new Receiver<ReferenceEntry<Integer, Integer>>() {
@Override
public void accept(ReferenceEntry<Integer, Integer> entry) {
cache.getUnchecked(entry.getKey());
}
});
}