Search in sources :

Example 6 with Employee

use of com.hazelcast.mapreduce.helpers.Employee in project hazelcast by hazelcast.

the class ClientQueryCacheMethodsWithPredicateTest method test_values_withoutIndex.

@Test
public void test_values_withoutIndex() {
    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);
    for (int i = 17; i < count; 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 7 with Employee

use of com.hazelcast.mapreduce.helpers.Employee 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 8 with Employee

use of com.hazelcast.mapreduce.helpers.Employee 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 9 with Employee

use of com.hazelcast.mapreduce.helpers.Employee 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 10 with Employee

use of com.hazelcast.mapreduce.helpers.Employee in project hazelcast by hazelcast.

the class QueryCacheListenerTest method testValueCaching.

private void testValueCaching(final boolean includeValue) {
    String cacheName = randomString();
    final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    final TestIncludeValueListener listener = new TestIncludeValueListener();
    cache.addEntryListener(listener, includeValue);
    final int putCount = 1000;
    populateMap(map, putCount);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(putCount, cache.size());
            if (includeValue) {
                assertTrue("There should not be any null value", listener.hasValue);
            } else {
                assertFalse("There should not be any non-null value", listener.hasValue);
            }
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.mapreduce.helpers.Employee) AssertTask(com.hazelcast.test.AssertTask)

Aggregations

Employee (com.hazelcast.mapreduce.helpers.Employee)35 ParallelTest (com.hazelcast.test.annotation.ParallelTest)32 QuickTest (com.hazelcast.test.annotation.QuickTest)32 Test (org.junit.Test)32 SqlPredicate (com.hazelcast.query.SqlPredicate)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)20 CountDownLatch (java.util.concurrent.CountDownLatch)6 AssertTask (com.hazelcast.test.AssertTask)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ClientConfig (com.hazelcast.client.config.ClientConfig)1 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)1 IMap (com.hazelcast.core.IMap)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1