@Override public Set<T> getServices() { return this.cache.keySet(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Set getAllKeys() { CloseableIterator<Object> values = getJBossCache().keySet().iterator(); Set output = new HashSet(); while (values.hasNext()) { output.add(values.next()); } return output; }
public void testRemoveIfMethodOfKeyCollection() { 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> keys = cache.keySet(); keys.removeIf(k -> k.equals("2")); assertCacheSize(2); }
public void testClearMethodOfKeyCollection() { 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); Set<Object> keys = cache.keySet(); keys.clear(); assertCacheIsEmpty(); }
/** * Verifies the cache doesn't contain any lock * @param cache */ public static void assertNoLocks(Cache<?,?> cache) { LockManager lm = TestingUtil.extractLockManager(cache); if (lm != null) { for (Object key : cache.keySet()) assert !lm.isLocked(key); } }
private List<CacheXid> getKeys(XidImpl xid) { return storage.keySet().stream() .filter(new XidPredicate(xid)) .collect(CacheCollectors.serializableCollector(Collectors::toList)); }
@Override void perform(MagicKey key, Cache<MagicKey, String> cache) { Iterator iterator = cache.keySet().iterator(); assertTrue(iterator.hasNext()); assertEquals(key, iterator.next()); assertFalse(iterator.hasNext()); } },
public void testClearMethodOfKeyCollection() { 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<Object> keys = cache(0, "replSync").keySet(); keys.clear(); assertEquals(0, cache(0, "replSync").size()); }
public void testKeySetForEachNonSerializable() { assertEquals(0, cache.size()); cache.put("k1", "v1"); List<Object> values = new ArrayList<>(); cache.keySet().forEach(values::add); assertEquals(1, values.size()); assertEquals("k1", values.iterator().next()); }
public void testObjKeySetMax() { 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<Integer> keySet = cache.keySet(); assertEquals(9, createStream(keySet).max(Integer::compare).get().intValue()); }
public void testKeySetAfterExpiryInPut(Method m) throws Exception { Cache<Integer, String> cache = cm.getCache(); Map dataIn = new HashMap(); dataIn.put(1, v(m, 1)); dataIn.put(2, v(m, 2)); final long lifespan = EXPIRATION_TIMEOUT; cache.putAll(dataIn, lifespan, TimeUnit.MILLISECONDS); timeService.advance(lifespan + 100); assertEquals(0, cache.keySet().size()); }
public void testKeySetIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.keySet().isEmpty()); } finally { tm().commit(); } }
public void testForceCommitOnOtherNode() throws Exception { String inDoubt = showInDoubtTransactions(0); assertInDoubtTxCount(inDoubt, 1); assertInDoubtTxCount(showInDoubtTransactions(1), 1); List<Long> ids = getInternalIds(inDoubt); assertEquals(1, ids.size()); assertEquals(0, cache(0, "test").keySet().size()); assertEquals(0, cache(1, "test").keySet().size()); if (log.isTraceEnabled()) log.trace("Before forcing commit!"); String result = invokeForceWithId("forceCommit", 0, ids.get(0)); checkResponse(result, 1); }
public void testTxCleanupWithKeySet() throws Exception { tm().begin(); assertEquals(0, cache.keySet().size()); TransactionTable txTable = getTransactionTable(cache); assertEquals(1, txTable.getLocalTransactions().size()); tm().commit(); assertEquals(0, txTable.getLocalTransactions().size()); }
public void testKeySetWithEvictedEntries() { 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()); Set<Object> keySet = cache.keySet(); for (int i = 0; i < numKeys; i++) { assertTrue("Key: " + i + " was not found!", keySet.contains(i)); } }
public void testKeySetSizeAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertEquals(0, cache.keySet().size()); } finally { tm().commit(); } }
private void printCacheContents() { log.debugf("%d cache managers: %s", getCacheManagers().size(), getCacheManagers()); for (int i = 0; i < getCacheManagers().size(); i++) { Cache<String, String> testCache = manager(i).getCache(TEST_CACHE_NAME); DataContainer<String, String> dataContainer = testCache.getAdvancedCache().getDataContainer(); log.debugf("DC on %s has %d keys: %s", address(i), dataContainer.size(), dataContainer.keySet()); Set<String> keySet = testCache.keySet(); log.debugf("Cache %s has %d keys: %s", address(i), keySet.size(), keySet); } }
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()); }