@Test public void testSimpleRemoveAll() throws Exception { Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", newCacheConfigurationBuilder(Number.class, CharSequence.class, heap(10))); testCache.put(1, "one"); testCache.put(2, "two"); testCache.put(3, "three"); testCache.removeAll(new HashSet<Number>(Arrays.asList(1, 2))); assertThat(testCache.get(1), is(nullValue())); assertThat(testCache.get(2), is(nullValue())); assertThat(testCache.get(3), is(notNullValue())); }
testCache.removeAll(new HashSet<Number>(Arrays.asList(1, 2, 3, 4))); fail("expected CacheWritingException"); } catch (BulkCacheWritingException ex) {
@Test public void testBulkOps() { TestCacheLoaderWriter loaderWriter = new TestCacheLoaderWriter(); CacheConfiguration<Long, String> cacheConfiguration = getCacheConfiguration(loaderWriter); CacheManager cacheManager = CacheManagerBuilder .newCacheManagerBuilder() .with(cluster(CLUSTER_URI).autoCreate()) .withCache("cache-1", cacheConfiguration) .build(true); Cache<Long, String> cache = cacheManager.getCache("cache-1", Long.class, String.class); Map<Long, String> mappings = new HashMap<>(); for (int i = 1; i <= 5; i++) { mappings.put((long) i, "" + i); } cache.putAll(mappings); assertThat(loaderWriter.storeMap.keySet(), containsInAnyOrder(mappings.keySet().toArray())); cache.clear(); Map<Long, String> loadedData = cache.getAll(mappings.keySet()); assertThat(mappings.keySet(), containsInAnyOrder(loadedData.keySet().toArray())); cache.removeAll(mappings.keySet()); assertThat(loaderWriter.storeMap.isEmpty(), is(true)); }
myCache.removeAll(fewKeysSet); fail(); } catch (BulkCacheWritingException bcwe) {
assertThat(all.get(3L), is("three")); cache2.removeAll(keySet);
myCache.removeAll(fewKeysSet);
myCache.removeAll(fewKeysSet); for (int i = 0; i < 3; i++) { if (i == 0 || i == 2) {
@Test public void removeAllKeys() { cache.put(1, "a"); cache.put(2, "b"); changesOf(0, 0, 2, 0); cache.removeAll(asSet(1, 2, 3)); changesOf(0, 0, 0, 2); }
@Test public void removeAllKeys() { cache.put(1, "a"); cache.put(2, "b"); changesOf(0, 0, 2, 0); cache.removeAll(asSet(1, 2, 3)); changesOf(0, 0, 0, 2); }
testCache.removeAll(keys);
private void innerClear() { cache.get(1); // one miss cache.getAll(asSet(1, 2, 3)); // 3 misses cache.put(1, "a"); // one put cache.put(1, "b"); // one put and update cache.putAll(Collections.singletonMap(2, "b")); // 1 put cache.get(1); // one hit cache.remove(1); // one remove cache.removeAll(asSet(2)); // one remove changesOf(1, 4, 3, 2); cacheStatistics.clear(); changesOf(-1, -4, -3, -2); }
private void innerClear() { cache.get(1); // one miss cache.getAll(asSet(1, 2, 3)); // 3 misses cache.put(1, "a"); // one put cache.put(1, "b"); // one put and update cache.putAll(Collections.singletonMap(2, "b")); // 1 put cache.get(1); // one hit cache.remove(1); // one remove cache.removeAll(asSet(2)); // one remove changesOf(1, 4, 3, 2); tierStatistics.clear(); changesOf(-1, -4, -3, -2); }
@Test public void testRemoveAll_without_cache_writer() throws Exception { CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, heap(100)); CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build(); CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder(); CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true); Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class); for (int i = 0; i < 3; i++) { myCache.put("key" + i, "value" + i); } Set<String> fewKeysSet = new HashSet<String>() { { add("key0"); add("key2"); } }; // the call to removeAll myCache.removeAll(fewKeysSet); for (int i = 0; i < 3; i++) { if (i == 0 || i == 2) { assertThat(myCache.get("key" + i), is(nullValue())); } else { assertThat(myCache.get("key" + i), is("value" + i)); } } }
@Override public void evict(String...keys) { this.cache.removeAll(Arrays.stream(keys).collect(Collectors.toSet())); }
private void flush(Set<Sha3Hash> keys) { pendingPool.removeAll(keys); pendingKeys.removeAll(keys); log.debug("flushSize={} remainPendingSize={}", keys.size(), pendingKeys.size()); }