Search in sources :

Example 36 with OutputCollector

use of org.apache.storm.task.OutputCollector in project storm by apache.

the class RollingCountBoltTest method shouldEmitSomethingIfAtLeastOneObjectWasCountedAndTickTupleIsReceived.

@SuppressWarnings("rawtypes")
@Test
public void shouldEmitSomethingIfAtLeastOneObjectWasCountedAndTickTupleIsReceived() {
    // given
    Tuple normalTuple = mockNormalTuple(new Object());
    Tuple tickTuple = MockTupleHelpers.mockTickTuple();
    RollingCountBolt bolt = new RollingCountBolt();
    Map<String, Object> conf = mock(Map.class);
    TopologyContext context = mock(TopologyContext.class);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(conf, context, collector);
    // when
    bolt.execute(normalTuple);
    bolt.execute(tickTuple);
    // then
    verify(collector).emit(any(Values.class));
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) Values(org.apache.storm.tuple.Values) TopologyContext(org.apache.storm.task.TopologyContext) Tuple(org.apache.storm.tuple.Tuple) Test(org.testng.annotations.Test)

Example 37 with OutputCollector

use of org.apache.storm.task.OutputCollector in project metron by apache.

the class ErrorUtilsTest method handleErrorShouldEmitAndReportError.

@Test
public void handleErrorShouldEmitAndReportError() {
    Throwable e = new Exception("error");
    MetronError error = new MetronError().withMessage("error message").withThrowable(e);
    OutputCollector collector = mock(OutputCollector.class);
    StormErrorUtils.handleError(collector, error);
    verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject())));
    verify(collector, times(1)).reportError(any());
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) MetronErrorJSONMatcher(org.apache.metron.test.error.MetronErrorJSONMatcher) MetronError(org.apache.metron.common.error.MetronError) Test(org.junit.jupiter.api.Test)

Example 38 with OutputCollector

use of org.apache.storm.task.OutputCollector in project metron by apache.

the class StormParserDriver method run.

public ProcessorResult<List<byte[]>> run(Iterable<byte[]> in) {
    ShimParserBolt bolt = new ShimParserBolt(new ArrayList<>());
    byte[] b = SerializationUtils.serialize(bolt);
    ShimParserBolt b2 = (ShimParserBolt) SerializationUtils.deserialize(b);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(null, null, collector);
    for (byte[] record : in) {
        Tuple tuple = toTuple(record);
        bolt.execute(tuple);
        verify(collector, times(1)).ack(tuple);
    }
    return bolt.getResults();
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) Tuple(org.apache.storm.tuple.Tuple)

Aggregations

OutputCollector (org.apache.storm.task.OutputCollector)38 Tuple (org.apache.storm.tuple.Tuple)21 TopologyContext (org.apache.storm.task.TopologyContext)20 Test (org.junit.Test)19 HashMap (java.util.HashMap)16 Fields (org.apache.storm.tuple.Fields)11 Map (java.util.Map)9 IOutputCollector (org.apache.storm.task.IOutputCollector)8 HiveOptions (org.apache.storm.hive.common.HiveOptions)6 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)5 Grouping (org.apache.storm.generated.Grouping)5 Before (org.junit.Before)5 Collections (java.util.Collections)4 Bolt (org.apache.storm.generated.Bolt)4 NullStruct (org.apache.storm.generated.NullStruct)4 SpoutSpec (org.apache.storm.generated.SpoutSpec)4 StormTopology (org.apache.storm.generated.StormTopology)4 JsonRecordHiveMapper (org.apache.storm.hive.bolt.mapper.JsonRecordHiveMapper)4 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)4 Count (org.apache.storm.streams.operations.aggregators.Count)4