use of org.apache.storm.task.OutputCollector in project storm by apache.
the class KafkaBoltTest method generateStringSerializerBolt.
private KafkaBolt generateStringSerializerBolt() {
Properties props = new Properties();
props.put("acks", "1");
props.put("bootstrap.servers", broker.getBrokerConnectionString());
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("metadata.fetch.timeout.ms", 1000);
KafkaBolt bolt = new KafkaBolt().withProducerProperties(props);
bolt.prepare(config, null, new OutputCollector(collector));
bolt.setAsync(false);
return bolt;
}
use of org.apache.storm.task.OutputCollector in project storm by apache.
the class BoltExecutor method init.
public void init(Map<Integer, Task> idToTask) {
while (!stormActive.get()) {
Utils.sleep(100);
}
LOG.info("Preparing bolt {}:{}", componentId, idToTask.keySet());
for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
Task taskData = entry.getValue();
IBolt boltObject = (IBolt) taskData.getTaskObject();
TopologyContext userContext = taskData.getUserContext();
taskData.getBuiltInMetrics().registerAll(stormConf, userContext);
if (boltObject instanceof ICredentialsListener) {
((ICredentialsListener) boltObject).setCredentials(credentials);
}
if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue, "transfer", workerData.getTransferQueue());
BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
Map cachedNodePortToSocket = (Map) workerData.getCachedNodeToPortSocket().get();
BuiltinMetricsUtil.registerIconnectionClientMetrics(cachedNodePortToSocket, stormConf, userContext);
BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), stormConf, userContext);
} else {
Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
}
IOutputCollector outputCollector = new BoltOutputCollectorImpl(this, taskData, entry.getKey(), rand, hasEventLoggers, isDebug);
boltObject.prepare(stormConf, userContext, new OutputCollector(outputCollector));
}
openOrPrepareWasCalled.set(true);
LOG.info("Prepared bolt {}:{}", componentId, idToTask.keySet());
setupMetrics();
}
use of org.apache.storm.task.OutputCollector in project nifi by apache.
the class TestNiFiBolt method testTickTupleWhenNotExceedingBatchInterval.
@Test
public void testTickTupleWhenNotExceedingBatchInterval() {
final NiFiBolt bolt = new TestableNiFiBolt(siteToSiteClientConfig, niFiDataPacketBuilder, tickFrequency);
// 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);
// process a tick tuple
Tuple tickTuple = MockTupleHelpers.mockTickTuple();
bolt.execute(tickTuple);
// should not have produced any NiFiDataPackets
verifyZeroInteractions(niFiDataPacketBuilder);
}
use of org.apache.storm.task.OutputCollector in project metron by apache.
the class ParserDriver method run.
public ProcessorResult<List<byte[]>> run(List<byte[]> in) {
ShimParserBolt bolt = new ShimParserBolt(new ArrayList<>());
OutputCollector collector = mock(OutputCollector.class);
bolt.prepare(null, null, collector);
for (byte[] record : in) {
bolt.execute(toTuple(record));
}
return bolt.getResults();
}
use of org.apache.storm.task.OutputCollector in project incubator-pulsar by apache.
the class PulsarBoltTest method testFailedProducer.
@Test
public void testFailedProducer() {
PulsarBoltConfiguration pulsarBoltConf = new PulsarBoltConfiguration();
pulsarBoltConf.setServiceUrl(serviceUrl);
pulsarBoltConf.setTopic("persistent://invalid");
pulsarBoltConf.setTupleToMessageMapper(tupleToMessageMapper);
pulsarBoltConf.setMetricsTimeIntervalInSecs(60);
PulsarBolt bolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
MockOutputCollector mockCollector = new MockOutputCollector();
OutputCollector collector = new OutputCollector(mockCollector);
TopologyContext context = mock(TopologyContext.class);
when(context.getThisComponentId()).thenReturn("new" + methodName);
when(context.getThisTaskId()).thenReturn(0);
try {
bolt.prepare(Maps.newHashMap(), context, collector);
fail("should have failed as producer creation failed");
} catch (IllegalStateException ie) {
// Ok.
}
}
Aggregations