@Test
public void testProcessOutput() throws Exception {

  Configuration conf = getConfiguration();
  conf.setInt("mapred.map.tasks", NUM_MAPS);
  Random rng = RandomUtils.getRandom();
  // prepare the output
  TreeID[] keys = new TreeID[NUM_TREES];
  MapredOutput[] values = new MapredOutput[NUM_TREES];
  int[] firstIds = new int[NUM_MAPS];
  randomKeyValues(rng, keys, values, firstIds);
  // store the output in a sequence file
  Path base = getTestTempDirPath("testdata");
  FileSystem fs = base.getFileSystem(conf);
  Path outputFile = new Path(base, "PartialBuilderTest.seq");
  Writer writer = SequenceFile.createWriter(fs, conf, outputFile,
      TreeID.class, MapredOutput.class);
  try {
    for (int index = 0; index < NUM_TREES; index++) {
      writer.append(keys[index], values[index]);
    }
  } finally {
    Closeables.close(writer, false);
  }
  // load the output and make sure its valid
  TreeID[] newKeys = new TreeID[NUM_TREES];
  Node[] newTrees = new Node[NUM_TREES];
  
  PartialBuilder.processOutput(new Job(conf), base, newKeys, newTrees);
  // check the forest
  for (int tree = 0; tree < NUM_TREES; tree++) {
    assertEquals(values[tree].getTree(), newTrees[tree]);
  }
  assertTrue("keys not equal", Arrays.deepEquals(keys, newKeys));
}