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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations