tjiuming commented on code in PR #15867:
URL: https://github.com/apache/pulsar/pull/15867#discussion_r898194283
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentTopicTest.java:
##########
@@ -308,4 +307,70 @@ public void
testAutoCreatePartitionedTopicThatNameIncludePartition() throws Exce
assertEquals(admin.topics().getList(ns).size(), 0);
pulsar.getConfiguration().setAllowAutoTopicCreationType("non-partitioned");
}
+
+
+ @Test
+ public void testNamespaceLevelDelayedDeliveryTrackerMemoryUsageMetric()
throws Exception {
+ String topic = "persistent://prop/autoNs/test_delayed_message_metric"
+ UUID.randomUUID();
+ testDelayedDeliveryTrackerMemoryUsageMetric(topic, false);
+ }
+
+ @Test
+ public void testTopicLevelDelayedDeliveryTrackerMemoryUsageMetric() throws
Exception {
+ String topic = "persistent://prop/autoNs/test_delayed_message_metric"
+ UUID.randomUUID();
+ testDelayedDeliveryTrackerMemoryUsageMetric(topic, true);
+ }
+
+
+ private void testDelayedDeliveryTrackerMemoryUsageMetric(String topic,
boolean exposeTopicLevelMetrics) throws Exception {
+ PulsarClient client = pulsar.getClient();
+ String namespace = TopicName.get(topic).getNamespace();
+ admin.namespaces().createNamespace(namespace);
+
+ @Cleanup
+ Producer<String> producer =
client.newProducer(Schema.STRING).topic(topic).enableBatching(false).create();
+ @Cleanup
+ Consumer<String> consumer = client.newConsumer(Schema.STRING)
+ .topic(topic)
+ .subscriptionName("test_sub")
+ .subscriptionType(SubscriptionType.Shared)
+ .messageListener((MessageListener<String>) (consumer1, msg) ->
{
+ try {
+ consumer1.acknowledge(msg);
+ } catch (PulsarClientException e) {
+ e.printStackTrace();
+ }
+ })
+ .subscribe();
+ for (int a = 0; a < 100; a++) {
+
producer.newMessage().value(UUID.randomUUID().toString()).deliverAfter(30,
TimeUnit.SECONDS).send();
+ }
+ producer.flush();
+
+ //wait for Dispatcher build delayed message index.
+ for (int a = 0; a < 100; a++) {
+ Thread.sleep(1);
+ }
+
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
Review Comment:
no need to close it, it's memory managed by heap. also,
ByteArrayOutputStream#close is noop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]