Search in sources :

Example 1 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class ClientQueryCacheTest method getConfig.

private ClientConfig getConfig(String queryCacheName, boolean enableInitialPopulation, String mapName) {
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setPopulate(enableInitialPopulation).getPredicateConfig().setImplementation(TruePredicate.INSTANCE);
    return addConfig(queryCacheConfig, mapName);
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig)

Example 2 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class ClientEvictionTest method testMaxSizeEvictionWorks.

@Test
public void testMaxSizeEvictionWorks() throws Exception {
    final int maxSize = 1000;
    final int populationCount = 5000;
    String mapName = randomString();
    String cacheName = randomString();
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    cacheConfig.getEvictionConfig().setSize(maxSize).setEvictionPolicy(EvictionPolicy.LFU).setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, cacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    // expecting at least populationCount - maxSize + 10 evicted entries according to max size.
    // 10 states an error margin since eviction does not sweep precise number of entries.
    int margin = 10;
    final CountDownLatch evictedCount = new CountDownLatch(populationCount - maxSize - margin);
    final QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, TruePredicate.INSTANCE, true);
    String listener = cache.addEntryListener(new EntryEvictedListener() {

        @Override
        public void entryEvicted(EntryEvent event) {
            evictedCount.countDown();
        }
    }, false);
    for (int i = 0; i < populationCount; i++) {
        map.put(i, i);
    }
    assertOpenEventually(evictedCount);
    assertQueryCacheEvicted(maxSize, margin, cache);
    assertTrue(cache.removeEntryListener(listener));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EntryEvent(com.hazelcast.core.EntryEvent) EntryEvictedListener(com.hazelcast.map.listener.EntryEvictedListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig 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);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class TestClientApplicationContext method testFullQueryCacheConfig.

@Test
public void testFullQueryCacheConfig() throws Exception {
    ClientConfig config = client6.getClientConfig();
    QueryCacheConfig queryCacheConfig = getQueryCacheConfig(config);
    EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
    assertTrue(entryListenerConfig.isIncludeValue());
    assertFalse(entryListenerConfig.isLocal());
    assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
    assertFalse(queryCacheConfig.isIncludeValue());
    assertEquals("my-query-cache-1", queryCacheConfig.getName());
    assertEquals(12, queryCacheConfig.getBatchSize());
    assertEquals(33, queryCacheConfig.getBufferSize());
    assertEquals(12, queryCacheConfig.getDelaySeconds());
    assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
    assertTrue(queryCacheConfig.isCoalesce());
    assertFalse(queryCacheConfig.isPopulate());
    assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
    assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaxSizePolicy());
    assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
    assertEquals(2, queryCacheConfig.getIndexConfigs().size());
    IndexConfig hashIndex = queryCacheConfig.getIndexConfigs().get(0);
    assertEquals(IndexType.HASH, hashIndex.getType());
    assertNull(hashIndex.getName());
    assertEquals(1, hashIndex.getAttributes().size());
    assertEquals("name", hashIndex.getAttributes().get(0));
    IndexConfig sortedIndex = queryCacheConfig.getIndexConfigs().get(1);
    assertEquals(IndexType.SORTED, sortedIndex.getType());
    assertEquals("sortedIndex", sortedIndex.getName());
    assertEquals(2, sortedIndex.getAttributes().size());
    assertEquals("age", sortedIndex.getAttributes().get(0));
    assertEquals("name", sortedIndex.getAttributes().get(1));
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryCacheConfig

use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.

the class TestFullApplicationContext method testFullQueryCacheConfig.

@Test
public void testFullQueryCacheConfig() {
    MapConfig mapConfig = config.getMapConfig("map-with-query-cache");
    QueryCacheConfig queryCacheConfig = mapConfig.getQueryCacheConfigs().get(0);
    EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
    assertTrue(entryListenerConfig.isIncludeValue());
    assertFalse(entryListenerConfig.isLocal());
    assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
    assertFalse(queryCacheConfig.isIncludeValue());
    assertEquals("my-query-cache-1", queryCacheConfig.getName());
    assertEquals(12, queryCacheConfig.getBatchSize());
    assertEquals(33, queryCacheConfig.getBufferSize());
    assertEquals(12, queryCacheConfig.getDelaySeconds());
    assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
    assertTrue(queryCacheConfig.isCoalesce());
    assertTrue(queryCacheConfig.isSerializeKeys());
    assertFalse(queryCacheConfig.isPopulate());
    assertIndexesEqual(queryCacheConfig);
    assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
    assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaxSizePolicy());
    assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Aggregations

QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)80 Config (com.hazelcast.config.Config)29 Test (org.junit.Test)29 QuickTest (com.hazelcast.test.annotation.QuickTest)28 MapConfig (com.hazelcast.config.MapConfig)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 PredicateConfig (com.hazelcast.config.PredicateConfig)17 ClientConfig (com.hazelcast.client.config.ClientConfig)15 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)14 AttributeConfig (com.hazelcast.config.AttributeConfig)8 Employee (com.hazelcast.map.impl.querycache.utils.Employee)8 Before (org.junit.Before)8 IndexConfig (com.hazelcast.config.IndexConfig)7 AssertTask (com.hazelcast.test.AssertTask)7 Map (java.util.Map)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 EvictionConfig (com.hazelcast.config.EvictionConfig)6 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 EventLostEvent (com.hazelcast.map.EventLostEvent)5