@Test public void removeRecordWithEntryProcessor() { final int ENTRY_COUNT = 10; CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(node1); CacheManager cacheManager = cachingProvider.getCacheManager(); CompleteConfiguration<Integer, String> cacheConfig = new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class); ICache<Integer, String> cache = cacheManager.createCache("MyCache", cacheConfig).unwrap(ICache.class); for (int i = 0; i < ENTRY_COUNT; i++) { cache.put(i * 1000, "Value-" + (i * 1000)); } assertEquals(ENTRY_COUNT, cache.size()); for (int i = 0; i < ENTRY_COUNT; i++) { if (i % 2 == 0) { cache.invoke(i * 1000, new RemoveRecordEntryProcessor()); } } assertEquals(ENTRY_COUNT / 2, cache.size()); }
public static void main(String[] args) { init(); try { ICache<Integer, Integer> cache = createCache("MyCacheForIteratorUsage"); for (int i = 0; i < SIZE; i++) { cache.put(i, i * i); } Iterator<Cache.Entry<Integer, Integer>> iter = cache.iterator(); while (iter.hasNext()) { Cache.Entry<Integer, Integer> e = iter.next(); int key = e.getKey(); int value = e.getValue(); System.out.println("Key: " + key + ", Value: " + value); } cache.destroy(); } catch (Throwable t) { t.printStackTrace(); } finally { destroy(); } }
@Test public void testPutRemoveGetShouldReturnNullWhenQuorumSizeMet() { cache1.put(123, "foo"); cache1.remove(123); assertNull(cache2.get(123)); }
@Test public void testPutGetWhenQuorumSizeMet() { cache1.put(123, "foo"); assertEquals("foo", cache2.get(123)); }
@Test(expected = QuorumException.class) public void testPutOperationThrowsExceptionWhenQuorumSizeNotMet() throws Exception { cache4.put(1, ""); }
@Test public void testPutOperationSuccessfulWhenQuorumSizeMet() throws Exception { cache1.put(1, ""); }
@Override public void put(K key, T val) { cache.put(key, val); }