Пример #1
0
 @Before
 public void setup() throws IOException {
   hazelcastFactory = new TestHazelcastFactory();
   hazelcastFactory.newHazelcastInstance();
   HazelcastInstance client = hazelcastFactory.newHazelcastClient();
   set = client.getSet(randomString());
 }
  @Test(timeout = 60000)
  public void testMapReduceWithSet() 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();

    int expectedResult = 0;
    ISet<Integer> set = h1.getSet("default");
    for (int o = 0; o < 100; o++) {
      set.add(o);
      expectedResult += o;
    }

    JobTracker jobTracker = client.getJobTracker("default");
    Job<String, Integer> job = jobTracker.newJob(KeyValueSource.fromSet(set));
    ICompletableFuture<Map<String, Integer>> ICompletableFuture =
        job.chunkSize(10)
            .mapper(new ListSetMapReduceTest.ListSetMapper())
            .combiner(new ListSetMapReduceTest.ListSetCombinerFactory())
            .reducer(new ListSetMapReduceTest.ListSetReducerFactory())
            .submit();

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

    assertEquals(1, result.size());

    for (Map.Entry<String, Integer> entry : result.entrySet()) {
      assertEquals(set.getName(), entry.getKey());
      assertEquals(expectedResult, (int) entry.getValue());
    }
  }
Пример #3
0
 public ISet<Object> getSet() {
   //        if (set == null) {
   set = hazelcast.getSet(namespace);
   //        }
   return set;
 }
Пример #4
0
 public HazelcastVisited(String visitedName, HazelcastInstance hazelcastInstance) {
   this.visited = hazelcastInstance.getSet(visitedName);
 }