use of org.apache.storm.task.OutputCollector in project storm by apache.
the class RollingCountBoltTest method shouldEmitNothingIfNoObjectHasBeenCountedYetAndTickTupleIsReceived.
@SuppressWarnings("rawtypes")
@Test
public void shouldEmitNothingIfNoObjectHasBeenCountedYetAndTickTupleIsReceived() {
// given
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(tickTuple);
// then
verifyZeroInteractions(collector);
}
use of org.apache.storm.task.OutputCollector in project storm by apache.
the class CoordinatedBolt method prepare.
@Override
public void prepare(Map<String, Object> config, TopologyContext context, OutputCollector collector) {
TimeCacheMap.ExpiredCallback<Object, TrackingInfo> callback = null;
if (delegate instanceof TimeoutCallback) {
callback = new TimeoutItems();
}
tracked = new TimeCacheMap<>(context.maxTopologyMessageTimeout(), callback);
this.collector = collector;
delegate.prepare(config, context, new OutputCollector(new CoordinatedOutputCollector(collector)));
for (String component : Utils.get(context.getThisTargets(), Constants.COORDINATED_STREAM_ID, new HashMap<String, Grouping>()).keySet()) {
for (Integer task : context.getComponentTasks(component)) {
countOutTasks.add(task);
}
}
if (!sourceArgs.isEmpty()) {
numSourceReports = 0;
for (Entry<String, SourceArgs> entry : sourceArgs.entrySet()) {
if (entry.getValue().singleCount) {
numSourceReports += 1;
} else {
numSourceReports += context.getComponentTasks(entry.getKey()).size();
}
}
}
}
use of org.apache.storm.task.OutputCollector in project storm by apache.
the class KafkaBoltTest method testCustomCallbackIsWrappedByDefaultCallbackBehavior.
@Test
public void testCustomCallbackIsWrappedByDefaultCallbackBehavior() {
MockProducer<String, String> producer = new MockProducer<>(Cluster.empty(), false, null, null, null);
KafkaBolt<String, String> bolt = makeBolt(producer);
PreparableCallback customCallback = mock(PreparableCallback.class);
bolt.withProducerCallback(customCallback);
OutputCollector collector = mock(OutputCollector.class);
TopologyContext context = mock(TopologyContext.class);
Map<String, Object> topoConfig = new HashMap<>();
bolt.prepare(topoConfig, context, collector);
verify(customCallback).prepare(topoConfig, context);
String key = "KEY";
String value = "VALUE";
Tuple testTuple = createTestTuple(key, value);
bolt.execute(testTuple);
assertThat(producer.history().size(), is(1));
ProducerRecord<String, String> arg = producer.history().get(0);
LOG.info("GOT {} ->", arg);
LOG.info("{}, {}, {}", arg.topic(), arg.key(), arg.value());
assertThat(arg.topic(), is("MY_TOPIC"));
assertThat(arg.key(), is(key));
assertThat(arg.value(), is(value));
// Force a send error
KafkaException ex = new KafkaException();
producer.errorNext(ex);
verify(customCallback).onCompletion(any(), eq(ex));
verify(collector).reportError(ex);
verify(collector).fail(testTuple);
}
use of org.apache.storm.task.OutputCollector in project storm by apache.
the class KafkaBoltTest method testSimpleWithError.
@Test
public void testSimpleWithError() {
MockProducer<String, String> producer = new MockProducer<>(Cluster.empty(), false, null, null, null);
KafkaBolt<String, String> bolt = makeBolt(producer);
OutputCollector collector = mock(OutputCollector.class);
TopologyContext context = mock(TopologyContext.class);
Map<String, Object> conf = new HashMap<>();
bolt.prepare(conf, context, collector);
String key = "KEY";
String value = "VALUE";
Tuple testTuple = createTestTuple(key, value);
bolt.execute(testTuple);
assertThat(producer.history().size(), is(1));
ProducerRecord<String, String> arg = producer.history().get(0);
LOG.info("GOT {} ->", arg);
LOG.info("{}, {}, {}", arg.topic(), arg.key(), arg.value());
assertThat(arg.topic(), is("MY_TOPIC"));
assertThat(arg.key(), is(key));
assertThat(arg.value(), is(value));
// Force a send error
KafkaException ex = new KafkaException();
producer.errorNext(ex);
verify(collector).reportError(ex);
verify(collector).fail(testTuple);
}
use of org.apache.storm.task.OutputCollector in project storm by apache.
the class BoltExecutor method init.
public void init(ArrayList<Task> idToTask, int idToTaskBase) throws InterruptedException {
executorTransfer.initLocalRecvQueues();
workerReady.await();
while (!stormActive.get()) {
// Topology may be deployed in deactivated mode, wait for activation
Utils.sleepNoSimulation(100);
}
LOG.info("Preparing bolt {}:{}", componentId, getTaskIds());
for (Task taskData : idToTask) {
if (taskData == null) {
// This happens if the min id is too small
continue;
}
IBolt boltObject = (IBolt) taskData.getTaskObject();
TopologyContext userContext = taskData.getUserContext();
if (boltObject instanceof ICredentialsListener) {
((ICredentialsListener) boltObject).setCredentials(credentials);
}
if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), topoConf, userContext);
// add any autocredential expiry metrics from the worker
if (workerData.getAutoCredentials() != null) {
for (IAutoCredentials autoCredential : workerData.getAutoCredentials()) {
if (autoCredential instanceof IMetricsRegistrant) {
IMetricsRegistrant registrant = (IMetricsRegistrant) autoCredential;
registrant.registerMetrics(userContext, topoConf);
}
}
}
}
this.outputCollector = new BoltOutputCollectorImpl(this, taskData, rand, hasEventLoggers, ackingEnabled, isDebug);
boltObject.prepare(topoConf, userContext, new OutputCollector(outputCollector));
}
openOrPrepareWasCalled.set(true);
LOG.info("Prepared bolt {}:{}", componentId, taskIds);
setupTicks(false);
setupMetrics();
}
Aggregations