Search in sources :

Example 6 with NonPersistentTopicStats

use of org.apache.pulsar.common.policies.data.NonPersistentTopicStats in project incubator-pulsar by apache.

the class AdminApiTest2 method nonPersistentTopics.

/**
 * verifies admin api command for non-persistent topic. It verifies: partitioned-topic, stats
 *
 * @throws Exception
 */
@Test
public void nonPersistentTopics() throws Exception {
    final String topicName = "nonPersistentTopic";
    final String persistentTopicName = "non-persistent://prop-xyz/use/ns1/" + topicName;
    // Force to create a topic
    publishMessagesOnTopic("non-persistent://prop-xyz/use/ns1/" + topicName, 0, 0);
    // create consumer and subscription
    URL pulsarUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
    PulsarClient client = PulsarClient.builder().serviceUrl(pulsarUrl.toString()).statsInterval(0, TimeUnit.SECONDS).build();
    Consumer<byte[]> consumer = client.newConsumer().topic(persistentTopicName).subscriptionName("my-sub").subscribe();
    publishMessagesOnTopic("non-persistent://prop-xyz/use/ns1/" + topicName, 10, 0);
    NonPersistentTopicStats topicStats = admin.nonPersistentTopics().getStats(persistentTopicName);
    assertEquals(topicStats.getSubscriptions().keySet(), Sets.newTreeSet(Lists.newArrayList("my-sub")));
    assertEquals(topicStats.getSubscriptions().get("my-sub").consumers.size(), 1);
    assertEquals(topicStats.getPublishers().size(), 0);
    PersistentTopicInternalStats internalStats = admin.nonPersistentTopics().getInternalStats(persistentTopicName);
    assertEquals(internalStats.cursors.keySet(), Sets.newTreeSet(Lists.newArrayList("my-sub")));
    consumer.close();
    client.close();
    topicStats = admin.nonPersistentTopics().getStats(persistentTopicName);
    assertTrue(topicStats.getSubscriptions().keySet().contains("my-sub"));
    assertEquals(topicStats.getPublishers().size(), 0);
    // test partitioned-topic
    final String partitionedTopicName = "non-persistent://prop-xyz/use/ns1/paritioned";
    assertEquals(admin.nonPersistentTopics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 0);
    admin.nonPersistentTopics().createPartitionedTopic(partitionedTopicName, 5);
    assertEquals(admin.nonPersistentTopics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 5);
}
Also used : NonPersistentTopicStats(org.apache.pulsar.common.policies.data.NonPersistentTopicStats) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) PulsarClient(org.apache.pulsar.client.api.PulsarClient) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

NonPersistentTopicStats (org.apache.pulsar.common.policies.data.NonPersistentTopicStats)6 NonPersistentSubscriptionStats (org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats)4 Test (org.testng.annotations.Test)4 NonPersistentTopic (org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic)3 ZookeeperServerTest (org.apache.pulsar.zookeeper.ZookeeperServerTest)3 NonPersistentPublisherStats (org.apache.pulsar.common.policies.data.NonPersistentPublisherStats)2 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)2 ObjectObjectHashMap (com.carrotsearch.hppc.ObjectObjectHashMap)1 URL (java.net.URL)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 WebTarget (javax.ws.rs.client.WebTarget)1 PulsarService (org.apache.pulsar.broker.PulsarService)1 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 NonPersistentReplicator (org.apache.pulsar.broker.service.nonpersistent.NonPersistentReplicator)1 PulsarClient (org.apache.pulsar.client.api.PulsarClient)1 ConsumerImpl (org.apache.pulsar.client.impl.ConsumerImpl)1 ProducerImpl (org.apache.pulsar.client.impl.ProducerImpl)1 TopicName (org.apache.pulsar.common.naming.TopicName)1