jiazhai commented on a change in pull request #7839:
URL: https://github.com/apache/pulsar/pull/7839#discussion_r474718765



##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
##########
@@ -337,4 +338,80 @@ public void testRemovePersistence() throws Exception {
 
         admin.topics().deletePartitionedTopic(testTopic, true);
     }
+
+    @Test
+    public void testCheckMaxProducers() throws Exception {
+        Integer maxProducers = new Integer(-1);
+        log.info("MaxProducers: {} will set to the topic: {}", maxProducers, 
testTopic);
+        try {
+            admin.topics().setMaxProducers(testTopic, maxProducers);
+            Assert.fail();
+        } catch (PulsarAdminException e) {
+            Assert.assertEquals(e.getStatusCode(), 412);
+        }
+
+        admin.topics().deletePartitionedTopic(testTopic, true);
+    }
+
+    @Test
+    public void testSetMaxProducers() throws Exception {
+        Integer maxProducers = 2;
+        log.info("MaxProducers: {} will set to the topic: {}", maxProducers, 
persistenceTopic);
+        admin.topics().setMaxProducers(persistenceTopic, maxProducers);
+        Thread.sleep(3000);
+
+        admin.topics().createPartitionedTopic(persistenceTopic, 2);
+        Producer producer1 = null;
+        Producer producer2 = null;
+        Producer producer3 = null;
+        try {
+            producer1 = 
pulsarClient.newProducer().topic(persistenceTopic).create();
+        } catch (PulsarClientException e) {
+            Assert.fail();
+        }
+        try {
+            producer2 = 
pulsarClient.newProducer().topic(persistenceTopic).create();
+        } catch (PulsarClientException e) {
+            Assert.fail();
+        }
+        try {
+            producer3 = 
pulsarClient.newProducer().topic(persistenceTopic).create();
+            Assert.fail();
+        } catch (PulsarClientException e) {
+            log.info("Topic reached max producers limit");
+        }
+        Assert.assertNotNull(producer1);
+        Assert.assertNotNull(producer2);
+        Assert.assertNull(producer3);
+        producer1.close();
+        producer2.close();
+
+        Integer getMaxProducers = 
admin.topics().getMaxProducers(persistenceTopic);
+        log.info("MaxProducers {} get on topic: {}", getMaxProducers, 
persistenceTopic);
+        Assert.assertEquals(getMaxProducers, maxProducers);
+
+        admin.topics().deletePartitionedTopic(persistenceTopic);
+        admin.topics().deletePartitionedTopic(testTopic, true);
+    }
+
+    @Test
+    public void testRemoveMaxProducers() throws Exception {
+        Integer maxProducers = 10;
+        log.info("MaxProducers: {} will set to the topic: {}", maxProducers, 
testTopic);
+
+        admin.topics().setMaxProducers(testTopic, maxProducers);
+        Thread.sleep(3000);
+        Integer getMaxProducers = admin.topics().getMaxProducers(testTopic);
+
+        log.info("MaxProducers: {} get on topic: {}", getMaxProducers, 
testTopic);
+        Assert.assertEquals(getMaxProducers, maxProducers);
+
+        admin.topics().removeMaxProducers(testTopic);

Review comment:
       How about change this test into this logic:  
   - maxProducers = 2;
   - after set, can only create 2 producers;
   - after remove, can create more than 2 producers;




----------------------------------------------------------------
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:
[email protected]


Reply via email to