Search in sources :

Example 31 with IMap

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

the class MapReduceTest method testMapperComplexMapping.

@Test(timeout = TEST_TIMEOUT)
public void testMapperComplexMapping() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 100; i++) {
            m1.put(i, i);
        }
        JobTracker tracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
        ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new GroupingTestMapper(2)).submit();
        Map<String, List<Integer>> result = future.get();
        assertEquals(1, result.size());
        assertEquals(25, result.values().iterator().next().size());
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList) List(java.util.List) 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 32 with IMap

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

the class MapReduceTest method testExceptionDistribution.

@Test(timeout = TEST_TIMEOUT, expected = ExecutionException.class)
public void testExceptionDistribution() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 100; i++) {
            m1.put(i, i);
        }
        JobTracker tracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
        ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new ExceptionThrowingMapper()).submit();
        try {
            future.get();
            fail();
        } catch (Exception e) {
            e.printStackTrace();
            assertTrue(e.getCause() instanceof NullPointerException);
            throw e;
        }
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with IMap

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

the class MapReduceTest method testExceptionDistributionWithCollator.

@Test(timeout = TEST_TIMEOUT, expected = ExecutionException.class)
public void testExceptionDistributionWithCollator() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 100; i++) {
            m1.put(i, i);
        }
        JobTracker tracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
        ICompletableFuture<Map<String, List<Integer>>> future = job.mapper(new ExceptionThrowingMapper()).submit(new Collator<Map.Entry<String, List<Integer>>, Map<String, List<Integer>>>() {

            @Override
            public Map<String, List<Integer>> collate(Iterable<Map.Entry<String, List<Integer>>> values) {
                return null;
            }
        });
        try {
            future.get();
            fail();
        } catch (Exception e) {
            e.printStackTrace();
            assertTrue(e.getCause() instanceof NullPointerException);
            throw e;
        }
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 34 with IMap

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

the class MapReduceTest method testMapperReducerChunked.

@Test(timeout = TEST_TIMEOUT)
public void testMapperReducerChunked() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 10000; i++) {
            m1.put(i, i);
        }
        JobTracker tracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
        JobCompletableFuture<Map<String, Integer>> future = job.chunkSize(10).mapper(new GroupingTestMapper()).reducer(new TestReducerFactory()).submit();
        TrackableJob trackableJob = tracker.getTrackableJob(future.getJobId());
        final JobProcessInformation processInformation = trackableJob.getJobProcessInformation();
        Map<String, Integer> result = future.get();
        // pre-calculate results
        int[] expectedResults = new int[4];
        for (int i = 0; i < 10000; i++) {
            int index = i % 4;
            expectedResults[index] += i;
        }
        for (int i = 0; i < 4; i++) {
            assertEquals(expectedResults[i], (int) result.get(String.valueOf(i)));
        }
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() {
                if (processInformation.getProcessedRecords() < 10000) {
                    System.err.println(processInformation.getProcessedRecords());
                }
                assertEquals(10000, processInformation.getProcessedRecords());
            }
        });
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) 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 35 with IMap

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

the class MapReduceTest method testNullFromObjectCombiner.

@Test(timeout = TEST_TIMEOUT)
public void testNullFromObjectCombiner() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 100; i++) {
            m1.put(i, i);
        }
        JobTracker jobTracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = jobTracker.newJob(integerKvSource(m1));
        JobCompletableFuture<Map<String, BigInteger>> future = job.chunkSize(10).mapper(new GroupingTestMapper()).combiner(new ObjectCombinerFactory()).reducer(new ObjectReducerFactory()).submit();
        int[] expectedResults = new int[4];
        for (int i = 0; i < 100; i++) {
            int index = i % 4;
            expectedResults[index] += i;
        }
        Map<String, BigInteger> map = future.get();
        for (int i = 0; i < 4; i++) {
            assertEquals(BigInteger.valueOf(expectedResults[i]), map.get(String.valueOf(i)));
        }
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) BigInteger(java.math.BigInteger) 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)

Aggregations

IMap (com.hazelcast.core.IMap)263 Test (org.junit.Test)241 QuickTest (com.hazelcast.test.annotation.QuickTest)218 ParallelTest (com.hazelcast.test.annotation.ParallelTest)211 HazelcastInstance (com.hazelcast.core.HazelcastInstance)144 Config (com.hazelcast.config.Config)80 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)80 Map (java.util.Map)65 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)62 HashMap (java.util.HashMap)53 CountDownLatch (java.util.concurrent.CountDownLatch)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)39 AssertTask (com.hazelcast.test.AssertTask)36 MapStoreConfig (com.hazelcast.config.MapStoreConfig)34 MapConfig (com.hazelcast.config.MapConfig)31 TransactionalMap (com.hazelcast.core.TransactionalMap)29 IExecutorService (com.hazelcast.core.IExecutorService)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)27 TransactionContext (com.hazelcast.transaction.TransactionContext)21 TransactionException (com.hazelcast.transaction.TransactionException)21