use of org.apache.storm.testing.TupleCaptureBolt in project storm by apache.
the class Testing method captureTopology.
/**
* Rewrites a topology so that all the tuples flowing through it are captured
* @param topology the topology to rewrite
* @return the modified topology and a new Bolt that can retrieve the
* captured tuples.
*/
public static CapturedTopology<StormTopology> captureTopology(StormTopology topology) {
//Don't modify the original
topology = topology.deepCopy();
TupleCaptureBolt capturer = new TupleCaptureBolt();
Map<GlobalStreamId, Grouping> captureBoltInputs = new HashMap<>();
for (Map.Entry<String, SpoutSpec> spoutEntry : topology.get_spouts().entrySet()) {
String id = spoutEntry.getKey();
for (Entry<String, StreamInfo> streamEntry : spoutEntry.getValue().get_common().get_streams().entrySet()) {
String stream = streamEntry.getKey();
StreamInfo info = streamEntry.getValue();
if (info.is_direct()) {
captureBoltInputs.put(new GlobalStreamId(id, stream), Thrift.prepareDirectGrouping());
} else {
captureBoltInputs.put(new GlobalStreamId(id, stream), Thrift.prepareGlobalGrouping());
}
}
}
for (Entry<String, Bolt> boltEntry : topology.get_bolts().entrySet()) {
String id = boltEntry.getKey();
for (Entry<String, StreamInfo> streamEntry : boltEntry.getValue().get_common().get_streams().entrySet()) {
String stream = streamEntry.getKey();
StreamInfo info = streamEntry.getValue();
if (info.is_direct()) {
captureBoltInputs.put(new GlobalStreamId(id, stream), Thrift.prepareDirectGrouping());
} else {
captureBoltInputs.put(new GlobalStreamId(id, stream), Thrift.prepareGlobalGrouping());
}
}
}
topology.put_to_bolts(Utils.uuid(), new Bolt(Thrift.serializeComponentObject(capturer), Thrift.prepareComponentCommon(captureBoltInputs, new HashMap<>(), null)));
return new CapturedTopology<>(topology, capturer);
}
Aggregations