.build(mapper, conf, mapWriter);
mapper.setup(mapContext);
// map the data
for (MeanShiftCanopy canopy : canopies) {
ClusterWritable clusterWritable = new ClusterWritable();
clusterWritable.setValue(canopy);
mapper.map(new Text(), clusterWritable, mapContext);
}
mapper.cleanup(mapContext);
assertEquals("Number of map results", 1, mapWriter.getData().size());
// now reduce the mapper output
MeanShiftCanopyReducer reducer = new MeanShiftCanopyReducer();
DummyRecordWriter<Text, ClusterWritable> reduceWriter = new DummyRecordWriter<Text, ClusterWritable>();
Reducer<Text, ClusterWritable, Text, ClusterWritable>.Context reduceContext = DummyRecordWriter
.build(reducer, conf, reduceWriter, Text.class, ClusterWritable.class);
reducer.setup(reduceContext);
reducer.reduce(new Text("0"), mapWriter.getValue(new Text("0")),
reduceContext);
reducer.cleanup(reduceContext);
// now verify the output
assertEquals("Number of canopies", reducerReference.size(), reduceWriter
.getKeys().size());
// add all points to the reference canopy maps
Map<String, MeanShiftCanopy> reducerReferenceMap = Maps.newHashMap();
for (MeanShiftCanopy canopy : reducerReference) {
reducerReferenceMap.put(canopy.getIdentifier(), canopy);
}
// compare the maps
for (Map.Entry<String, MeanShiftCanopy> mapEntry : reducerReferenceMap
.entrySet()) {
MeanShiftCanopy refCanopy = mapEntry.getValue();
List<ClusterWritable> values = reduceWriter.getValue(new Text((refCanopy
.isConverged() ? "MSV-" : "MSC-")
+ refCanopy.getId()));
assertEquals("values", 1, values.size());
ClusterWritable clusterWritable = values.get(0);
MeanShiftCanopy reducerCanopy = (MeanShiftCanopy) clusterWritable.getValue();
assertEquals("ids", refCanopy.getId(), reducerCanopy.getId());
long refNumPoints = refCanopy.getNumObservations();
long reducerNumPoints = reducerCanopy.getNumObservations();
assertEquals("numPoints", refNumPoints, reducerNumPoints);
String refCenter = refCanopy.getCenter().asFormatString();