Search in sources :

Example 11 with SpoutOutputCollector

use of backtype.storm.spout.SpoutOutputCollector in project kafka-spout by HolmesNL.

the class KafkaSpoutConstructorTest method testOpenWithDefaultConstructor.

/**
     * Using the default constructor, a topic name must be in the storm config
     */
@Test
public void testOpenWithDefaultConstructor() {
    KafkaSpout spout = spy(new KafkaSpout());
    TopologyContext topology = mock(TopologyContext.class);
    SpoutOutputCollector collector = mock(SpoutOutputCollector.class);
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(ConfigUtils.CONFIG_TOPIC, "topic");
    doNothing().when(spout).createConsumer(config);
    spout.open(config, topology, collector);
    assertEquals("Wrong Topic Name", spout._topic, "topic");
}
Also used : HashMap(java.util.HashMap) SpoutOutputCollector(backtype.storm.spout.SpoutOutputCollector) TopologyContext(backtype.storm.task.TopologyContext) Test(org.junit.Test)

Example 12 with SpoutOutputCollector

use of backtype.storm.spout.SpoutOutputCollector 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

SpoutOutputCollector (backtype.storm.spout.SpoutOutputCollector)12 TopologyContext (backtype.storm.task.TopologyContext)7 HashMap (java.util.HashMap)6 ISpoutOutputCollector (backtype.storm.spout.ISpoutOutputCollector)4 Test (org.junit.Test)4 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)3 PersistentTopicStats (com.yahoo.pulsar.common.policies.data.PersistentTopicStats)2 Random (java.util.Random)2 Test (org.testng.annotations.Test)2 IntervalCheck (com.alibaba.jstorm.utils.IntervalCheck)1 ConsumerConfiguration (com.yahoo.pulsar.client.api.ConsumerConfiguration)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1