Search in sources :

Example 66 with QueryCacheConfig

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

the class QueryCacheListenerTest method published_event_contains_key_when_include_value_is_false.

@Test
public void published_event_contains_key_when_include_value_is_false() {
    CountDownLatch waitEventLatch = new CountDownLatch(1);
    AtomicReference<EntryEvent<Integer, Employee>> eventObject = new AtomicReference<>();
    MapConfig mapConfig = new MapConfig(mapName);
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig((EntryAddedListener<Integer, Employee>) event -> {
        eventObject.set(event);
        waitEventLatch.countDown();
    }, true, false));
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    Config config = new Config();
    config.addMapConfig(mapConfig);
    IMap<Integer, Employee> map = getIMap(config);
    // trigger creation of the query cache
    map.getQueryCache(cacheName);
    map.put(1, new Employee(1));
    assertOpenEventually(waitEventLatch);
    assertEquals(1, eventObject.get().getKey().intValue());
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) PredicateConfig(com.hazelcast.config.PredicateConfig) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with QueryCacheConfig

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

the class QueryCacheMapLoaderTest method getConfig.

private Config getConfig(String mapName, String cacheName) {
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setInMemoryFormat(inMemoryFormat);
    mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(mapLoader);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    mapConfig.addQueryCacheConfig(cacheConfig);
    return config;
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig)

Example 68 with QueryCacheConfig

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

the class QueryCacheNoEventLossTest method newConfig.

private Config newConfig() {
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig().setName(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(Predicates.alwaysTrue()));
    MapConfig mapConfig = new MapConfig(MAP_NAME).addQueryCacheConfig(queryCacheConfig);
    return smallInstanceConfig().addMapConfig(mapConfig);
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 69 with QueryCacheConfig

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

the class QueryCachePredicateConfigTest method test_whenSqlIsSet.

@Test
public void test_whenSqlIsSet() {
    String mapName = randomString();
    String cacheName = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
    predicateConfig.setSql("id > 10");
    mapConfig.addQueryCacheConfig(cacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Employee> map = getMap(node, mapName);
    for (int i = 0; i < 15; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
    assertEquals(4, cache.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with QueryCacheConfig

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

the class QueryCacheSimpleStressTest method setUp.

@Before
public void setUp() {
    EvictionConfig evictionConfig = new EvictionConfig();
    evictionConfig.setMaxSizePolicy(MaxSizePolicy.ENTRY_COUNT);
    evictionConfig.setSize(Integer.MAX_VALUE);
    evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setBufferSize(30).setDelaySeconds(2).setBatchSize(2).setPopulate(true).getPredicateConfig().setImplementation(Predicates.alwaysTrue());
    queryCacheConfig.setEvictionConfig(evictionConfig);
    MapConfig mapConfig = new MapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    config.addMapConfig(mapConfig);
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) MapConfig(com.hazelcast.config.MapConfig) Before(org.junit.Before)

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