Search in sources :

Example 6 with EventLostEvent

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

the class InternalQueryCacheListenerAdapter method onEvent.

@Override
public void onEvent(IMapEvent event) {
    EntryEventType eventType = event.getEventType();
    if (eventType != null) {
        callListener(event, eventType.getType());
        return;
    }
    if (event instanceof EventLostEvent) {
        EventLostEvent eventLostEvent = (EventLostEvent) event;
        callListener(eventLostEvent, EventLostEvent.EVENT_TYPE);
        return;
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) EventLostEvent(com.hazelcast.map.EventLostEvent)

Example 7 with EventLostEvent

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

the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    String mapName = randomMapName("map");
    String queryCacheName = randomMapName("cache");
    Config config = new Config();
    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, 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);
    }
    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) 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) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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