Search in sources :

Example 1 with EventLostListener

use of com.hazelcast.map.listener.EventLostListener in project hazelcast by hazelcast.

the class ClientQueryCacheEventLostListenerTest method testListenerNotified_onEventLoss.

@Test
public void testListenerNotified_onEventLoss() throws Exception {
    int count = 30;
    String mapName = randomString();
    String queryCacheName = randomString();
    IMap<Integer, Integer> mapNode = node.getMap(mapName);
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Integer> mapClient = client.getMap(mapName);
    setTestSequencer(mapClient, 9);
    // expecting one lost event publication per partition.
    final CountDownLatch lostEventCount = new CountDownLatch(1);
    QueryCache queryCache = mapClient.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            lostEventCount.countDown();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        mapNode.put(i, i);
    }
    assertOpenEventually(lostEventCount);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with EventLostListener

use of com.hazelcast.map.listener.EventLostListener in project hazelcast by hazelcast.

the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    String mapName = randomString();
    String queryCacheName = randomString();
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    mapConfig.setBackupCount(0);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
    setTestSequencer(node, 9);
    setTestSequencer(node2, 9);
    IMap<Integer, Integer> map = getMap(node, mapName);
    node2.getMap(mapName);
    //set test sequencer to subscribers.
    int count = 30;
    final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            queryCache.tryRecover();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    AssertTask task = new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(9, queryCache.size());
        }
    };
    assertTrueEventually(task);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with EventLostListener

use of com.hazelcast.map.listener.EventLostListener in project hazelcast by hazelcast.

the class QueryCacheSimpleStressTest method testStress.

@Test
public void testStress() throws Exception {
    final IMap<Integer, Integer> map = getMap();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < numberOfElementsToPut; i++) {
                map.put(i, i);
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    final QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            queryCache.tryRecover();
        }
    }, true);
    thread.join();
    assertQueryCacheSizeEventually(numberOfElementsToPut, queryCache);
}
Also used : EventLostEvent(com.hazelcast.map.EventLostEvent) EventLostListener(com.hazelcast.map.listener.EventLostListener) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with EventLostListener

use of com.hazelcast.map.listener.EventLostListener in project hazelcast by hazelcast.

the class QueryCacheEventLostListenerTest method testListenerNotified_uponEventLoss.

@Test
public void testListenerNotified_uponEventLoss() {
    String mapName = randomString();
    String queryCacheName = randomString();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    Config config = new Config();
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    mapConfig.setBackupCount(0);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
    setTestSequencer(node, 9);
    setTestSequencer(node2, 9);
    IMap<Integer, Integer> map = getMap(node, mapName);
    node2.getMap(mapName);
    // set test sequencer to all nodes
    int count = 30;
    // expecting one lost event per partition
    final CountDownLatch lossCount = new CountDownLatch(1);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            lossCount.countDown();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertOpenEventually(lossCount);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with EventLostListener

use of com.hazelcast.map.listener.EventLostListener in project hazelcast by hazelcast.

the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    String mapName = randomMapName("map");
    String queryCacheName = randomMapName("cache");
    Config config = getConfig();
    config.setProperty(PARTITION_COUNT.getName(), "1");
    factory.newHazelcastInstance(config);
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    // set test sequencer to subscriber
    int count = 30;
    setTestSequencer(map, 9);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            queryCache.tryRecover();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(9, queryCache.size());
        }
    });
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EventLostEvent (com.hazelcast.map.EventLostEvent)8 EventLostListener (com.hazelcast.map.listener.EventLostListener)8 Test (org.junit.Test)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 QueryCache (com.hazelcast.map.QueryCache)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Config (com.hazelcast.config.Config)5 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)5 AssertTask (com.hazelcast.test.AssertTask)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MapConfig (com.hazelcast.config.MapConfig)3 SqlPredicate (com.hazelcast.query.SqlPredicate)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 IMap (com.hazelcast.map.IMap)1 AbstractQueryCacheTestSupport.getMap (com.hazelcast.map.impl.querycache.AbstractQueryCacheTestSupport.getMap)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 Map (java.util.Map)1