Search in sources :

Example 6 with GlobalStreamId

use of org.apache.storm.generated.GlobalStreamId in project storm by apache.

the class TridentTopologyBuilder method getBoltSubscriptionStreams.

List<GlobalStreamId> getBoltSubscriptionStreams(String id) {
    List<GlobalStreamId> ret = new ArrayList();
    Component c = _bolts.get(id);
    for (InputDeclaration d : c.declarations) {
        ret.add(new GlobalStreamId(d.getComponent(), d.getStream()));
    }
    return ret;
}
Also used : GlobalStreamId(org.apache.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList)

Example 7 with GlobalStreamId

use of org.apache.storm.generated.GlobalStreamId in project storm by apache.

the class ProcessorBoltTest method setUpProcessorBolt.

private void setUpProcessorBolt(Processor<?> processor, Set<String> windowedParentStreams, boolean isWindowed, String tsFieldName) {
    ProcessorNode node = new ProcessorNode(processor, "outputstream", new Fields("value"));
    node.setWindowedParentStreams(windowedParentStreams);
    node.setWindowed(isWindowed);
    Mockito.when(mockStreamToProcessors.get(Mockito.anyString())).thenReturn(Collections.singletonList(node));
    Mockito.when(mockStreamToProcessors.keySet()).thenReturn(Collections.singleton("inputstream"));
    Map mockSources = Mockito.mock(Map.class);
    GlobalStreamId mockGlobalStreamId = Mockito.mock(GlobalStreamId.class);
    Mockito.when(mockTopologyContext.getThisSources()).thenReturn(mockSources);
    Mockito.when(mockSources.keySet()).thenReturn(Collections.singleton(mockGlobalStreamId));
    Mockito.when(mockGlobalStreamId.get_streamId()).thenReturn("inputstream");
    Mockito.when(mockGlobalStreamId.get_componentId()).thenReturn("bolt0");
    Mockito.when(mockTopologyContext.getComponentTasks(Mockito.anyString())).thenReturn(Collections.singletonList(1));
    graph.addVertex(node);
    bolt = new ProcessorBolt("bolt1", graph, Collections.singletonList(node));
    if (tsFieldName != null && !tsFieldName.isEmpty()) {
        bolt.setTimestampField(tsFieldName);
    }
    bolt.setStreamToInitialProcessors(mockStreamToProcessors);
    bolt.prepare(new HashMap<>(), mockTopologyContext, mockOutputCollector);
}
Also used : Fields(org.apache.storm.tuple.Fields) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with GlobalStreamId

use of org.apache.storm.generated.GlobalStreamId 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)

Example 9 with GlobalStreamId

use of org.apache.storm.generated.GlobalStreamId in project storm by apache.

the class StreamBuilderTest method testMultiPartitionByKeyWithRepartition.

@Test
public void testMultiPartitionByKeyWithRepartition() {
    TopologyContext mockContext = Mockito.mock(TopologyContext.class);
    OutputCollector mockCollector = Mockito.mock(OutputCollector.class);
    Map<GlobalStreamId, Grouping> expected = new HashMap<>();
    expected.put(new GlobalStreamId("bolt2", "s3"), Grouping.fields(Collections.singletonList("key")));
    expected.put(new GlobalStreamId("bolt2", "s3__punctuation"), Grouping.all(new NullStruct()));
    Stream<Integer> stream = streamBuilder.newStream(newSpout(Utils.DEFAULT_STREAM_ID), new ValueMapper<>(0));
    stream.mapToPair(x -> Pair.of(x, x)).window(TumblingWindows.of(BaseWindowedBolt.Count.of(10))).reduceByKey((x, y) -> x + y).repartition(10).reduceByKey((x, y) -> 0).print();
    StormTopology topology = streamBuilder.build();
    assertEquals(3, topology.get_bolts_size());
    assertEquals(expected, topology.get_bolts().get("bolt3").get_common().get_inputs());
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) IRichSpout(org.apache.storm.topology.IRichSpout) BaseWindowedBolt(org.apache.storm.topology.base.BaseWindowedBolt) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Count(org.apache.storm.streams.operations.aggregators.Count) Bolt(org.apache.storm.generated.Bolt) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) StormTopology(org.apache.storm.generated.StormTopology) BranchProcessor(org.apache.storm.streams.processors.BranchProcessor) Map(java.util.Map) ValueMapper(org.apache.storm.streams.operations.mappers.ValueMapper) Before(org.junit.Before) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) PairValueMapper(org.apache.storm.streams.operations.mappers.PairValueMapper) Grouping(org.apache.storm.generated.Grouping) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Fields(org.apache.storm.tuple.Fields) Utils(org.apache.storm.utils.Utils) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Mockito(org.mockito.Mockito) TumblingWindows(org.apache.storm.streams.windowing.TumblingWindows) SpoutSpec(org.apache.storm.generated.SpoutSpec) IRichBolt(org.apache.storm.topology.IRichBolt) NullStruct(org.apache.storm.generated.NullStruct) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) OutputCollector(org.apache.storm.task.OutputCollector) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) HashMap(java.util.HashMap) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) StormTopology(org.apache.storm.generated.StormTopology) Grouping(org.apache.storm.generated.Grouping) TopologyContext(org.apache.storm.task.TopologyContext) NullStruct(org.apache.storm.generated.NullStruct) Test(org.junit.Test)

