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

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

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

Cache.forEach介绍

暂无

代码示例

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

@Test
public void testForEach() {
 cache.put("A", "B");
 cache.put("C", "D");
 List<String> values = new ArrayList<>();
 BiConsumer<? super Object, ? super Object> collectKeyValues = (k, v) -> values.add("hello_" + k.toString() + v.toString());
 cache.forEach(collectKeyValues);
 assertEquals(2, values.size());
 //iteration order is not guaranteed, checking just that value is present
 assertTrue(values.contains("hello_AB"));
 assertTrue(values.contains("hello_CD"));
}

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

public void testForEach() {
 cache.put("A", "B");
 cache.put("C", "D");
 List<String> values = new ArrayList<>();
 BiConsumer<? super Object, ? super Object> collectKeyValues = (k, v) -> values.add("hello_" + k.toString() + v.toString());
 cache.forEach(collectKeyValues);
 assertEquals(2, values.size());
 assertEquals("hello_AB", values.get(0));
 assertEquals("hello_CD", values.get(1));
}

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

List<Address> cacheMembers = cacheTopology.getActualMembers();
Map<Address, ServerAddress> serverEndpoints = new HashMap<>();
addressCache.forEach(serverEndpoints::put);

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

public void testKeySegmentFilter() {
 Cache<Integer, String> cache = getCache(0);
 int range = 12;
 // 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();
 // Take the first half of the segments
 int segments = cache.getCacheConfiguration().clustering().hash().numSegments() / 2;
 AtomicInteger realCount = new AtomicInteger();
 KeyPartitioner keyPartitioner = cache.getAdvancedCache().getComponentRegistry().getComponent(KeyPartitioner.class);
 cache.forEach((k, v) -> {
   if (segments >= keyPartitioner.getSegment(k)) {
    realCount.incrementAndGet();
   }
 });
 assertEquals(realCount.get(), createStream(entrySet).filterKeySegments(
    IntStream.range(0, segments).boxed().collect(Collectors.toSet())).count());
}

相关文章