int totalCount() { int sum = 0; for (Integer i : categories.values()) { sum += i; } return sum; }
public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(SpringBootApp.class, args); EmbeddedCacheManager cacheManager = ctx.getBean(EmbeddedCacheManager.class); Cache<Long, String> cache = cacheManager.getCache(CACHE_NAME); cache.put(System.currentTimeMillis(), "Infinispan"); logger.info("Keys from Cache: {}", cache.keySet()); logger.info("Values from Cache: {}", cache.values()); }
private List<String> copyValues(Cache<?, String> cache) { return new ArrayList<>(cache.values()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Set getAllValues() { CloseableIterator<Object> values = getJBossCache().values().iterator(); Set output = new HashSet(); while (values.hasNext()) { output.add(values.next()); } return output; }
public void testRemoveIfMethodOfValuesCollection() { 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.putAll(m); Collection<Object> values = cache.values(); values.removeIf(v -> ((String) v).startsWith("t")); assertCacheSize(1); }
public void testClearMethodOfValuesCollection() { 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.putAll(m); Collection<Object> values = cache.values(); values.clear(); assertCacheIsEmpty(); }
public void testRemoveAllMethodOfValuesCollection() { 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<String> valueCollection = new ArrayList<>(2); valueCollection.add(value1); valueCollection.add(value2); Collection<Object> values = cache(0, "replSync").values(); values.removeAll(valueCollection); assertEquals(1, cache(0, "replSync").size()); }
public void testObjValuesMax() { 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()); CacheCollection<String> keySet = cache.values(); assertEquals("9-value", createStream(keySet).max((e1, e2) -> Integer.compare( Integer.valueOf(e1.substring(0, 1)), Integer.valueOf(e2.substring(0, 1)))).get()); }
public void testValuesForEachNonSerializable() { assertEquals(0, cache.size()); cache.put("k1", "v1"); List<Object> values = new ArrayList<>(); cache.values().forEach(values::add); assertEquals(1, values.size()); assertEquals("v1", values.iterator().next()); } }
public void testClearMethodOfValuesCollection() { 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); Collection<Object> values = cache(0, "replSync").values(); values.clear(); assertEquals(0, cache(0, "replSync").size()); }
public void testValuesIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.values().isEmpty()); } finally { tm().commit(); } }
public void testTxCleanupWithValues() throws Exception { tm().begin(); assertEquals(0, cache.values().size()); TransactionTable txTable = getTransactionTable(cache); assertEquals(1, txTable.getLocalTransactions().size()); tm().commit(); assertEquals(0, txTable.getLocalTransactions().size()); }
public void testValuesAfterClearInBranchedTransaction() throws Exception { cache.put(1, "v1"); tm().begin(); try { assertEquals("v1", cache.get(1)); //clear is non transactional cache.clear(); Collection<Object> values = cache.values(); assertEquals(1, values.size()); assertTrue(values.contains("v1")); } finally { safeCommit(false); } }
public void testValuesAfterClearInBranchedTransactionOnWrite() throws Exception { cache.put(1, "v1"); tm().begin(); try { assertEquals("v1", cache.put(1, "v2")); //clear is non transactional cache.clear(); Collection<Object> values = cache.values(); assertEquals(1, values.size()); assertTrue(values.contains("v2")); } finally { safeCommit(true); } }
public void testValuesSizeAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertEquals(0, cache.values().size()); } finally { tm().commit(); } } }
public void testObjValuesForEachCacheInjected() { Cache<Integer, String> cache = getCache(0); int cacheOffset = populateNextForEachStructure(cache); int atomicOffset = populateNextForEachStructure(new AtomicInteger()); try { testIntOperation(() -> { createStream(cache.values()).forEach(new ForEachInjected<>(cacheOffset, atomicOffset, e -> Integer.valueOf(e.substring(0, 1)))); return ((AtomicInteger) getForEachObject(atomicOffset)).get(); }, cache); } finally { clearForEachObject(cacheOffset); clearForEachObject(atomicOffset); } }
public void testValuesWithEvictedEntries() { final int numKeys = 300; for (int i = 0; i < numKeys; i++) { cache.put(i, i); } assertFalse("Data Container should not have all keys", numKeys == cache.getAdvancedCache().getDataContainer().size()); Collection<Object> values = cache.values(); for (int i = 0; i < numKeys; i++) { assertTrue("Value: " + i + " was not found!", values.contains(i)); } }
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()); }
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()); }