Search in sources :

Example 31 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class ClientQueryCacheMethodsWithPredicateTest method test_entrySet_withIndexedKeys_whenIncludeValueFalse.

@Test
public void test_entrySet_withIndexedKeys_whenIncludeValueFalse() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance instance = getInstance();
    IMap<Integer, Employee> map = instance.getMap(mapName);
    int count = 111;
    for (int i = 0; i < count; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    // here adding key index. (key --> integer; value --> Employee)
    cache.addIndex(IndexType.SORTED, "__key");
    for (int i = 17; i < count; i++) {
        map.remove(i);
    }
    // ust choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 17;
    assertEntrySetSizeEventually(expectedSize, Predicates.sql("__key < " + smallerThan), cache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class ClientQueryCacheMethodsWithPredicateTest method assertValuesSizeEventually.

private void assertValuesSizeEventually(final int expectedSize, final Predicate predicate, final QueryCache<Integer, Employee> cache) {
    AssertTask task = new AssertTask() {

        @Override
        public void run() throws Exception {
            int size = cache.size();
            Collection<Employee> values = cache.values(predicate);
            assertEquals("cache size = " + size, expectedSize, values.size());
        }
    };
    assertTrueEventually(task, DEFAULT_TEST_TIMEOUT);
}
Also used : Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask)

Example 33 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.

the class QueryCacheListenerTest method listenerShouldBeRegistered_whenConfiguredProgrammatically.

@Test
public void listenerShouldBeRegistered_whenConfiguredProgrammatically() {
    MapConfig mapConfig = new MapConfig(mapName);
    final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig(listener, true, true));
    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);
    populateMap(map, 100);
    assertTrueEventually(() -> assertEquals(100, listener.getAddedEventCount()));
    assertTrueAllTheTime(() -> assertEquals(100, listener.getAddedEventCount()), 5);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.map.impl.querycache.utils.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) 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) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee 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 35 with Employee

use of com.hazelcast.map.impl.querycache.utils.Employee 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)

Aggregations

Employee (com.hazelcast.map.impl.querycache.utils.Employee)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)35 QuickTest (com.hazelcast.test.annotation.QuickTest)35 Test (org.junit.Test)35 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)11 AssertTask (com.hazelcast.test.AssertTask)11 PredicateConfig (com.hazelcast.config.PredicateConfig)10 Config (com.hazelcast.config.Config)9 IMap (com.hazelcast.map.IMap)6 AttributeConfig (com.hazelcast.config.AttributeConfig)5 MapConfig (com.hazelcast.config.MapConfig)4 EntryAdapter (com.hazelcast.core.EntryAdapter)4 EntryEvent (com.hazelcast.core.EntryEvent)4 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)4 Set (java.util.Set)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)3 IFunction (com.hazelcast.core.IFunction)3