use of com.hazelcast.map.QueryCache 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.QueryCache 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.QueryCache in project hazelcast by hazelcast.
the class QueryCacheMemoryLeakTest method removes_user_listener_upon_query_cache_destroy.
@Test
public void removes_user_listener_upon_query_cache_destroy() {
String name = "mapA";
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = getConfig();
final HazelcastInstance node1 = factory.newHazelcastInstance(config);
final HazelcastInstance node2 = factory.newHazelcastInstance(config);
assertClusterSizeEventually(2, node1, node2);
final IMap<Integer, Integer> map = node1.getMap(name);
int key = RandomPicker.getInt(0, Integer.MAX_VALUE);
map.put(key, 1);
QueryCache queryCache = map.getQueryCache(name, Predicates.alwaysTrue(), true);
queryCache.get(key);
queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {
@Override
public void entryAdded(EntryEvent<Integer, Integer> event) {
}
}, true);
queryCache.destroy();
map.destroy();
assertNoUserListenerLeft(node1);
assertNoUserListenerLeft(node2);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheMemoryLeakTest method stress_user_listener_removal_upon_query_cache_destroy.
@Test
public void stress_user_listener_removal_upon_query_cache_destroy() throws InterruptedException {
final String[] mapNames = new String[] { "mapA", "mapB", "mapC", "mapD" };
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = getConfig();
final HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
HazelcastInstance node3 = factory.newHazelcastInstance(config);
final AtomicBoolean stop = new AtomicBoolean(false);
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < STRESS_TEST_THREAD_COUNT; i++) {
Thread thread = new Thread() {
@Override
public void run() {
while (!stop.get()) {
String name = mapNames[RandomPicker.getInt(0, 4)];
final IMap<Integer, Integer> map = node1.getMap(name);
int key = RandomPicker.getInt(0, Integer.MAX_VALUE);
map.put(key, 1);
QueryCache queryCache = map.getQueryCache(name, Predicates.alwaysTrue(), true);
queryCache.get(key);
queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {
@Override
public void entryAdded(EntryEvent<Integer, Integer> event) {
}
}, true);
queryCache.destroy();
map.destroy();
}
}
};
threads.add(thread);
}
for (Thread thread : threads) {
thread.start();
}
sleepSeconds(STRESS_TEST_RUN_SECONDS);
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertNoUserListenerLeft(node1);
assertNoUserListenerLeft(node2);
assertNoUserListenerLeft(node3);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.
@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
populateMap(map, 1000);
IFunction clear = (ignored) -> {
map.clear();
return null;
};
assertQueryCacheSizeEventually(0, clear, queryCache);
}
Aggregations