@Test public void testZeroResetsTTL() throws InterruptedException { Config cfg = new Config(); MapConfig mc = cfg.getMapConfig("testZeroResetsTTL"); int ttl = 5; mc.setTimeToLiveSeconds(ttl); TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1); HazelcastInstance instance = factory.newHazelcastInstance(cfg); IMap<Object, Object> map = instance.getMap("testZeroResetsTTL"); final CountDownLatch latch = new CountDownLatch(1); map.addEntryListener( new EntryAdapter<Object, Object>() { public void entryEvicted(EntryEvent event) { latch.countDown(); } }, false); map.put(1, 1); map.put(2, 2); map.put(1, 2, 0, TimeUnit.SECONDS); latch.await(10, TimeUnit.SECONDS); assertNull(map.get(2)); assertEquals(2, map.get(1)); }
@Test public void testMapRecordEviction() throws InterruptedException { int size = 100000; Config cfg = new Config(); MapConfig mc = cfg.getMapConfig("testMapRecordEviction"); mc.setTimeToLiveSeconds(1); final CountDownLatch latch = new CountDownLatch(size); mc.addEntryListenerConfig( new EntryListenerConfig() .setImplementation( new EntryAdapter() { public void entryEvicted(EntryEvent event) { latch.countDown(); } }) .setLocal(true)); TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2); final HazelcastInstance[] instances = factory.newInstances(cfg); IMap map = instances[0].getMap("testMapRecordEviction"); for (int i = 0; i < size; i++) { map.put(i, i); } assertTrue(latch.await(5, TimeUnit.MINUTES)); assertEquals(0, map.size()); }