Search in sources :

Example 1 with Employee

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

the class MapReduceTest method employeeMapReduceTest.

@Test(timeout = TEST_TIMEOUT)
public void employeeMapReduceTest() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    try {
        IMap<Integer, Employee> map = h1.getMap(randomString());
        int keyCount = 100;
        for (int id = 0; id < keyCount; id++) {
            map.put(id, new Employee(id));
        }
        JobTracker tracker = h1.getJobTracker(randomString());
        Job<Integer, Employee> job = tracker.newJob(KeyValueSource.<Integer, Employee>fromMap(map));
        ICompletableFuture<Map<Integer, Set<Employee>>> future = job.mapper(new ModIdMapper(2)).combiner(new RangeIdCombinerFactory(10, 30)).reducer(new IdReducerFactory(10, 20, 30)).submit();
        Map<Integer, Set<Employee>> result = future.get();
        assertEquals("Expected 8 employees with ids ending 2, 4, 6, 8", 8, result.size());
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with Employee

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

the class ClientQueryCacheIndexTest method test_keySet_withPredicate.

@Test
public void test_keySet_withPredicate() {
    String mapName = randomString();
    String cacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Employee> map = client.getMap(mapName);
    // populate map before construction of query cache.
    final 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, true);
    cache.addIndex("id", 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("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 3 with Employee

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

the class ClientQueryCacheIndexTest method test_entrySet_withPredicate_whenValuesNotCached.

@Test
public void test_entrySet_withPredicate_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);
    cache.addIndex("id", 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 = 0;
    assertEntrySetSizeEventually(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)

Example 4 with Employee

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

the class ClientQueryCacheIndexTest method test_keySet_withPredicate_afterRemovals.

@Test
public void test_keySet_withPredicate_afterRemovals() {
    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);
    cache.addIndex("id", true);
    for (int i = 17; i < putCount; 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)

Example 5 with Employee

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

the class ClientQueryCacheMethodsWithPredicateTest method test_keySet.

@Test
public void test_keySet() {
    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;
    assertKeySetSizeEventually(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)

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