use of com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory in project hazelcast by hazelcast.
the class QueryCacheMemoryLeakTest method no_query_cache_left_after_creating_and_destroying_same_map_concurrently.
@Test
public void no_query_cache_left_after_creating_and_destroying_same_map_concurrently() throws Exception {
Config config = getConfig();
final HazelcastInstance node = createHazelcastInstance(config);
final String mapName = "test";
ExecutorService pool = Executors.newFixedThreadPool(STRESS_TEST_THREAD_COUNT);
final AtomicBoolean stop = new AtomicBoolean();
for (int i = 0; i < 1000; i++) {
Runnable runnable = new Runnable() {
public void run() {
while (!stop.get()) {
IMap<Integer, Integer> map = node.getMap(mapName);
try {
populateMap(map);
for (int j = 0; j < 10; j++) {
map.getQueryCache(j + "-test-QC", Predicates.alwaysTrue(), true);
}
} finally {
map.destroy();
}
}
}
};
pool.submit(runnable);
}
sleepSeconds(STRESS_TEST_RUN_SECONDS);
stop.set(true);
pool.shutdown();
pool.awaitTermination(120, TimeUnit.SECONDS);
SubscriberContext subscriberContext = getSubscriberContext(node);
final QueryCacheEndToEndProvider provider = subscriberContext.getEndToEndQueryCacheProvider();
final QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, provider.getQueryCacheCount(mapName));
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, queryCacheFactory.getQueryCacheCount());
}
});
assertNoListenerLeftOnEventService(node);
assertNoRegisteredListenerLeft(node, mapName);
assertNoAccumulatorInfoSupplierLeft(node, mapName);
assertNoPartitionAccumulatorRegistryLeft(node, mapName);
}
use of com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory in project hazelcast by hazelcast.
the class QueryCacheMemoryLeakTest method removes_internal_query_caches_upon_map_destroy.
@Test
public void removes_internal_query_caches_upon_map_destroy() {
Config config = getConfig();
HazelcastInstance node = createHazelcastInstance(config);
String mapName = "test";
IMap<Integer, Integer> map = node.getMap(mapName);
populateMap(map);
for (int j = 0; j < 10; j++) {
map.getQueryCache(j + "-test-QC", Predicates.alwaysTrue(), true);
}
map.destroy();
SubscriberContext subscriberContext = getSubscriberContext(node);
QueryCacheEndToEndProvider provider = subscriberContext.getEndToEndQueryCacheProvider();
QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
assertEquals(0, provider.getQueryCacheCount(mapName));
assertEquals(0, queryCacheFactory.getQueryCacheCount());
}
use of com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory in project hazelcast by hazelcast.
the class ClientQueryCacheMemoryLeakTest method removes_internal_query_caches_upon_map_destroy.
@Test
public void removes_internal_query_caches_upon_map_destroy() {
factory.newHazelcastInstance();
HazelcastInstance client = factory.newHazelcastClient();
String mapName = "test";
IMap<Integer, Integer> map = client.getMap(mapName);
populateMap(map);
for (int j = 0; j < 10; j++) {
map.getQueryCache(j + "-test-QC", Predicates.alwaysTrue(), true);
}
map.destroy();
ClientQueryCacheContext queryCacheContext = ((ClientMapProxy) map).getQueryCacheContext();
SubscriberContext subscriberContext = queryCacheContext.getSubscriberContext();
QueryCacheEndToEndProvider provider = subscriberContext.getEndToEndQueryCacheProvider();
QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
assertEquals(0, provider.getQueryCacheCount(mapName));
assertEquals(0, queryCacheFactory.getQueryCacheCount());
}
use of com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory in project hazelcast by hazelcast.
the class ClientQueryCacheMemoryLeakTest method no_query_cache_left_after_creating_and_destroying_same_map_concurrently.
@Test
public void no_query_cache_left_after_creating_and_destroying_same_map_concurrently() throws Exception {
final HazelcastInstance node = factory.newHazelcastInstance();
final HazelcastInstance client = factory.newHazelcastClient();
final String mapName = "test";
ExecutorService pool = Executors.newFixedThreadPool(STRESS_TEST_THREAD_COUNT);
final AtomicBoolean stop = new AtomicBoolean(false);
for (int i = 0; i < 1000; i++) {
Runnable runnable = new Runnable() {
public void run() {
while (!stop.get()) {
IMap<Integer, Integer> map = client.getMap(mapName);
try {
populateMap(map);
for (int j = 0; j < 10; j++) {
map.getQueryCache(j + "-test-QC", Predicates.alwaysTrue(), true);
}
} finally {
map.destroy();
}
}
}
};
pool.submit(runnable);
}
sleepSeconds(STRESS_TEST_RUN_SECONDS);
stop.set(true);
pool.shutdown();
pool.awaitTermination(120, TimeUnit.SECONDS);
SubscriberContext subscriberContext = getSubscriberContext(client, mapName);
final QueryCacheEndToEndProvider provider = subscriberContext.getEndToEndQueryCacheProvider();
final QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, provider.getQueryCacheCount(mapName));
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, queryCacheFactory.getQueryCacheCount());
}
});
assertNoListenerLeftOnEventService(node);
assertNoRegisteredListenerLeft(node, mapName);
assertNoAccumulatorInfoSupplierLeft(node, mapName);
assertNoPartitionAccumulatorRegistryLeft(node, mapName);
}
use of com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory in project hazelcast by hazelcast.
the class ClientQueryCacheContext method recreateAllCaches.
public void recreateAllCaches() {
// Since query cache is lost we are firing event lost event for each cache and for each partition
QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
Map<String, SubscriberRegistry> registryMap = subscriberContext.getMapSubscriberRegistry().getAll();
for (SubscriberRegistry subscriberRegistry : registryMap.values()) {
Map<String, Accumulator> accumulatorMap = subscriberRegistry.getAll();
for (Accumulator accumulator : accumulatorMap.values()) {
AccumulatorInfo info = accumulator.getInfo();
String cacheId = info.getCacheId();
InternalQueryCache queryCache = queryCacheFactory.getOrNull(cacheId);
if (queryCache != null) {
queryCache.recreate();
}
}
}
}
Aggregations