Search in sources :

Example 1 with EventLostEvent

use of com.hazelcast.map.EventLostEvent 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 EventLostEvent

use of com.hazelcast.map.EventLostEvent in project hazelcast by hazelcast.

the class EventPublisherHelper method createIMapEvent.

public static IMapEvent createIMapEvent(EventData eventData, EventFilter filter, Member member, SerializationService serializationService) {
    String source = eventData.getSource();
    int eventType = eventData.getEventType();
    if (eventType == EventLostEvent.EVENT_TYPE) {
        LocalEntryEventData localEventData = (LocalEntryEventData) eventData;
        int partitionId = localEventData.getPartitionId();
        return new EventLostEvent(source, null, partitionId);
    }
    if (eventType == EntryEventType.CLEAR_ALL.getType() || eventType == EntryEventType.EVICT_ALL.getType()) {
        LocalCacheWideEventData localCacheWideEventData = (LocalCacheWideEventData) eventData;
        int numberOfEntriesAffected = localCacheWideEventData.getNumberOfEntriesAffected();
        return new MapEvent(source, null, eventType, numberOfEntriesAffected);
    }
    LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventData;
    Data dataKey = localEntryEventData.getKeyData();
    Data dataNewValue = localEntryEventData.getValueData();
    Data dataOldValue = localEntryEventData.getOldValueData();
    boolean includeValue = isIncludeValue(filter);
    return new DataAwareEntryEvent(member, eventType, source, dataKey, (includeValue ? dataNewValue : null), (includeValue ? dataOldValue : null), null, serializationService);
}
Also used : LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) MapEvent(com.hazelcast.core.MapEvent) IMapEvent(com.hazelcast.core.IMapEvent) EventLostEvent(com.hazelcast.map.EventLostEvent) Data(com.hazelcast.nio.serialization.Data) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EventData(com.hazelcast.map.impl.event.EventData) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Example 3 with EventLostEvent

use of com.hazelcast.map.EventLostEvent 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(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 all nodes
    int count = 30;
    // expecting one lost event per partition
    final CountDownLatch lossCount = new CountDownLatch(1);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("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) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) 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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with EventLostEvent

use of com.hazelcast.map.EventLostEvent 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 5 with EventLostEvent

use of com.hazelcast.map.EventLostEvent 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)

Aggregations

EventLostEvent (com.hazelcast.map.EventLostEvent)7 EventLostListener (com.hazelcast.map.listener.EventLostListener)5 Test (org.junit.Test)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 QueryCache (com.hazelcast.map.QueryCache)4 SqlPredicate (com.hazelcast.query.SqlPredicate)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Config (com.hazelcast.config.Config)3 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)3 MapConfig (com.hazelcast.config.MapConfig)2 AssertTask (com.hazelcast.test.AssertTask)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 EntryEventType (com.hazelcast.core.EntryEventType)1 IMapEvent (com.hazelcast.core.IMapEvent)1 MapEvent (com.hazelcast.core.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1 EventData (com.hazelcast.map.impl.event.EventData)1