@Test public void iterateOverMapEntries() { HazelcastClient hClient = getHazelcastClient(); IMap<String, String> map = hClient.getMap("iterateOverMapEntries"); map.put("1", "A"); map.put("2", "B"); map.put("3", "C"); Set<Entry<String, String>> entrySet = map.entrySet(); assertEquals(3, entrySet.size()); Set<String> keySet = map.keySet(); for (Entry<String, String> entry : entrySet) { assertTrue(keySet.contains(entry.getKey())); assertEquals(entry.getValue(), map.get(entry.getKey())); } Iterator<Entry<String, String>> it = entrySet.iterator(); for (String key : keySet) { MapEntry mapEntry = map.getMapEntry(key); assertEquals(1, mapEntry.getHits()); } while (it.hasNext()) { it.next(); it.remove(); } assertTrue(map.isEmpty()); }
@Test(timeout = 20000) public void test_updateAttribute() throws Exception { IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME); CookieStore cookieStore = new BasicCookieStore(); executeRequest("write", serverPort1, cookieStore); executeRequest("update", serverPort2, cookieStore); assertEquals("value-updated", executeRequest("read", serverPort1, cookieStore)); String newSessionId = map.keySet().iterator().next(); SessionState sessionState = (SessionState) map.get(newSessionId); SerializationService ss = getNode(hz).getSerializationService(); assertSizeEventually(1, map); assertSizeEventually(1, sessionState.getAttributes()); }
@Test public void testKeySetValues() throws Exception { final String mapName = randomString(); IMap map = client.getMap(mapName); map.put("key1", "value1"); final TransactionContext context = client.newTransactionContext(); context.beginTransaction(); final TransactionalMap<Object, Object> txMap = context.getMap(mapName); assertNull(txMap.put("key2", "value2")); assertEquals(2, txMap.size()); assertEquals(2, txMap.keySet().size()); assertEquals(2, txMap.values().size()); context.commitTransaction(); assertEquals(2, map.size()); assertEquals(2, map.keySet().size()); assertEquals(2, map.values().size()); }
@Test(timeout = 120000) public void testIssue1019() throws InterruptedException { final String keyWithNullValue = "keyWithNullValue"; TestEventBasedMapStore testMapStore = new TestEventBasedMapStore() { @Override public Set loadAllKeys() { Set keys = new HashSet(super.loadAllKeys()); // Include an extra key that will *not* be returned by loadAll(). keys.add(keyWithNullValue); return keys; } }; Map mapForStore = new HashMap(); mapForStore.put("key1", 17); mapForStore.put("key2", 37); mapForStore.put("key3", 47); testMapStore.getStore().putAll(mapForStore); Config config = newConfig(testMapStore, 0); HazelcastInstance instance = createHazelcastInstance(config); IMap map = instance.getMap("default"); Set expected = map.keySet(); Set actual = mapForStore.keySet(); assertEquals(expected, actual); List actualList = new ArrayList(map.values()); List expectedList = new ArrayList(mapForStore.values()); Collections.sort(actualList); Collections.sort(expectedList); assertEquals(expectedList, actualList); assertEquals(map.entrySet(), mapForStore.entrySet()); assertFalse(map.containsKey(keyWithNullValue)); assertNull(map.get(keyWithNullValue)); }
@Test public void testMapPagingKeySet() { final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); final ClientConfig clientConfig = new ClientConfig(); final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); final IMap<Integer, Integer> map = client.getMap("map"); final int size = 50; final int pageSize = 5; for (int i = 0; i < size; i++) { map.put(size - i, i); } final PagingPredicate predicate = new PagingPredicate(pageSize); predicate.nextPage(); final Set<Integer> values = map.keySet(predicate); assertEquals(pageSize, values.size()); }