Search in sources :

Example 16 with TopologyContext

use of backtype.storm.task.TopologyContext in project pulsar by yahoo.

the class PulsarBoltTest method setup.

@Override
protected void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    pulsarBoltConf = new PulsarBoltConfiguration();
    pulsarBoltConf.setServiceUrl(serviceUrl);
    pulsarBoltConf.setTopic(topic);
    pulsarBoltConf.setTupleToMessageMapper(tupleToMessageMapper);
    pulsarBoltConf.setMetricsTimeIntervalInSecs(60);
    bolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    mockCollector = new MockOutputCollector();
    OutputCollector collector = new OutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-bolt-" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    bolt.prepare(Maps.newHashMap(), context, collector);
    consumer = pulsarClient.subscribe(topic, subscriptionName);
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration)

Example 17 with TopologyContext

use of backtype.storm.task.TopologyContext in project pulsar by yahoo.

the class PulsarSpoutTest method testNoSharedConsumer.

@Test
public void testNoSharedConsumer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    pulsarSpoutConf.setSharedConsumerEnabled(false);
    PulsarSpout otherSpout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector otherMockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherSpout.open(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 2);
    otherSpout.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
}
Also used : SpoutOutputCollector(backtype.storm.spout.SpoutOutputCollector) PersistentTopicStats(com.yahoo.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Aggregations

TopologyContext (backtype.storm.task.TopologyContext)17 SpoutOutputCollector (backtype.storm.spout.SpoutOutputCollector)7 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 PersistentTopicStats (com.yahoo.pulsar.common.policies.data.PersistentTopicStats)3 Test (org.testng.annotations.Test)3 OutputCollector (backtype.storm.task.OutputCollector)2 Config (backtype.storm.Config)1 GlobalStreamId (backtype.storm.generated.GlobalStreamId)1 Grouping (backtype.storm.generated.Grouping)1 StormTopology (backtype.storm.generated.StormTopology)1 ITaskHook (backtype.storm.hooks.ITaskHook)1 SpoutOutputCollectorImpl (backtype.storm.spout.SpoutOutputCollectorImpl)1 OutputCollectorImpl (backtype.storm.task.OutputCollectorImpl)1 WorkerTopologyContext (backtype.storm.task.WorkerTopologyContext)1 TopologyBuilder (backtype.storm.topology.TopologyBuilder)1 Tuple (backtype.storm.tuple.Tuple)1 TupleImpl (backtype.storm.tuple.TupleImpl)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1