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;
}
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);
}
Aggregations