Example 10 with GlobalStreamId

use of org.apache.storm.generated.GlobalStreamId in project storm by apache.

the class StatefulBoltExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    mockBolt = Mockito.mock(IStatefulBolt.class);
    executor = new StatefulBoltExecutor<>(mockBolt);
    GlobalStreamId mockGlobalStreamId = Mockito.mock(GlobalStreamId.class);
    Mockito.when(mockGlobalStreamId.get_streamId()).thenReturn(CheckpointSpout.CHECKPOINT_STREAM_ID);
    mockStreamIds = new HashSet<>();
    mockStreamIds.add(mockGlobalStreamId);
    mockTopologyContext = Mockito.mock(TopologyContext.class);
    mockOutputCollector = Mockito.mock(OutputCollector.class);
    mockGlobalStream = Mockito.mock(Map.class);
    mockState = Mockito.mock(State.class);
    Mockito.when(mockTopologyContext.getThisComponentId()).thenReturn("test");
    Mockito.when(mockTopologyContext.getThisTaskId()).thenReturn(1);
    Mockito.when(mockTopologyContext.getThisSources()).thenReturn(mockGlobalStream);
    Mockito.when(mockTopologyContext.getComponentTasks(Mockito.anyString())).thenReturn(Collections.singletonList(1));
    Mockito.when(mockGlobalStream.keySet()).thenReturn(mockStreamIds);
    mockTuple = Mockito.mock(Tuple.class);
    mockCheckpointTuple = Mockito.mock(Tuple.class);
    executor.prepare(mockStormConf, mockTopologyContext, mockOutputCollector, mockState);
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) State(org.apache.storm.state.State) KeyValueState(org.apache.storm.state.KeyValueState) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) TopologyContext(org.apache.storm.task.TopologyContext) IStatefulBolt(org.apache.storm.topology.IStatefulBolt) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) Before(org.junit.Before)

Aggregations

GlobalStreamId (org.apache.storm.generated.GlobalStreamId)37 HashMap (java.util.HashMap)21 Grouping (org.apache.storm.generated.Grouping)16 Map (java.util.Map)13 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 Bolt (org.apache.storm.generated.Bolt)7 Tuple (org.apache.storm.tuple.Tuple)7 StormTopology (org.apache.storm.generated.StormTopology)6 HashSet (java.util.HashSet)5 ComponentCommon (org.apache.storm.generated.ComponentCommon)4 NullStruct (org.apache.storm.generated.NullStruct)4 SpoutSpec (org.apache.storm.generated.SpoutSpec)4 StreamInfo (org.apache.storm.generated.StreamInfo)4 TopologyContext (org.apache.storm.task.TopologyContext)4 IRichSpout (org.apache.storm.topology.IRichSpout)4 Fields (org.apache.storm.tuple.Fields)4 TreeMap (java.util.TreeMap)3 OutputCollector (org.apache.storm.task.OutputCollector)3 IRichBolt (org.apache.storm.topology.IRichBolt)3