@Test public void putIfAbsent() { HazelcastClient hClient = getHazelcastClient(); IMap<String, String> map = hClient.getMap("putIfAbsent"); String result = map.put("1", "CBDEF"); assertNull(result); assertNull(map.putIfAbsent("2", "C")); assertEquals("C", map.putIfAbsent("2", "D")); }
@Test public void putIfAbsentWithTtl() throws InterruptedException { HazelcastClient hClient = getHazelcastClient(); IMap<String, String> map = hClient.getMap("putIfAbsentWithTtl"); String result = map.put("1", "CBDEF"); assertNull(result); assertNull(map.putIfAbsent("2", "C", 100, TimeUnit.MILLISECONDS)); assertEquals(2, map.size()); assertEquals("C", map.putIfAbsent("2", "D", 100, TimeUnit.MILLISECONDS)); Thread.sleep(100); assertEquals(1, map.size()); }