Search in sources :

Example 31 with Tuple

use of org.apache.storm.tuple.Tuple in project storm by apache.

the class ProcessorBoltTest method setUpMockTuples.

private void setUpMockTuples(Tuple... tuples) {
    for (Tuple tuple : tuples) {
        Mockito.when(tuple.size()).thenReturn(1);
        Mockito.when(tuple.getValue(0)).thenReturn(100);
        Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
        Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
    }
}
Also used : Tuple(org.apache.storm.tuple.Tuple)

Example 32 with Tuple

use of org.apache.storm.tuple.Tuple 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 33 with Tuple

use of org.apache.storm.tuple.Tuple in project storm by apache.

the class WindowedProcessorBoltTest method setUpMockTuples.

private void setUpMockTuples(Tuple... tuples) {
    for (Tuple tuple : tuples) {
        Mockito.when(tuple.size()).thenReturn(1);
        Mockito.when(tuple.getValue(0)).thenReturn(100);
        Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0");
        Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream");
    }
}
Also used : Tuple(org.apache.storm.tuple.Tuple)

Example 34 with Tuple

use of org.apache.storm.tuple.Tuple in project storm by apache.

the class StatefulWindowedBoltExecutorTest method getMockTuples.

private List<Tuple> getMockTuples(int count) {
    List<Tuple> mockTuples = new ArrayList<>();
    for (long i = 0; i < count; i++) {
        Tuple mockTuple = Mockito.mock(Tuple.class);
        Mockito.when(mockTuple.getLongByField("msgid")).thenReturn(i);
        Mockito.when(mockTuple.getSourceTask()).thenReturn(1);
        Mockito.when(mockTuple.getSourceGlobalStreamId()).thenReturn(new GlobalStreamId("a", "s"));
        mockTuples.add(mockTuple);
    }
    return mockTuples;
}
Also used : GlobalStreamId(org.apache.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList) Tuple(org.apache.storm.tuple.Tuple)

Example 35 with Tuple

use of org.apache.storm.tuple.Tuple in project storm by apache.

the class MockTupleHelpers method mockTuple.

public static Tuple mockTuple(String componentId, String streamId) {
    Tuple tuple = Mockito.mock(Tuple.class);
    Mockito.when(tuple.getSourceComponent()).thenReturn(componentId);
    Mockito.when(tuple.getSourceStreamId()).thenReturn(streamId);
    return tuple;
}
Also used : Tuple(org.apache.storm.tuple.Tuple)

Aggregations

Tuple (org.apache.storm.tuple.Tuple)85 Test (org.junit.Test)30 Fields (org.apache.storm.tuple.Fields)13 OutputCollector (org.apache.storm.task.OutputCollector)11 Values (org.apache.storm.tuple.Values)11 ArrayList (java.util.ArrayList)10 HiveOptions (org.apache.storm.hive.common.HiveOptions)10 TupleWindow (org.apache.storm.windowing.TupleWindow)9 HashMap (java.util.HashMap)7 Test (org.testng.annotations.Test)7 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)6 DelimitedRecordHiveMapper (org.apache.storm.hive.bolt.mapper.DelimitedRecordHiveMapper)6 HashSet (java.util.HashSet)5 JsonRecordHiveMapper (org.apache.storm.hive.bolt.mapper.JsonRecordHiveMapper)5 TopologyContext (org.apache.storm.task.TopologyContext)5 TupleImpl (org.apache.storm.tuple.TupleImpl)5 BasicOutputCollector (org.apache.storm.topology.BasicOutputCollector)4 Map (java.util.Map)3 Callback (org.apache.kafka.clients.producer.Callback)3 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)3