hangc0276 commented on a change in pull request #9042: URL: https://github.com/apache/pulsar/pull/9042#discussion_r548339312
########## File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java ########## @@ -1413,6 +1414,132 @@ public void testRetentionPolicyValidation() throws Exception { admin.namespaces().deleteNamespace(namespace); } + @Test(timeOut = 30000) + public void testMaxTopicsPerNamespace() throws Exception { + super.internalCleanup(); + conf.setMaxTopicsPerNamespace(15); + super.internalSetup(); + + String namespace = "testTenant/ns1"; + admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString())); + TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), + Sets.newHashSet("use")); + admin.tenants().createTenant("testTenant", tenantInfo); + admin.namespaces().createNamespace(namespace, Sets.newHashSet("use")); + + admin.namespaces().setMaxTopicsPerNamespace(namespace, 10); + assertEquals(10, admin.namespaces().getMaxTopicsPerNamespace(namespace)); + + // check create partitioned/non-partitioned topics using namespace policy + String topic = "persistent://testTenant/ns1/test_create_topic_v"; + admin.topics().createPartitionedTopic(topic + "1", 2); + admin.topics().createPartitionedTopic(topic + "2", 3); + admin.topics().createPartitionedTopic(topic + "3", 4); + admin.topics().createNonPartitionedTopic(topic + "4"); + + try { + admin.topics().createPartitionedTopic(topic + "5", 2); + fail(); + } catch (PulsarAdminException e) { + assertEquals(e.getStatusCode(), 412); + assertEquals(e.getHttpError(), "Exceed maximum number of topics in namespace."); + } + + // remove namespace policy limit, use broker configuration instead. + admin.namespaces().removeMaxTopicsPerNamespace(namespace); + admin.topics().createPartitionedTopic(topic + "6", 4); + try { + admin.topics().createPartitionedTopic(topic + "7", 3); + fail(); + } catch (PulsarAdminException e) { + assertEquals(e.getStatusCode(), 412); + assertEquals(e.getHttpError(), "Exceed maximum number of topics in namespace."); + } + + admin.namespaces().setMaxTopicsPerNamespace(namespace, 0); + // set namespace policy to no limit + for (int i = 0; i< 10; ++i) { + admin.topics().createPartitionedTopic(topic + "_v" + i, 2); + admin.topics().createNonPartitionedTopic(topic + "_vn" + i); + } + + + // check producer/consumer auto create partitioned topic + super.internalCleanup(); + conf.setMaxTopicsPerNamespace(0); + conf.setDefaultNumPartitions(3); + conf.setAllowAutoTopicCreationType("partitioned"); + super.internalSetup(); + + admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString())); + admin.tenants().createTenant("testTenant", tenantInfo); + admin.namespaces().createNamespace(namespace, Sets.newHashSet("use")); + admin.namespaces().setMaxTopicsPerNamespace(namespace, 10); + + pulsarClient.newProducer().topic(topic + "1").create(); Review comment: OK, i will close them. ---------------------------------------------------------------- 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: us...@infra.apache.org