本文整理汇总了Java中com.google.common.cache.TestingCacheLoaders.IdentityLoader类的典型用法代码示例。如果您正苦于以下问题:Java IdentityLoader类的具体用法?Java IdentityLoader怎么用?Java IdentityLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityLoader类属于com.google.common.cache.TestingCacheLoaders包,在下文中一共展示了IdentityLoader类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:google,项目名称:guava,代码行数:17,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:google,项目名称:guava,代码行数:20,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:google,项目名称:guava,代码行数:21,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:google,项目名称:guava,代码行数:24,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:google,项目名称:guava,代码行数:25,代码来源:CacheEvictionTest.java
示例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));
}
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:CacheEvictionTest.java
示例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));
}
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:CacheEvictionTest.java
示例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);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:CacheEvictionTest.java
示例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());
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:CacheEvictionTest.java
示例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());
}
});
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:CacheEvictionTest.java
示例16: testUpdateRecency_onInvalidate
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testUpdateRecency_onInvalidate() {
IdentityLoader<Integer> loader = identityLoader();
final LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.maximumSize(MAX_SIZE)
.concurrencyLevel(1)
.build(loader);
CacheTesting.checkRecency(cache, MAX_SIZE,
new Receiver<ReferenceEntry<Integer, Integer>>() {
@Override
public void accept(ReferenceEntry<Integer, Integer> entry) {
Integer key = entry.getKey();
cache.invalidate(key);
}
});
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:CacheEvictionTest.java
示例17: testEviction_lru
import com.google.common.cache.TestingCacheLoaders.IdentityLoader; //导入依赖的package包/类
public void testEviction_lru() {
// test lru within a single segment
IdentityLoader<Integer> loader = identityLoader();
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumSize(10)
.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);
// re-order
getAll(cache, asList(0, 1, 2));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(3, 4, 5, 6, 7, 8, 9, 0, 1, 2);
// evict 3, 4, 5
getAll(cache, asList(10, 11, 12));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(6, 7, 8, 9, 0, 1, 2, 10, 11, 12);
// re-order
getAll(cache, asList(6, 7, 8));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(9, 0, 1, 2, 10, 11, 12, 6, 7, 8);
// evict 9, 0, 1
getAll(cache, asList(13, 14, 15));
CacheTesting.drainRecencyQueues(cache);
assertThat(keySet).containsExactly(2, 10, 11, 12, 6, 7, 8, 13, 14, 15);
}
开发者ID:zugzug90,项目名称:guava-mock,代码行数:32,代码来源:CacheEvictionTest.java
注:本文中的com.google.common.cache.TestingCacheLoaders.IdentityLoader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论