@Test public void values() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); MultiMap<String, String> multiMap = hClient.getMultiMap("entrySet"); Map<String, List<String>> valueKeyListMap = new HashMap<String, List<String>>(); int count = 100; for (int i = 0; i < count; i++) { for (int j = 0; j <= i; j++) { String key = String.valueOf(i); String value = String.valueOf(j); multiMap.put(key, value); if (valueKeyListMap.get(value) == null) { valueKeyListMap.put(value, new ArrayList<String>()); } valueKeyListMap.get(value).add(key); } } assertEquals(count * (count + 1) / 2, multiMap.size()); Collection<String> collection = multiMap.values(); assertEquals(count * (count + 1) / 2, collection.size()); Iterator<String> iterator = collection.iterator(); System.out.println(iterator.getClass()); for (; iterator.hasNext(); ) { String value = iterator.next(); assertNotNull(valueKeyListMap.get(value).remove(0)); if (valueKeyListMap.get(value).size() == 0) { valueKeyListMap.remove(value); } } assertTrue(valueKeyListMap.isEmpty()); }
@Test public void testMultiMapValues() { HazelcastClient hClient = getHazelcastClient(); MultiMap<String, String> map = hClient.getMultiMap("testMultiMapValues"); map.put("Hello", "World"); map.put("Hello", "Europe"); map.put("Hello", "America"); map.put("Hello", "Asia"); map.put("Hello", "Africa"); map.put("Hello", "Antarctica"); map.put("Hello", "Australia"); Collection<String> values = map.values(); assertEquals(7, values.size()); }
@Test public void testKeyValues() { final int maxKeys = 31; final int maxValues = 3; final MultiMap mm = client.getMultiMap(randomString()); Set expected = new TreeSet(); for (int key = 0; key < maxKeys; key++) { for (int val = 0; val < maxValues; val++) { mm.put(key, val); expected.add(val); } } Set resultSet = new TreeSet(mm.values()); assertEquals(expected, resultSet); }
@Test public void testValues_whenEmptyCollection() { final MultiMap mm = client.getMultiMap(randomString()); assertEquals(Collections.EMPTY_LIST, mm.values()); }
@Override public Collection<V> values() { return delegate.values(); }