Search in sources :

Example 31 with SqlPredicate

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

the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListeningKey_withPredicate.

@Test
public void shouldReceiveEvent_whenListeningKey_withPredicate() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance instance = factory.newHazelcastClient();
    IMap<Integer, Employee> map = instance.getMap(mapName);
    CountDownLatch numberOfCaughtEvents = new CountDownLatch(1);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    int keyToListen = 109;
    cache.addEntryListener(new QueryCacheAdditionListener(numberOfCaughtEvents), new SqlPredicate("id > 100"), keyToListen, true);
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    assertOpenEventually(numberOfCaughtEvents, 10);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 32 with SqlPredicate

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

the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListeningKey_withMultipleListener.

@Test
public void shouldReceiveEvent_whenListeningKey_withMultipleListener() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance instance = factory.newHazelcastClient();
    IMap<Integer, Employee> map = instance.getMap(mapName);
    CountDownLatch additionCount = new CountDownLatch(2);
    CountDownLatch removalCount = new CountDownLatch(2);
    final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    int keyToListen = 109;
    cache.addEntryListener(new QueryCacheAdditionListener(additionCount), new SqlPredicate("id > 100"), keyToListen, true);
    cache.addEntryListener(new QueryCacheRemovalListener(removalCount), new SqlPredicate("id > 100"), keyToListen, true);
    // populate map before construction of query cache
    int count = 111;
    for (int i = 0; i < count; i++) {
        map.put(i, new Employee(i));
    }
    for (int i = 0; i < count; i++) {
        map.remove(i);
    }
    for (int i = 0; i < count; i++) {
        map.put(i, new Employee(i));
    }
    for (int i = 0; i < count; i++) {
        map.remove(i);
    }
    AssertTask task = new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, cache.size());
        }
    };
    assertTrueEventually(task);
    assertOpenEventually(cache.size() + "", additionCount, 10);
    assertOpenEventually(cache.size() + "", removalCount, 10);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with SqlPredicate

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

the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListening_withPredicate.

@Test
public void shouldReceiveEvent_whenListening_withPredicate() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance instance = factory.newHazelcastClient();
    IMap<Integer, Employee> map = instance.getMap(mapName);
    CountDownLatch numberOfCaughtEvents = new CountDownLatch(10);
    final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addEntryListener(new QueryCacheAdditionListener(numberOfCaughtEvents), new SqlPredicate("id > 100"), true);
    final int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    assertOpenEventually(numberOfCaughtEvents, 10);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with SqlPredicate

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

the class ClientQueryCacheMethodsWithPredicateTest method test_values.

@Test
public void test_values() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance instance = getInstance();
    IMap<Integer, Employee> map = instance.getMap(mapName);
    // populate map before construction of query cache
    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, true);
    cache.addIndex("id", true);
    // populate map after construction of query cache
    for (int i = count; i < 2 * count; i++) {
        map.put(i, new Employee(i));
    }
    // 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 : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 35 with SqlPredicate

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

the class ClientQueryCacheMethodsWithPredicateTest method test_keySet_onRemovedIndexes.

@Test
public void test_keySet_onRemovedIndexes() {
    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, true);
    cache.addIndex("id", true);
    for (int i = 17; i < count; i++) {
        map.remove(i);
    }
    // just choose arbitrary numbers to prove whether #keySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 17;
    assertKeySetSizeEventually(expectedSize, new SqlPredicate("id < " + smallerThan), cache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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