Example #1
0
  @Test(timeout = 30000)
  public void testNullFromObjectCombiner() throws Exception {

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);

    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();

    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(KeyValueSource.fromMap(m1));
    JobCompletableFuture<Map<String, BigInteger>> future =
        job.chunkSize(1)
            .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)));
    }
  }
  @Test(timeout = 60000)
  public void testMapReduceWithCustomKeyValueSource() throws Exception {

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);

    final HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    final HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    final HazelcastInstance h3 = nodeFactory.newHazelcastInstance();

    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);

    JobTracker jobTracker = h1.getJobTracker("default");
    Job<String, Integer> job = jobTracker.newJob(new CustomKeyValueSource());
    ICompletableFuture<Map<String, Integer>> completableFuture =
        job.chunkSize(10)
            .mapper(new CustomMapper())
            .combiner(new CustomCombinerFactory())
            .reducer(new CustomReducerFactory())
            .submit();

    Map<String, Integer> result = completableFuture.get();

    assertEquals(1000, result.size());

    List<Map.Entry<String, Integer>> entrySet = new ArrayList(result.entrySet());
    Collections.sort(entrySet, ENTRYSET_COMPARATOR);

    int count = 0;
    for (Map.Entry<String, Integer> entry : entrySet) {
      assertEquals(String.valueOf(count), entry.getKey());
      assertEquals(count++ * 6, (int) entry.getValue());
    }
  }
Example #3
0
  @Test(timeout = 60000)
  public void testMapperReducerChunked() throws Exception {

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);

    final HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    final HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    final HazelcastInstance h3 = nodeFactory.newHazelcastInstance();

    assertClusterSizeEventually(3, h1);

    final 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(KeyValueSource.fromMap(m1));
    JobCompletableFuture<Map<String, Integer>> future =
        job.chunkSize(10)
            .mapper(new GroupingTestMapper())
            .reducer(new TestReducerFactory())
            .submit();

    final TrackableJob trackableJob = tracker.getTrackableJob(future.getJobId());
    final JobProcessInformation processInformation = trackableJob.getJobProcessInformation();
    Map<String, Integer> result = future.get();

    // Precalculate 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());
          }
        });
  }