@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")); }
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)); }
List<Address> cacheMembers = cacheTopology.getActualMembers(); Map<Address, ServerAddress> serverEndpoints = new HashMap<>(); addressCache.forEach(serverEndpoints::put);
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()); }