hunk.code_window: Getting Involved
   ----------------
   - Ask questions on our mailing list `ray-dev@googlegroups.com`_.
   - Please report bugs by submitting a `GitHub issue`_.
   - Submit contributions using `pull requests`_.
   .. _`ray-dev@googlegroups.com`: https://groups.google.com/forum/#!forum/ray-dev
  
hunk.labels: keep keep keep keep replace replace replace keep keep
hunk.after_edit: - `ray-dev@googlegroups.com`_: For discussions about development or any general
     questions.
   - `StackOverflow`_: For questions about how to use Ray.
   - `GitHub Issues`_: For reporting bugs and feature requests.
   - `Pull Requests`_: For submitting code contributions.
  
hunk.file_path: README.rst
hunk.type: replace
file: package org.ray.api.test;
  
  import java.io.FileNotFoundException;
  import java.util.Arrays;
  import java.util.List;
  import org.ray.api.Ray;
  import org.ray.api.RayObject;
  import org.ray.api.annotation.RayRemote;
  import org.ray.runtime.util.FileUtil;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  /**
   * given a directory of document files on each "machine", we would like to count the appearance of
   * some word.
   */
  public class WordCountTest {
  
    @RayRemote
    public static List<String> getMachineList() {
      return Arrays.asList("A", "B", "C");
    }
  
    @RayRemote
    public static Integer countWord(String machine, String word) {
  
      String log;
      try {
        log = FileUtil.readResourceFile("mapreduce/" + machine + ".log");
      } catch (FileNotFoundException e) {
        e.printStackTrace();
        log = "";
      }
      log = log.toLowerCase();
      int start = 0;
      int count = 0;
      while (true) {
        if (start >= log.length()) {
          break;
        }
        int index = log.indexOf(word, start);
        if (index == -1) {
          break;
        }
        start = index + word.length();
        count++;
      }
      return count;
    }
  
    @RayRemote
    public static Integer sum(Integer a, Integer/*TODO modify int to Integer in ASM hook*/ b) {
      return a + b;
    }
  
    //@Test
    public void test() {
      int sum = mapReduce();
      Assert.assertEquals(sum, 143);
    }
  
    public int mapReduce() {
      RayObject<List<String>> machines = Ray.call(WordCountTest::getMachineList);
      RayObject<Integer> total = null;
      for (String machine : machines.get()) {
        RayObject<Integer> wordcount = Ray.call(WordCountTest::countWord, machine, "ray");
        if (total == null) {
          total = wordcount;
        } else {
          total = Ray.call(WordCountTest::sum, total, wordcount);
        }
      }
      return total.get();
    }
  }
  