You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/18 08:14:00 UTC

[GitHub] [pulsar] AnonHxy commented on a change in pull request #14387: [Broker]Dynamic update topic broker-level publish-rate

AnonHxy commented on a change in pull request #14387:
URL: https://github.com/apache/pulsar/pull/14387#discussion_r829773714



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PrecisTopicPublishRateThrottleTest.java
##########
@@ -140,4 +141,64 @@ public void testPrecisTopicPublishRateLimitingProduceRefresh() throws Exception
         Assert.assertNotNull(messageId);
         super.internalCleanup();
     }
+
+    @Test
+    public void testMultiLevelPublishRate() throws Exception{
+        conf.setPreciseTopicPublishRateLimiterEnable(true);
+        conf.setTopicLevelPoliciesEnabled(true);
+        conf.setSystemTopicEnabled(true);
+        conf.setMaxPendingPublishRequestsPerConnection(0);
+        super.baseSetup();
+        org.apache.pulsar.client.api.Producer<byte[]> producer = pulsarClient.newProducer()
+            .topic("persistent://prop/ns-abc/testPrecisTopicPublishRateLimiting")
+            .producerName("producer-name")
+            .create();
+        testPublishRate(producer, 30, 20, 10, 10);
+        Thread.sleep(1000);
+        testPublishRate(producer, 30, 20, -1, 20);
+        Thread.sleep(1000);
+        testPublishRate(producer, 30, -1, -1, 30);
+        Thread.sleep(1000);
+        testPublishRate(producer, -1, -1, 10, 10);
+        super.internalCleanup();
+    }
+
+    private void testPublishRate(org.apache.pulsar.client.api.Producer<byte[]> producer, int brokerRate, int nsRate,
+                                 int topicRate, int expectedRate) throws Exception {
+        PublishRate topicPublishRate = new PublishRate(1, topicRate);
+        PublishRate nsPublishRate = new PublishRate(1, nsRate);
+        final String topic = "persistent://prop/ns-abc/testPrecisTopicPublishRateLimiting";
+        admin.topicPolicies().setPublishRate(topic, topicPublishRate);
+        Awaitility.await()
+            .untilAsserted(() -> Assert.assertEquals(admin.topicPolicies().getPublishRate(topic), topicPublishRate));
+        admin.namespaces().setPublishRate("prop/ns-abc", nsPublishRate);
+        Awaitility.await()
+            .untilAsserted(() -> Assert.assertEquals(admin.namespaces().getPublishRate("prop/ns-abc"), nsPublishRate));
+        admin.brokers().updateDynamicConfiguration("maxPublishRatePerTopicInBytes", "" + brokerRate);
+        Awaitility.await()
+            .untilAsserted(() ->
+                Assert.assertEquals(admin.brokers().getAllDynamicConfigurations().get("maxPublishRatePerTopicInBytes"),
+                    "" + brokerRate));
+
+        Topic topicRef = pulsar.getBrokerService().getTopicReference(topic).get();
+        Assert.assertNotNull(topicRef);
+        MessageId messageId = null;
+        try {
+            // first will be success, and will set auto read to false
+            messageId = producer.sendAsync(new byte[expectedRate]).get(500, TimeUnit.MILLISECONDS);

Review comment:
       Have updated the UT, PTAL @codelipenghui @Jason918 




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org