Search in sources :

Example 1 with QueryCacheFactory

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);
}
Also used : QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) Config(com.hazelcast.config.Config) QueryCacheFactory(com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with QueryCacheFactory

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());
}
Also used : QueryCacheFactory(com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory) QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with QueryCacheFactory

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());
}
Also used : ClientMapProxy(com.hazelcast.client.impl.proxy.ClientMapProxy) QueryCacheFactory(com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory) QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with QueryCacheFactory

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);
}
Also used : QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) QueryCacheFactory(com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryCacheFactory

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();
            }
        }
    }
}
Also used : QueryCacheFactory(com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory) Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) SubscriberRegistry(com.hazelcast.map.impl.querycache.subscriber.SubscriberRegistry) InternalQueryCache(com.hazelcast.map.impl.querycache.subscriber.InternalQueryCache) AccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo)

Aggregations

QueryCacheFactory (com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 QueryCacheEndToEndProvider (com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider)4 SubscriberContext (com.hazelcast.map.impl.querycache.subscriber.SubscriberContext)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Config (com.hazelcast.config.Config)2 AssertTask (com.hazelcast.test.AssertTask)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ClientMapProxy (com.hazelcast.client.impl.proxy.ClientMapProxy)1 Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)1 AccumulatorInfo (com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo)1 InternalQueryCache (com.hazelcast.map.impl.querycache.subscriber.InternalQueryCache)1 SubscriberRegistry (com.hazelcast.map.impl.querycache.subscriber.SubscriberRegistry)1