Search in sources :

Example 16 with PredicateConfig

use of com.hazelcast.config.PredicateConfig 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 17 with PredicateConfig

use of com.hazelcast.config.PredicateConfig 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 18 with PredicateConfig

use of com.hazelcast.config.PredicateConfig 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 19 with PredicateConfig

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

the class QueryCacheBasicTest method setup.

// setup a map with 2 query caches, same predicate, one includes values, the other excludes values
@Before
public void setup() {
    Config config = new Config();
    config.getMapConfig(TEST_MAP_NAME).addQueryCacheConfig(new QueryCacheConfig(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(predicate)).setIncludeValue(includeValues));
    if (useNearCache) {
        config.getMapConfig(TEST_MAP_NAME).setNearCacheConfig(new NearCacheConfig().setCacheLocalEntries(true));
    }
    config.setProperty(MapEventPublisherImpl.LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES.getName(), Boolean.toString(useQueryCacheNaturalFilteringStrategy));
    instance = createHazelcastInstance(config);
    map = getMap(instance, "EntryListenerEventTypesTestMap");
    queryCache = map.getQueryCache(QUERY_CACHE_NAME);
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Before(org.junit.Before)

Example 20 with PredicateConfig

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

the class QueryCacheInMemoryFormatTest method testInMemoryFormat.

private void testInMemoryFormat(InMemoryFormat inMemoryFormat, int expectedDeserializationCount) {
    SerializableObject.deserializationCount.set(0);
    String mapName = randomString();
    String cacheName = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    cacheConfig.setInMemoryFormat(inMemoryFormat);
    PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
    predicateConfig.setSql("__key > -1");
    mapConfig.addQueryCacheConfig(cacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, SerializableObject> map = getMap(node, mapName);
    map.put(1, new SerializableObject());
    assertEquals(0, SerializableObject.deserializationCount.get());
    QueryCache<Integer, SerializableObject> cache = map.getQueryCache(cacheName);
    for (int i = 0; i < 10; i++) {
        cache.get(1);
        int expectedInitialCountInLoop = inMemoryFormat == BINARY ? i + 1 : 1;
        assertEquals("Error on iteration " + i, expectedInitialCountInLoop, SerializableObject.deserializationCount.get());
    }
    assertEquals(expectedDeserializationCount, SerializableObject.deserializationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Aggregations

PredicateConfig (com.hazelcast.config.PredicateConfig)21 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)14 Config (com.hazelcast.config.Config)11 MapConfig (com.hazelcast.config.MapConfig)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Employee (com.hazelcast.map.impl.querycache.utils.Employee)6 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)5 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 AttributeConfig (com.hazelcast.config.AttributeConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3 Before (org.junit.Before)3 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)2 AwsConfig (com.hazelcast.config.AwsConfig)2 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)2 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2