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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations