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