use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method testZeroResetsTTL.
@Test
public void testZeroResetsTTL() throws Exception {
MapConfig mapConfig = newMapConfig("testZeroResetsTTL").setTimeToLiveSeconds(5);
Config config = getConfig().addMapConfig(mapConfig);
HazelcastInstance instance = createHazelcastInstance(config);
final 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, SECONDS);
latch.await(10, SECONDS);
assertTrueEventually(() -> {
assertNull(map.get(2));
assertEquals(2, map.get(1));
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method testMapRecordEviction.
@Test(timeout = 5 * 60 * 1000)
public void testMapRecordEviction() {
String mapName = randomMapName();
final int size = 100;
final AtomicInteger entryEvictedEventCount = new AtomicInteger(0);
EntryListenerConfig entryListenerConfig = new EntryListenerConfig().setLocal(true).setImplementation(new EntryAdapter() {
public void entryExpired(EntryEvent event) {
entryEvictedEventCount.incrementAndGet();
}
});
MapConfig mapConfig = newMapConfig(mapName).setTimeToLiveSeconds(1).addEntryListenerConfig(entryListenerConfig);
Config config = getConfig().addMapConfig(mapConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Integer> map = instance.getMap(mapName);
for (int i = 0; i < size; i++) {
map.put(i, i);
}
// wait until eviction is complete
assertSizeEventually(0, map);
assertTrueEventually(() -> assertEquals(size, entryEvictedEventCount.get()));
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method testMapPutTTLWithListener.
/**
* Background task {@link com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask}
* should sweep expired records eventually.
*/
@Test
@Category(NightlyTest.class)
public void testMapPutTTLWithListener() {
int putCount = 100;
IMap<Integer, Integer> map = createSimpleMap();
final CountDownLatch latch = new CountDownLatch(putCount);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryExpired(final EntryEvent event) {
latch.countDown();
}
}, true);
int ttl = (int) (Math.random() * 5000);
for (int j = 0; j < putCount; j++) {
map.put(j, j, ttl, TimeUnit.MILLISECONDS);
}
// wait until eviction is complete
assertOpenEventually(latch, 100);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ListenerTest method testConfigListenerRegistration.
@Test
public void testConfigListenerRegistration() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
String name = randomString();
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(name);
EntryListenerConfig entryListenerConfig = new EntryListenerConfig();
entryListenerConfig.setImplementation(new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch.countDown();
}
});
mapConfig.addEntryListenerConfig(entryListenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Object, Object> map = instance.getMap(name);
map.put(1, 1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.
@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() {
final int size = 10000;
TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 0);
config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
MapConfig mapConfig = config.getMapConfig("default");
EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
evictionConfig.setSize(size);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap("default");
final CountDownLatch countDownLatch = new CountDownLatch(size);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryEvicted(EntryEvent event) {
countDownLatch.countDown();
}
}, false);
for (int i = 0; i < size * 2; i++) {
// trigger eviction
if (i == (size * 2) - 1 || i == size) {
sleepMillis(1001);
}
map.put(i, new Employee("joe", i, true, 100.00));
}
assertEquals(testMapStore.getStore().size(), size * 2);
assertOpenEventually(countDownLatch);
final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
assertTrue(msgFailure, map.size() > size / 2);
assertTrue(msgFailure, map.size() <= size);
assertEquals(testMapStore.getStore().size(), size * 2);
}
Aggregations