use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_destroy.
@Test
public void event_service_is_empty_after_queryCache_destroy() throws InterruptedException {
final String mapName = "test";
final String queryCacheName = "cqc";
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = getConfig();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
HazelcastInstance node3 = factory.newHazelcastInstance(config);
assertClusterSizeEventually(3, node1, node2, node3);
final IMap<Integer, Integer> map = node1.getMap(mapName);
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()) {
QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.alwaysTrue(), true);
queryCache.destroy();
}
}
};
threads.add(thread);
}
for (Thread thread : threads) {
thread.start();
}
sleepSeconds(STRESS_TEST_RUN_SECONDS);
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
map.destroy();
assertNoUserListenerLeft(node1);
assertNoUserListenerLeft(node2);
assertNoUserListenerLeft(node3);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheNoEventLossTest method assertAllQueryCachesSyncWithMap.
private void assertAllQueryCachesSyncWithMap() {
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
for (HazelcastInstance instance : instances) {
IMap map = instance.getMap(MAP_NAME);
Set<Map.Entry> mapEntrySet = map.entrySet();
QueryCache queryCache = map.getQueryCache(QUERY_CACHE_NAME);
Set<Map.Entry> queryCacheEntrySet = queryCache.entrySet();
assertEquals(queryCacheEntrySet.size(), mapEntrySet.size());
for (Map.Entry entry : mapEntrySet) {
Object key = entry.getKey();
Object valueFromMap = entry.getValue();
Object valueFromQueryCache = queryCache.get(key);
assertEquals(valueFromQueryCache, valueFromMap);
}
}
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_evictAll.
@Test
public void testQueryCacheCleared_afterCalling_IMap_evictAll() {
final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
populateMap(map, 1000);
IFunction evictAll = (ignored) -> {
map.evictAll();
return null;
};
assertQueryCacheSizeEventually(0, evictAll, queryCache);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheTest method testDestroy_emptiesQueryCache.
@Test
public void testDestroy_emptiesQueryCache() {
int entryCount = 1000;
final CountDownLatch numberOfAddEvents = new CountDownLatch(entryCount);
IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, (EntryAddedListener<Integer, Employee>) (event) -> numberOfAddEvents.countDown(), TRUE_PREDICATE, false);
populateMap(map, entryCount);
assertOpenEventually(numberOfAddEvents);
queryCache.destroy();
assertEquals(0, queryCache.size());
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheCreateDestroyTest method create_after_destroy_gives_fresh_query_cache_instance.
@Test
public void create_after_destroy_gives_fresh_query_cache_instance() {
final String mapName = "someMap";
final String queryCacheName = "testCache";
HazelcastInstance server = factory.newHazelcastInstance(newConfigWithQueryCache(mapName, queryCacheName));
server.getMap(mapName);
IMap map = server.getMap(mapName);
QueryCache queryCache = map.getQueryCache(queryCacheName);
queryCache.destroy();
QueryCache newQueryCache = map.getQueryCache(queryCacheName);
assertFalse(queryCache == newQueryCache);
}
Aggregations