Search in sources :

Example 31 with Employee

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

the class QueryCacheMethodsWithPredicateTest method testKeySet_onIndexedField_afterRemovalOfSomeIndexes.

@Test
public void testKeySet_onIndexedField_afterRemovalOfSomeIndexes() {
    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, 17, count);
    // 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 : 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 32 with Employee

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

the class QueryCacheMethodsWithPredicateTest method testValues_withoutIndex_whenIncludeValueFalse.

@Test
public void testValues_withoutIndex_whenIncludeValueFalse() {
    int count = 111;
    String cacheName = randomString();
    populateMap(map, count);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    removeEntriesFromMap(map, 17, count);
    // 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 : 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 33 with Employee

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

the class QueryCacheListenerTest method listen_withPredicate_afterQueryCacheCreation.

@Test
public void listen_withPredicate_afterQueryCacheCreation() {
    String cacheName = randomString();
    CountDownLatch numberOfCaughtEvents = new CountDownLatch(10);
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addEntryListener(new QueryCacheAdditionListener(numberOfCaughtEvents), SQL_PREDICATE_GT, true);
    int count = 111;
    populateMap(map, count);
    assertOpenEventually(numberOfCaughtEvents, 10);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.mapreduce.helpers.Employee) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with Employee

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

the class QueryCacheListenerTest method listenKey_withMultipleListeners_afterQueryCacheCreation.

@Test
public void listenKey_withMultipleListeners_afterQueryCacheCreation() {
    int keyToListen = 109;
    String cacheName = randomString();
    CountDownLatch additionCount = new CountDownLatch(2);
    CountDownLatch removalCount = new CountDownLatch(2);
    final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
    cache.addEntryListener(new QueryCacheAdditionListener(additionCount), SQL_PREDICATE_GT, keyToListen, true);
    cache.addEntryListener(new QueryCacheRemovalListener(removalCount), SQL_PREDICATE_GT, keyToListen, true);
    int count = 111;
    populateMap(map, count);
    removeEntriesFromMap(map, 0, count);
    populateMap(map, count);
    removeEntriesFromMap(map, 0, count);
    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 : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Employee(com.hazelcast.mapreduce.helpers.Employee) 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 35 with Employee

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

the class QueryCacheMethodsWithPredicateTest method testKeySet_onIndexedField.

@Test
public void testKeySet_onIndexedField() {
    int count = 111;
    populateMap(map, count);
    String cacheName = randomString();
    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;
    assertKeySetSizeEventually(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)

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