use of org.apache.storm.task.TopologyContext 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);
}
use of org.apache.storm.task.TopologyContext in project incubator-heron by apache.
the class CustomStreamGroupingDelegate method prepare.
@Override
public void prepare(com.twitter.heron.api.topology.TopologyContext context, String component, String streamId, List<Integer> targetTasks) {
TopologyContext c = new TopologyContext(context);
GlobalStreamId g = new GlobalStreamId(component, streamId);
delegate.prepare(c, g, targetTasks);
}
use of org.apache.storm.task.TopologyContext 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.TopologyContext in project storm by apache.
the class WindowedBoltExecutorTest method getTopologyContext.
private TopologyContext getTopologyContext() {
TopologyContext context = Mockito.mock(TopologyContext.class);
Map<GlobalStreamId, Grouping> sources = Collections.singletonMap(new GlobalStreamId("s1", "default"), null);
Mockito.when(context.getThisSources()).thenReturn(sources);
return context;
}
use of org.apache.storm.task.TopologyContext 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);
}
Aggregations