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