use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.
the class ListenerTest method hazelcastAwareEntryListener_whenConfiguredByProvidingInstance_thenInjectHazelcastInstance.
@Test
public void hazelcastAwareEntryListener_whenConfiguredByProvidingInstance_thenInjectHazelcastInstance() throws InterruptedException {
EntryListenerConfig listenerConfig = new EntryListenerConfig(new PingPongListener(), false, true);
hazelcastAwareEntryListener_injectHazelcastInstance(listenerConfig);
}
use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.
the class ListenerTest method hazelcastAwareEntryListener_injectHazelcastInstance.
private void hazelcastAwareEntryListener_injectHazelcastInstance(EntryListenerConfig listenerConfig) {
String pingMapName = randomMapName();
Config config = getConfig();
config.getMapConfig(pingMapName).getEntryListenerConfigs().add(listenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, String> pingMap = instance.getMap(pingMapName);
String pongMapName = randomMapName();
pingMap.put(0, pongMapName);
IMap<Integer, String> outputMap = instance.getMap(pongMapName);
assertSizeEventually(1, outputMap);
}
use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.
the class ReplicatedMapListenerTest method testRegisterListenerViaConfiguration.
@Test
public void testRegisterListenerViaConfiguration() throws Exception {
String mapName = randomMapName();
Config config = new Config();
ReplicatedMapConfig replicatedMapConfig = config.getReplicatedMapConfig(mapName);
EntryListenerConfig listenerConfig = new EntryListenerConfig();
final EventCountingListener listener = new EventCountingListener();
listenerConfig.setImplementation(listener);
replicatedMapConfig.addEntryListenerConfig(listenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
ReplicatedMap<Object, Object> replicatedMap = instance.getReplicatedMap(mapName);
replicatedMap.put(3, 3);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.addCount.get());
assertEquals(3, listener.keys.peek());
}
}, 10);
}
use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.
the class RestTest method testMapTtl.
// issue #1783
@Test
public void testMapTtl() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
EntryListenerConfig listenerConfig = new EntryListenerConfig().setImplementation(new EntryAdapter() {
@Override
public void entryEvicted(EntryEvent event) {
latch.countDown();
}
});
String name = randomMapName();
config.getMapConfig(name).setTimeToLiveSeconds(3).addEntryListenerConfig(listenerConfig);
String key = "key";
communicator.mapPut(name, key, "value");
assertOpenEventually(latch);
String value = communicator.mapGet(name, key);
assertTrue(value.isEmpty());
}
use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.
the class EvictionTest method testMapRecordEviction.
@Test
public void testMapRecordEviction() throws InterruptedException {
final String mapName = randomMapName();
final int size = 100;
final AtomicInteger entryEvictedEventCount = new AtomicInteger(0);
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.setTimeToLiveSeconds(1);
mapConfig.addEntryListenerConfig(new EntryListenerConfig().setImplementation(new EntryAdapter() {
public void entryEvicted(EntryEvent event) {
entryEvictedEventCount.incrementAndGet();
}
}).setLocal(true));
HazelcastInstance instance = createHazelcastInstance(config);
final 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, 300);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(size, entryEvictedEventCount.get());
}
}, 300);
}
Aggregations