Search in sources :

Example 11 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.

the class QueryCacheMethodsWithPredicateTest method testEntrySet.

@Test
public void testEntrySet() {
    int count = 1;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addIndex("id", true);
    populateMap(map, count, 2 * count);
    // just choose arbitrary numbers for querying in order to prove whether #keySet with predicate is correctly working
    int equalsOrBiggerThan = 0;
    int expectedSize = 2 * count - equalsOrBiggerThan;
    assertEntrySetSizeEventually(expectedSize, new SqlPredicate("id >= " + equalsOrBiggerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.

the class QueryCacheMethodsWithPredicateTest method testEntrySet_whenIncludeValueFalse.

@Test
public void testEntrySet_whenIncludeValueFalse() throws Exception {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    cache.addIndex("id", true);
    removeEntriesFromMap(map, 17, count);
    // just choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 0;
    assertEntrySetSizeEventually(expectedSize, new SqlPredicate("id < " + smallerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.

the class QueryCacheMethodsWithPredicateTest method testValues.

@Test
public void testValues() {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addIndex("id", true);
    populateMap(map, count, 2 * count);
    // just choose arbitrary numbers for querying in order to prove whether #keySet with predicate is correctly working
    int equalsOrBiggerThan = 27;
    int expectedSize = 2 * count - equalsOrBiggerThan;
    assertValuesSizeEventually(expectedSize, new SqlPredicate("id >= " + equalsOrBiggerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with SqlPredicate

use of com.hazelcast.query.SqlPredicate 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 15 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.

the class QueryCacheMethodsWithPredicateTest method testEntrySet_withIndexedKeys_whenIncludeValueFalse.

@Test
public void testEntrySet_withIndexedKeys_whenIncludeValueFalse() {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    // here adding key index. (key --> integer; value --> Employee)
    cache.addIndex("__key", true);
    removeEntriesFromMap(map, 17, count);
    // just choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 17;
    assertEntrySetSizeEventually(expectedSize, new SqlPredicate("__key < " + smallerThan), cache);
}
Also used : Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

SqlPredicate (com.hazelcast.query.SqlPredicate)53 QuickTest (com.hazelcast.test.annotation.QuickTest)40 Test (org.junit.Test)40 ParallelTest (com.hazelcast.test.annotation.ParallelTest)35 Employee (com.hazelcast.mapreduce.helpers.Employee)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 IMap (com.hazelcast.core.IMap)5 Map (java.util.Map)5 AssertTask (com.hazelcast.test.AssertTask)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Config (com.hazelcast.config.Config)3 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)3 EventLostEvent (com.hazelcast.map.EventLostEvent)3 QueryCache (com.hazelcast.map.QueryCache)3 EventLostListener (com.hazelcast.map.listener.EventLostListener)3 Predicate (com.hazelcast.query.Predicate)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2