Search in sources :

Example 6 with EntryListenerConfig

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);
}
Also used : EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with EntryListenerConfig

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig)

Example 8 with EntryListenerConfig

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) AssertTask(com.hazelcast.test.AssertTask) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with EntryListenerConfig

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());
}
Also used : EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with EntryListenerConfig

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);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)17 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 Config (com.hazelcast.config.Config)5 MapConfig (com.hazelcast.config.MapConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 MultiMapConfig (com.hazelcast.config.MultiMapConfig)4 EntryAdapter (com.hazelcast.core.EntryAdapter)4 EntryEvent (com.hazelcast.core.EntryEvent)4 MapPartitionLostListenerConfig (com.hazelcast.config.MapPartitionLostListenerConfig)3 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)3 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 AssertTask (com.hazelcast.test.AssertTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapAttributeConfig (com.hazelcast.config.MapAttributeConfig)1