org.infinispan.Cache.size()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.infinispan.Cache.size()方法的一些代码示例,展示了Cache.size()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.size()方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:size

Cache.size介绍

暂无

代码示例

代码示例来源:origin: org.infinispan/infinispan-core

private void testIntOperation(Supplier<Integer> intSupplier, Cache<Integer, String> cache) {
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 assertEquals((range - 1) * (range / 2), intSupplier.get().intValue());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testEntrySetForEachNonSerializable() {
 assertEquals(0, cache.size());
 cache.put("k1", "v1");
 List<Object> values = new ArrayList<>();
 cache.entrySet().forEach(values::add);
 assertEquals(1, values.size());
 Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) values.iterator().next();
 assertEquals("k1", entry.getKey());
 assertEquals("v1", entry.getValue());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testClearMethodOfEntryCollection() {
 final String key1 = "1", value1 = "one", key2 = "2", value2 = "two", key3 = "3", value3 = "three";
 Map<String, String> m = new HashMap<>();
 m.put(key1, value1);
 m.put(key2, value2);
 m.put(key3, value3);
 cache(0, "replSync").putAll(m);
 Set<Map.Entry<Object, Object>> entries = cache(0, "replSync").entrySet();
 entries.clear();
 assertEquals(0, cache(0, "replSync").size());
}

代码示例来源:origin: org.infinispan/infinispan-cachestore-remote

RemoteCache<String, String> targetRemoteCache = targetCluster.getRemoteCache(CACHE_NAME);
IntStream.rangeClosed(1, INITIAL_NUM_ENTRIES).boxed().map(String::valueOf)
   .forEach(s -> sourceRemoteCache.put(s, s, 10, TimeUnit.MINUTES, 30, TimeUnit.MINUTES));
assertEquals(INITIAL_NUM_ENTRIES, storeWrites(sourceCluster));
assertEquals("4", targetRemoteCache.get("4"));
targetRemoteCache.remove("1");
targetRemoteCache.put("new key", "new value", 10, TimeUnit.MINUTES, 30, TimeUnit.MINUTES);
assertEquals(INITIAL_NUM_ENTRIES - 1, storeSize(sourceCluster));
assertEquals(INITIAL_NUM_ENTRIES + 2, storeWrites(sourceCluster));
assertEquals(INITIAL_NUM_ENTRIES - 1, migrated);
assertEquals(sourceCluster.getEmbeddedCache(CACHE_NAME).size(), targetCluster.getEmbeddedCache(CACHE_NAME).size());

代码示例来源:origin: org.infinispan/infinispan-core

public void testLoadEntrySet() {
 int numberOfEntries = 10;
 ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
 createCacheStoreConfig(cb.persistence(), true);
 cacheManager.defineConfiguration("testLoadKeySet", cb.build());
 Cache<String, Object> cache = cacheManager.getCache("testLoadKeySet");
 Map<String, Object> entriesMap = IntStream.range(0, numberOfEntries).boxed()
    .collect(Collectors.toMap(Object::toString, i -> wrap(i.toString(), "Val"+i)));
 cache.putAll(entriesMap);
 cache.stop();
 cache.start();
 CacheSet<Map.Entry<String, Object>> set = cache.entrySet();
 assertEquals(numberOfEntries, cache.size());
 assertEquals(numberOfEntries, set.size());
 set.forEach(e -> assertEquals(entriesMap.get(e.getKey()), e.getValue()));
}

代码示例来源:origin: org.infinispan/infinispan-core

private void assertCacheSize(int expectedSize) {
 assertEquals(expectedSize, cache.size());
 assertEquals(expectedSize, cache.keySet().size());
 assertEquals(expectedSize, cache.values().size());
 assertEquals(expectedSize, cache.entrySet().size());
 boolean isEmpty = expectedSize == 0;
 assertEquals(isEmpty, cache.isEmpty());
 assertEquals(isEmpty, cache.keySet().isEmpty());
 assertEquals(isEmpty, cache.values().isEmpty());
 assertEquals(isEmpty, cache.entrySet().isEmpty());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjCollect() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 List<Map.Entry<Integer, String>> list = createStream(entrySet).collect(ArrayList::new,
    ArrayList::add, ArrayList::addAll);
 assertEquals(cache.size(), list.size());
 list.parallelStream().forEach(e -> assertEquals(cache.get(e.getKey()), e.getValue()));
}

代码示例来源:origin: org.infinispan/infinispan-core

private void testLongOperation(Supplier<Long> longSupplier, Cache<Long, String> cache) {
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 assertEquals((range - 1) * (range / 2), longSupplier.get().longValue());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testReloadWithEviction() {
 int numberOfEntries = 10;
 ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
 createCacheStoreConfig(cb.persistence(), false).memory().size(numberOfEntries/2).evictionType(EvictionType.COUNT);
 cacheManager.defineConfiguration("testReload", cb.build());
 Cache<String, Object> cache = cacheManager.getCache("testReload");
 Map<String, Object> entriesMap = IntStream.range(0, numberOfEntries).boxed()
    .collect(Collectors.toMap(Object::toString, i -> wrap(i.toString(), "Val"+i)));
 cache.putAll(entriesMap);
 assertEquals(numberOfEntries, cache.size());
 entriesMap.forEach((k, v) -> assertEquals(v, cache.get(k)));
 cache.stop();
 cache.start();
 assertEquals(numberOfEntries, cache.size());
 entriesMap.forEach((k, v) -> assertEquals(v, cache.get(k)));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjMax() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 assertEquals(Integer.valueOf(9),
    createStream(entrySet).max((e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).get().getKey());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testLongCollect() {
 Cache<Long, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
 HashSet<Long> set = createStream(entrySet).mapToLong(toLong).collect(HashSet::new, Set::add, Set::addAll);
 assertEquals(10, set.size());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPutAllBatch() throws Exception {
 int numberOfEntries = 100;
 String cacheName = "testPutAllBatch";
 ConfigurationBuilder cb = new ConfigurationBuilder();
 cb.read(cacheManager.getDefaultCacheConfiguration());
 createCacheStoreConfig(cb.persistence(), false);
 cacheManager.defineConfiguration(cacheName, cb.build());
 Cache<String, Object> cache = cacheManager.getCache(cacheName);
 Map<String, Object> entriesMap = IntStream.range(0, numberOfEntries).boxed()
    .collect(Collectors.toMap(Object::toString, i -> wrap(i.toString(), "Val"+i)));
 cache.putAll(entriesMap);
 assertEquals(numberOfEntries, cache.size());
 CacheLoader cl = TestingUtil.getCacheLoader(cache);
 if (cl != null)
   IntStream.range(0, numberOfEntries).forEach(i -> assertNotNull(cl.load(Integer.toString(i))));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjReduce3() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 // This isn't the best usage of this, but should be a usable example
 Integer result = createStream(entrySet).reduce(0, (e1, e2) -> e1 + e2.getKey(), (i1, i2) -> i1 + i2);
 assertEquals((range - 1) * (range / 2), result.intValue());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testLongMax() {
 Cache<Long, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
 assertEquals(9, createStream(entrySet).mapToLong(toLong).max().getAsLong());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjMin() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 assertEquals(Integer.valueOf(0),
    createStream(entrySet).min((e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).get().getKey());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testLongMin() {
 Cache<Long, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
 assertEquals(0, createStream(entrySet).mapToLong(toLong).min().getAsLong());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjFindFirst() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 assertEquals(0, createStream(entrySet).sorted(
    (e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).findFirst().get().getKey().intValue());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testLongAverage() {
 Cache<Long, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
 assertEquals(4.5, createStream(entrySet).mapToLong(toLong).average().getAsDouble());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testObjFlatMapIterator() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 Iterator<String> iterator = createStream(entrySet).flatMap(e -> Arrays.stream(e.getValue().split("a"))).iterator();
 List<String> list = new ArrayList<>(range * 2);
 iterator.forEachRemaining(list::add);
 assertEquals(range * 2, list.size());
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testEntrySetIteratorRemoveInExplicitTx() throws Exception {
 assertEquals(0, cache.size());
 cache.put("k1", "v1");
 TransactionManager tm = TestingUtil.getTransactionManager(cache);
 withTx(tm, () -> {
   try (CloseableIterator<Entry<Object, Object>> entryIterator = cache.entrySet().iterator()) {
    entryIterator.next();
    entryIterator.remove();
    assertEquals(0, cache.size());
   }
   tm.setRollbackOnly();
   return null;
 });
}

相关文章