use of org.apache.storm.streams.processors.BranchProcessor in project storm by apache.
the class StreamBuilderTest method testBranch.
@Test
public void testBranch() throws Exception {
Stream<Tuple> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID));
Stream<Tuple>[] streams = stream.branch(x -> true);
StormTopology topology = streamBuilder.build();
assertEquals(1, topology.get_spouts_size());
assertEquals(1, topology.get_bolts_size());
Map<GlobalStreamId, Grouping> expected = new HashMap<>();
String spoutId = topology.get_spouts().keySet().iterator().next();
expected.put(new GlobalStreamId(spoutId, "default"), Grouping.shuffle(new NullStruct()));
assertEquals(expected, topology.get_bolts().values().iterator().next().get_common().get_inputs());
assertEquals(1, streams.length);
assertEquals(1, streams[0].node.getOutputStreams().size());
String parentStream = streams[0].node.getOutputStreams().iterator().next() + "-branch";
assertEquals(1, streams[0].node.getParents(parentStream).size());
Node processorNdoe = streams[0].node.getParents(parentStream).iterator().next();
assertTrue(processorNdoe instanceof ProcessorNode);
assertTrue(((ProcessorNode) processorNdoe).getProcessor() instanceof BranchProcessor);
assertTrue(processorNdoe.getParents("default").iterator().next() instanceof SpoutNode);
}
Aggregations