Search in sources :

Example 71 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapReduceTest method testMapperReducer.

@Test(timeout = 120000)
public void testMapperReducer() throws Exception {
    Config config = buildConfig();
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
    for (int i = 0; i < 100; i++) {
        m1.put(i, i);
    }
    JobTracker tracker = client.getJobTracker("default");
    Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
    ICompletableFuture<Map<String, Integer>> future = job.mapper(new GroupingTestMapper()).reducer(new TestReducerFactory()).submit();
    Map<String, Integer> result = future.get();
    // Precalculate results
    int[] expectedResults = new int[4];
    for (int i = 0; i < 100; i++) {
        int index = i % 4;
        expectedResults[index] += i;
    }
    for (int i = 0; i < 4; i++) {
        assertEquals(expectedResults[i], (int) result.get(String.valueOf(i)));
    }
}
Also used : Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 72 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapReduceTest method testKeyedAsyncMapper.

@Test(timeout = 120000)
public void testKeyedAsyncMapper() throws Exception {
    Config config = buildConfig();
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
    for (int i = 0; i < 100; i++) {
        m1.put(i, i);
    }
    final Map<String, List<Integer>> listenerResults = new HashMap<String, List<Integer>>();
    final Semaphore semaphore = new Semaphore(1);
    semaphore.acquire();
    JobTracker tracker = client.getJobTracker("default");
    Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
    ICompletableFuture<Map<String, List<Integer>>> future = job.onKeys(50).mapper(new TestMapper()).submit();
    future.andThen(new ExecutionCallback<Map<String, List<Integer>>>() {

        @Override
        public void onResponse(Map<String, List<Integer>> response) {
            listenerResults.putAll(response);
            semaphore.release();
        }

        @Override
        public void onFailure(Throwable t) {
            semaphore.release();
        }
    });
    semaphore.acquire();
    assertEquals(1, listenerResults.size());
    for (List<Integer> value : listenerResults.values()) {
        assertEquals(1, value.size());
    }
}
Also used : HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) Semaphore(java.util.concurrent.Semaphore) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 73 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapReduceTest method testAsyncMapper.

@Test(timeout = 120000)
public void testAsyncMapper() throws Exception {
    Config config = buildConfig();
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
    for (int i = 0; i < 100; i++) {
        m1.put(i, i);
    }
    final Map<String, List<Integer>> listenerResults = new HashMap<String, List<Integer>>();
    final Semaphore semaphore = new Semaphore(1);
    semaphore.acquire();
    JobTracker tracker = client.getJobTracker("default");
    Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
    ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new TestMapper()).submit();
    future.andThen(new ExecutionCallback<Map<String, List<Integer>>>() {

        @Override
        public void onResponse(Map<String, List<Integer>> response) {
            listenerResults.putAll(response);
            semaphore.release();
        }

        @Override
        public void onFailure(Throwable t) {
            semaphore.release();
        }
    });
    semaphore.acquire();
    assertEquals(100, listenerResults.size());
    for (List<Integer> value : listenerResults.values()) {
        assertEquals(1, value.size());
    }
}
Also used : HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) Semaphore(java.util.concurrent.Semaphore) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 74 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapReduceTest method testExceptionDistribution.

@Test(expected = ExecutionException.class)
public void testExceptionDistribution() throws Exception {
    Config config = buildConfig();
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    MultiMap<Integer, Integer> m1 = client.getMultiMap(randomString());
    for (int i = 0; i < 100; i++) {
        m1.put(i / 2, i);
    }
    JobTracker tracker = client.getJobTracker("default");
    Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
    ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new ExceptionThrowingMapper()).submit();
    try {
        Map<String, List<Integer>> result = future.get();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(e.getCause() instanceof NullPointerException);
        throw e;
    }
}
Also used : Config(com.hazelcast.config.Config) JobTracker(com.hazelcast.mapreduce.JobTracker) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) HashMap(java.util.HashMap) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 75 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapListenersTest method testListeners_clearAllFromNode.

@Test
public void testListeners_clearAllFromNode() {
    final String name = randomString();
    final MultiMap mm = client.getMultiMap(name);
    MyEntryListener listener = new CountDownValueNullListener(1);
    mm.addEntryListener(listener, false);
    mm.put("key", "value");
    server.getMultiMap(name).clear();
    assertOpenEventually(listener.addLatch);
    assertOpenEventually(listener.clearLatch);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MultiMap (com.hazelcast.core.MultiMap)118 Test (org.junit.Test)117 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)106 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)12 Map (java.util.Map)11 Config (com.hazelcast.config.Config)9 TransactionalMultiMap (com.hazelcast.core.TransactionalMultiMap)9 JobTracker (com.hazelcast.mapreduce.JobTracker)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 HashMap (java.util.HashMap)9 TransactionContext (com.hazelcast.transaction.TransactionContext)8 SlowTest (com.hazelcast.test.annotation.SlowTest)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AssertTask (com.hazelcast.test.AssertTask)5 Collection (java.util.Collection)5 List (java.util.List)5 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4