Search in sources :

Example 6 with PersistentTopicInternalStats

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

the class NonPersistentTopic method getInternalStats.

public PersistentTopicInternalStats getInternalStats() {
    PersistentTopicInternalStats stats = new PersistentTopicInternalStats();
    stats.entriesAddedCounter = ENTRIES_ADDED_COUNTER_UPDATER.get(this);
    stats.cursors = Maps.newTreeMap();
    subscriptions.forEach((name, subs) -> stats.cursors.put(name, new CursorStats()));
    replicators.forEach((name, subs) -> stats.cursors.put(name, new CursorStats()));
    return stats;
}
Also used : PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) CursorStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats)

Example 7 with PersistentTopicInternalStats

use of org.apache.pulsar.common.policies.data.PersistentTopicInternalStats 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

PersistentTopicInternalStats (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats)7 CursorStats (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats)3 Test (org.testng.annotations.Test)3 URL (java.net.URL)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 WebTarget (javax.ws.rs.client.WebTarget)2 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)2 PulsarClient (org.apache.pulsar.client.api.PulsarClient)2 TopicName (org.apache.pulsar.common.naming.TopicName)2 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)1 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)1 Message (org.apache.pulsar.client.api.Message)1 NonPersistentTopicStats (org.apache.pulsar.common.policies.data.NonPersistentTopicStats)1 LedgerInfo (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.LedgerInfo)1 PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)1