Search in sources :

Example 1 with PulsarSpout

use of org.apache.pulsar.storm.PulsarSpout in project incubator-pulsar by apache.

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(org.apache.storm.spout.SpoutOutputCollector) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 2 with PulsarSpout

use of org.apache.pulsar.storm.PulsarSpout in project incubator-pulsar by apache.

the class PulsarSpoutTest method testSerializability.

@Test
public void testSerializability() throws Exception {
    // test serializability with no auth
    PulsarSpout spoutWithNoAuth = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration());
    TestUtil.testSerializability(spoutWithNoAuth);
}
Also used : PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 3 with PulsarSpout

use of org.apache.pulsar.storm.PulsarSpout in project incubator-pulsar by apache.

the class PulsarSpoutTest method testSharedConsumer.

@Test
public void testSharedConsumer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    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(), 1);
    otherSpout.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
}
Also used : SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 4 with PulsarSpout

use of org.apache.pulsar.storm.PulsarSpout in project incubator-pulsar by apache.

the class PulsarSpoutTest method setup.

@Override
protected void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    pulsarSpoutConf = new PulsarSpoutConfiguration();
    pulsarSpoutConf.setServiceUrl(serviceUrl);
    pulsarSpoutConf.setTopic(topic);
    pulsarSpoutConf.setSubscriptionName(subscriptionName);
    pulsarSpoutConf.setMessageToValuesMapper(messageToValuesMapper);
    pulsarSpoutConf.setFailedRetriesTimeout(1, TimeUnit.SECONDS);
    pulsarSpoutConf.setMaxFailedRetries(2);
    pulsarSpoutConf.setSharedConsumerEnabled(true);
    pulsarSpoutConf.setMetricsTimeIntervalInSecs(60);
    consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Shared);
    spout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    mockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    spout.open(Maps.newHashMap(), context, collector);
    producer = pulsarClient.createProducer(topic);
}
Also used : PulsarSpoutConfiguration(org.apache.pulsar.storm.PulsarSpoutConfiguration) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration)

Example 5 with PulsarSpout

use of org.apache.pulsar.storm.PulsarSpout in project incubator-pulsar by apache.

the class PulsarSpoutTest method testFailedConsumer.

@Test
public void testFailedConsumer() throws Exception {
    PulsarSpoutConfiguration pulsarSpoutConf = new PulsarSpoutConfiguration();
    pulsarSpoutConf.setServiceUrl(serviceUrl);
    pulsarSpoutConf.setTopic("persistent://invalidTopic");
    pulsarSpoutConf.setSubscriptionName(subscriptionName);
    pulsarSpoutConf.setMessageToValuesMapper(messageToValuesMapper);
    pulsarSpoutConf.setFailedRetriesTimeout(1, TimeUnit.SECONDS);
    pulsarSpoutConf.setMaxFailedRetries(2);
    pulsarSpoutConf.setSharedConsumerEnabled(false);
    pulsarSpoutConf.setMetricsTimeIntervalInSecs(60);
    ConsumerConfiguration consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Shared);
    PulsarSpout spout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector mockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("new-test" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    try {
        spout.open(Maps.newHashMap(), context, collector);
        fail("should have failed as consumer creation failed");
    } catch (IllegalStateException e) {
    // Ok
    }
}
Also used : PulsarSpoutConfiguration(org.apache.pulsar.storm.PulsarSpoutConfiguration) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Aggregations

ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)6 PulsarSpout (org.apache.pulsar.storm.PulsarSpout)6 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)4 TopologyContext (org.apache.storm.task.TopologyContext)4 Test (org.testng.annotations.Test)4 PulsarSpoutConfiguration (org.apache.pulsar.storm.PulsarSpoutConfiguration)3 ConsumerConfiguration (org.apache.pulsar.client.api.ConsumerConfiguration)2 PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)2 Consumer (org.apache.pulsar.client.api.Consumer)1 Message (org.apache.pulsar.client.api.Message)1 Producer (org.apache.pulsar.client.api.Producer)1 PulsarClient (org.apache.pulsar.client.api.PulsarClient)1 PulsarBolt (org.apache.pulsar.storm.PulsarBolt)1 PulsarBoltConfiguration (org.apache.pulsar.storm.PulsarBoltConfiguration)1 Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 IMetricsConsumer (org.apache.storm.metric.api.IMetricsConsumer)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1