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 2020/09/04 12:35:55 UTC

[GitHub] [pulsar] zhanghaou commented on a change in pull request #7968: [Issue 7759] Support set Max Consumer on topic level.

zhanghaou commented on a change in pull request #7968:
URL: https://github.com/apache/pulsar/pull/7968#discussion_r483587668



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
##########
@@ -590,4 +591,121 @@ public void testRemovePublishRate() throws Exception {
 
         admin.topics().deletePartitionedTopic(testTopic, true);
     }
+
+    @Test
+    public void testCheckMaxConsumers() throws Exception {
+        Integer maxProducers = new Integer(-1);
+        log.info("MaxConsumers: {} will set to the topic: {}", maxProducers, testTopic);
+        try {
+            admin.topics().setMaxConsumers(testTopic, maxProducers);
+            Assert.fail();
+        } catch (PulsarAdminException e) {
+            Assert.assertEquals(e.getStatusCode(), 412);
+        }
+
+        admin.topics().deletePartitionedTopic(testTopic, true);
+    }
+
+    @Test
+    public void testSetMaxConsumers() throws Exception {
+        admin.namespaces().setMaxConsumersPerTopic(myNamespace, 1);
+        log.info("MaxConsumers: {} will set to the namespace: {}", 1, myNamespace);
+        Integer maxConsumers = 2;
+        log.info("MaxConsumers: {} will set to the topic: {}", maxConsumers, persistenceTopic);
+        admin.topics().setMaxConsumers(persistenceTopic, maxConsumers);
+        Thread.sleep(3000);
+
+        admin.topics().createPartitionedTopic(persistenceTopic, 2);
+        Consumer consumer1 = null;
+        Consumer consumer2 = null;
+        Consumer consumer3 = null;
+        try {
+            consumer1 = pulsarClient.newConsumer().subscriptionName("sub1").topic(persistenceTopic).subscribe();
+        } catch (PulsarClientException e) {
+            Assert.fail();
+        }
+        try {
+            consumer2 = pulsarClient.newConsumer().subscriptionName("sub2").topic(persistenceTopic).subscribe();
+        } catch (PulsarClientException e) {
+            Assert.fail();
+        }
+        try {
+            consumer3 = pulsarClient.newConsumer().subscriptionName("sub3").topic(persistenceTopic).subscribe();
+            Assert.fail();
+        } catch (PulsarClientException e) {
+            log.info("Topic reached max consumers limit");
+        }
+        Assert.assertNotNull(consumer1);
+        Assert.assertNotNull(consumer2);
+        Assert.assertNull(consumer3);
+        consumer1.close();
+        consumer2.close();
+
+        Integer getMaxConsumers = admin.topics().getMaxConsumers(persistenceTopic);
+        log.info("MaxConsumers {} get on topic: {}", getMaxConsumers, persistenceTopic);
+        Assert.assertEquals(getMaxConsumers, maxConsumers);
+
+        admin.topics().deletePartitionedTopic(persistenceTopic, true);
+        admin.topics().deletePartitionedTopic(testTopic, true);

Review comment:
       'testTopic' was created in BeforeMethod.




----------------------------------------------------------------
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.

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