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

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

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

Cache.entrySet介绍

暂无

代码示例

代码示例来源: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

@Override
  void perform(MagicKey key, Cache<MagicKey, String> cache) {
   List<Map.Entry<MagicKey, String>> list = cache.entrySet().stream().collect(() -> Collectors.toList());
   assertEquals(1, list.size());
   assertEquals(key, list.get(0).getKey());
  }
}

代码示例来源: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-core

private void testStayLocalIfAllSegmentsPresentLocally(boolean rehashAware) throws Exception {
 Cache<Object, String> cache0 = cache(0, CACHE_NAME);
 ClusterStreamManager clusterStreamManager = replaceWithSpy(cache0);
 IntStream.rangeClosed(0, 499).boxed().forEach(i -> cache0.put(i, i.toString()));
 KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache0, KeyPartitioner.class);
 ConsistentHash ch = cache0.getAdvancedCache().getDistributionManager().getWriteConsistentHash();
 Set<Integer> segmentsCache0 = ch.getSegmentsForOwner(address(0));
 CacheStream<Map.Entry<Object, String>> stream = cache0.entrySet().stream();
 if (!rehashAware) stream = stream.disableRehashAware();
 Map<Object, String> entries = mapFromIterator(stream.filterKeySegments(segmentsCache0).iterator());
 Map<Integer, Set<Map.Entry<Object, String>>> entriesPerSegment = generateEntriesPerSegment(keyPartitioner, entries.entrySet());
 // We should not see keys from other segments, but there may be segments without any keys
 assertTrue(segmentsCache0.containsAll(entriesPerSegment.keySet()));
 verify(clusterStreamManager, never()).awaitCompletion(any(UUID.class), anyLong(), any(TimeUnit.class));
}

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

public void testEntrySetSizeAfterLocalClear() throws Exception {
 cache.put(1, "v1");
 tm().begin();
 try {
   cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear();
   assertEquals(0, cache.entrySet().size());
 } finally {
   tm().commit();
 }
}

代码示例来源: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.server/infinispan-server-testsuite

@Override
@SuppressWarnings("unchecked")
public Object call() throws IOException, ClassNotFoundException {
 Cache<Object, Object> cache = (Cache<Object, Object>) taskContext.getCache().get();
 Map.Entry<Object, Object> entry = cache.entrySet().iterator().next();
 cache.getCacheManager().getCache(CACHE_NAME).put(entry.getKey(), MODIFIED_PREFIX + entry.getValue());
 return null;
}

代码示例来源: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 testDoubleSortedSkip() {
 Cache<Double, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).mapToDouble(value -> value).forEach(i -> cache.put(i, i + "-value"));
 CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
 for (int i = 0; i < range; i++) {
   DoubleSummaryStatistics stats = createStream(entrySet).mapToDouble(toDouble)
      .sorted().skip(i).summaryStatistics();
   assertEquals(range - i, stats.getCount());
   assertEquals((double) i, stats.getMin());
   assertEquals((double) range - 1, stats.getMax());
   assertEquals((double) IntStream.range(i, range).sum(), stats.getSum());
 }
}

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

public void testTxCleanupWithEntrySet() throws Exception {
 tm().begin();
 assertEquals(0, cache.entrySet().size());
 TransactionTable txTable = getTransactionTable(cache);
 assertEquals(1, txTable.getLocalTransactions().size());
 tm().commit();
 assertEquals(0, txTable.getLocalTransactions().size());
}

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

public void testRemoveAllMethodOfEntryCollection() {
 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);
 List<Map.Entry> entryCollection = new ArrayList<>(2);
 entryCollection.add(createMapEntry(key1, value1));
 entryCollection.add(createMapEntry(key3, value3));
 Set<Map.Entry<Object, Object>> entries = cache(0, "replSync").entrySet();
 entries.removeAll(entryCollection);
 assertEquals(1, cache(0, "replSync").size());
}

代码示例来源: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 testEntrySetIsEmptyAfterLocalClear() throws Exception {
 cache.put(1, "v1");
 tm().begin();
 try {
   cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear();
   assertTrue(cache.entrySet().isEmpty());
 } finally {
   tm().commit();
 }
}

代码示例来源: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 testLongSortedLimit() {
 Cache<Long, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 LongStream.range(0, range).forEach(i -> cache.put(i, i + "-value"));
 CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
 for (int i = 1; i < range; i++) {
   LongSummaryStatistics stats = createStream(entrySet).mapToLong(toLong)
      .sorted().limit(i).summaryStatistics();
   assertEquals(i, stats.getCount());
   assertEquals(0, stats.getMin());
   assertEquals(i - 1, stats.getMax());
   assertEquals(IntStream.range(0, i).sum(), stats.getSum());
 }
}

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

@Test
public void simpleTest() {
 Map<Object, String> values = putValuesInCache();
 Cache<MagicKey, String> cache = cache(0, CACHE_NAME);
 Iterator<Map.Entry<MagicKey, String>> iterator = cache.entrySet().iterator();
 Map<MagicKey, String> results = mapFromIterator(iterator);
 assertEquals(values, results);
}

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

@Test( expectedExceptions = AvailabilityException.class)
public void testRetrievalWhenPartitionIsDegraded() {
 Cache<MagicKey, String> cache0 = cache(0);
 cache0.put(new MagicKey(cache(1), cache(2)), "not-local");
 cache0.put(new MagicKey(cache(0), cache(1)), "local");
 splitCluster(new int[]{0, 1}, new int[]{2, 3});
 partition(0).assertDegradedMode();
 try (CloseableIterator iterator = Closeables.iterator(cache(0).entrySet().stream())) {
   iterator.next();
 }
}

代码示例来源: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 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 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());
}

相关文章