InterResults { public static int load(FileSystem fs, Path forestPath, int numMaps, int numTrees, int partition, TreeID[] keys, Node[] trees) throws IOException { Preconditions.checkArgument(keys.length == trees.length, "keys.length != trees.length"); FSDataInputStream in = fs.open(forestPath); TreeID key = new TreeID(); int numInstances = -1; try { for (int p = 0; p < numMaps; p++) { if (p == partition) { numInstances = in.readInt(); } else { in.readInt(); } } int current = 0; for (int index = 0; index < numTrees; index++) { key.readFields(in); if (key.partition() == partition) { Node.read(in); } else { keys[current] = key.clone(); trees[current] = Node.read(in); current++; } } if (current != keys.length) { throw new IllegalStateException("loaded less keys/trees than expected"); } } finally { in.close(); } return numInstances; } private  InterResults(); static int load(FileSystem fs,
                         Path forestPath,
                         int numMaps,
                         int numTrees,
                         int partition,
                         TreeID[] keys,
                         Node[] trees); static void store(FileSystem fs,
                           Path forestPath,
                           TreeID[] keys,
                           Node[] trees,
                           int[] sizes);  }
@Test public void testLoad() throws Exception { Path forestPath = new Path("testdata/InterResultsTest/test.forest"); FileSystem fs = forestPath.getFileSystem(new Configuration()); InterResults.store(fs, forestPath, keys, trees, sizes); for (int partition = 0; partition < NUM_MAPPERS; partition++) { int nbConcerned = Step2Mapper.nbConcerned(NUM_MAPPERS, NUM_TREES, partition); TreeID[] newKeys = new TreeID[nbConcerned]; Node[] newValues = new Node[nbConcerned]; int numInstances = InterResults.load(fs, forestPath, NUM_MAPPERS, NUM_TREES, partition, newKeys, newValues); assertEquals(splits[partition].length, numInstances); int current = 0; for (int index = 0; index < NUM_TREES; index++) { if (current < nbConcerned) { assertFalse("A tree from the current partition has been loaded", newKeys[current].partition() == partition); } if (keys[index].partition() == partition) { continue; } assertEquals("index: " + index, keys[index], newKeys[current]); assertEquals("index: " + index, trees[index], newValues[current]); current++; } } }