Search in sources :

Example 6 with OutputCollector

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

the class TestNiFiBolt method testTickTupleWhenExceedingBatchInterval.

@Test
public void testTickTupleWhenExceedingBatchInterval() throws InterruptedException {
    final int batchInterval = 1;
    final NiFiBolt bolt = new TestableNiFiBolt(siteToSiteClientConfig, niFiDataPacketBuilder, tickFrequency).withBatchInterval(batchInterval);
    // prepare the bolt
    Map conf = mock(Map.class);
    TopologyContext context = mock(TopologyContext.class);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(conf, context, collector);
    // process a regular tuple
    Tuple dataTuple = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple);
    // sleep so we pass the batch interval
    Thread.sleep(batchInterval + 1000);
    // process a tick tuple
    Tuple tickTuple = MockTupleHelpers.mockTickTuple();
    bolt.execute(tickTuple);
    // should have produced one data packet and acked it
    verify(niFiDataPacketBuilder, times(1)).createNiFiDataPacket(eq(dataTuple));
    verify(collector, times(1)).ack(eq(dataTuple));
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 7 with OutputCollector

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

the class TestNiFiBolt method testBatchSize.

@Test
public void testBatchSize() {
    final int batchSize = 3;
    final NiFiBolt bolt = new TestableNiFiBolt(siteToSiteClientConfig, niFiDataPacketBuilder, tickFrequency).withBatchSize(batchSize);
    // prepare the bolt
    Map conf = mock(Map.class);
    TopologyContext context = mock(TopologyContext.class);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(conf, context, collector);
    // process a regular tuple, haven't hit batch size yet
    Tuple dataTuple1 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple1);
    verifyZeroInteractions(niFiDataPacketBuilder);
    // process a regular tuple, haven't hit batch size yet
    Tuple dataTuple2 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple2);
    verifyZeroInteractions(niFiDataPacketBuilder);
    // process a regular tuple, triggers batch size
    Tuple dataTuple3 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple3);
    verify(niFiDataPacketBuilder, times(batchSize)).createNiFiDataPacket(any(Tuple.class));
    verify(collector, times(batchSize)).ack(any(Tuple.class));
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 8 with OutputCollector

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

the class TestNiFiBolt method testFailure.

@Test
public void testFailure() throws IOException {
    final int batchSize = 3;
    final NiFiBolt bolt = new TestableNiFiBolt(siteToSiteClientConfig, niFiDataPacketBuilder, tickFrequency).withBatchSize(batchSize);
    when(((TestableNiFiBolt) bolt).transaction.complete()).thenThrow(new RuntimeException("Could not complete transaction"));
    // prepare the bolt
    Map conf = mock(Map.class);
    TopologyContext context = mock(TopologyContext.class);
    OutputCollector collector = mock(OutputCollector.class);
    bolt.prepare(conf, context, collector);
    // process a regular tuple, haven't hit batch size yet
    Tuple dataTuple1 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple1);
    verifyZeroInteractions(niFiDataPacketBuilder);
    // process a regular tuple, haven't hit batch size yet
    Tuple dataTuple2 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple2);
    verifyZeroInteractions(niFiDataPacketBuilder);
    // process a regular tuple, triggers batch size
    Tuple dataTuple3 = MockTupleHelpers.mockTuple("nifi", "nifi");
    bolt.execute(dataTuple3);
    verify(niFiDataPacketBuilder, times(batchSize)).createNiFiDataPacket(any(Tuple.class));
    verify(collector, times(batchSize)).fail(any(Tuple.class));
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 9 with OutputCollector

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

the class ErrorUtilsTest method handleErrorShouldEmitAndReportError.

@Test
public void handleErrorShouldEmitAndReportError() throws Exception {
    Throwable e = new Exception("error");
    MetronError error = new MetronError().withMessage("error message").withThrowable(e);
    OutputCollector collector = mock(OutputCollector.class);
    ErrorUtils.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) IOException(java.io.IOException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 10 with OutputCollector

use of org.apache.storm.task.OutputCollector in project incubator-pulsar by apache.

the class PulsarBoltTest method testSharedProducer.

@Test
public void testSharedProducer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    PulsarBolt otherBolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    MockOutputCollector otherMockCollector = new MockOutputCollector();
    OutputCollector collector = new OutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-bolt-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherBolt.prepare(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    otherBolt.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(org.apache.storm.task.TopologyContext) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

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