Search in sources :

Example 26 with SqlPredicate

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

the class ClientQueryCacheTest method testQueryCache_withLocalListener.

@Test
public void testQueryCache_withLocalListener() {
    String mapName = randomString();
    String queryCacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(mapName);
    for (int i = 0; i < 30; i++) {
        map.put(i, i);
    }
    final AtomicInteger countAddEvent = new AtomicInteger();
    final AtomicInteger countRemoveEvent = new AtomicInteger();
    final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new EntryAdapter() {

        @Override
        public void entryAdded(EntryEvent event) {
            countAddEvent.incrementAndGet();
        }

        @Override
        public void entryRemoved(EntryEvent event) {
            countRemoveEvent.incrementAndGet();
        }
    }, new SqlPredicate("this > 20"), true);
    for (int i = 0; i < 30; i++) {
        map.remove(i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, queryCache.size());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("Count of add events wrong!", 9, countAddEvent.get());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get());
        }
    });
}
Also used : EntryAdapter(com.hazelcast.core.EntryAdapter) SqlPredicate(com.hazelcast.query.SqlPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with SqlPredicate

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

the class ClientQueryCacheIndexTest method test_values_withoutIndex_whenValuesCached.

@Test
public void test_values_withoutIndex_whenValuesCached() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    for (int i = 17; i < putCount; i++) {
        map.remove(i);
    }
    // just choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 17;
    assertValuesSizeEventually(expectedSize, new SqlPredicate("__key < " + 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)

Example 28 with SqlPredicate

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

the class ClientQueryCacheIndexTest method test_entrySet_onIndexedKeys_whenValuesNotCached.

@Test
public void test_entrySet_onIndexedKeys_whenValuesNotCached() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    // here add index to key. (key --> integer; value --> Employee)
    cache.addIndex("__key", true);
    for (int i = 17; i < putCount; i++) {
        map.remove(i);
    }
    // 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 : 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 29 with SqlPredicate

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

the class ClientQueryCacheIndexTest method test_values_withoutIndex_whenValuesNotCached.

@Test
public void test_values_withoutIndex_whenValuesNotCached() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    for (int i = 17; i < putCount; i++) {
        map.remove(i);
    }
    // just choose arbitrary numbers to prove whether #entrySet with predicate is working
    int smallerThan = 17;
    int expectedSize = 0;
    assertValuesSizeEventually(expectedSize, new SqlPredicate("__key < " + 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)

Example 30 with SqlPredicate

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

the class ClientQueryCacheIndexTest method test_keySet_withPredicate_whenValuesAreNotCached.

@Test
public void test_keySet_withPredicate_whenValuesAreNotCached() {
    String mapName = randomString();
    String cacheName = randomString();
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
    queryCacheConfig.setDelaySeconds(1);
    queryCacheConfig.setBatchSize(3);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    // populate map before construction of query cache
    int putCount = 111;
    for (int i = 0; i < putCount; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    cache.addIndex("__key", true);
    // populate map after construction of query cache
    for (int i = putCount; i < 2 * putCount; 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 * putCount - equalsOrBiggerThan;
    assertKeySetSizeEventually(expectedSize, new SqlPredicate("__key >= " + equalsOrBiggerThan), cache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) ClientConfig(com.hazelcast.client.config.ClientConfig) 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