// Check that the results from the MapReduce were as expected.
FileSystem fileSystem = FileSystem.get(job.getConfiguration());
FileStatus[] outputFiles = fileSystem.globStatus(outputPath.suffix("/myavro-r-00000.avro"));
Assert.assertEquals(1, outputFiles.length);
DataFileReader<GenericData.Record> reader = new DataFileReader<GenericData.Record>(
new FsInput(outputFiles[0].getPath(), job.getConfiguration()),
new GenericDatumReader<GenericData.Record>(STATS_SCHEMA));
Map<String, Integer> counts = new HashMap<String, Integer>();
for (GenericData.Record record : reader) {
counts.put(((Utf8) record.get("name")).toString(), (Integer) record.get("count"));
}
reader.close();
Assert.assertEquals(3, counts.get("apple").intValue());
Assert.assertEquals(2, counts.get("banana").intValue());
Assert.assertEquals(1, counts.get("carrot").intValue());
outputFiles = fileSystem.globStatus(outputPath.suffix("/myavro1-r-00000.avro"));
Assert.assertEquals(1, outputFiles.length);
reader = new DataFileReader<GenericData.Record>(
new FsInput(outputFiles[0].getPath(), job.getConfiguration()),
new GenericDatumReader<GenericData.Record>(STATS_SCHEMA_2));
counts = new HashMap<String, Integer>();
for (GenericData.Record record : reader) {
counts.put(((Utf8) record.get("name1")).toString(), (Integer) record.get("count1"));
}