Search in sources :

Example 1 with BranchProcessor

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);
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Grouping(org.apache.storm.generated.Grouping) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) BranchProcessor(org.apache.storm.streams.processors.BranchProcessor) NullStruct(org.apache.storm.generated.NullStruct) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)1 Grouping (org.apache.storm.generated.Grouping)1 NullStruct (org.apache.storm.generated.NullStruct)1 StormTopology (org.apache.storm.generated.StormTopology)1 BranchProcessor (org.apache.storm.streams.processors.BranchProcessor)1 Tuple (org.apache.storm.tuple.Tuple)1 Test (org.junit.Test)1