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 2021/11/09 16:17:05 UTC

[GitHub] [pulsar] cbornet commented on a change in pull request #12699: Fix namespace policy override ignored when creating subscription

cbornet commented on a change in pull request #12699:
URL: https://github.com/apache/pulsar/pull/12699#discussion_r745780962



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
##########
@@ -350,6 +350,37 @@ public void testNotAllowSubscriptionTopicCreation() throws Exception{
 
     }
 
+    @Test
+    public void testAutoCreationNamespaceOverridesSubscriptionTopicCreation() throws Exception {
+        pulsar.getConfiguration().setAllowAutoTopicCreation(false);
+        String topicString = "persistent://prop/ns-abc/non-partitioned-topic" + System.currentTimeMillis();
+        String subscriptionName = "non-partitioned-topic-sub";
+        final TopicName topicName = TopicName.get(topicString);
+        pulsar.getAdminClient().namespaces().setAutoTopicCreation(topicName.getNamespace(),
+                AutoTopicCreationOverride.builder()
+                        .allowAutoTopicCreation(true)
+                        .topicType(TopicType.NON_PARTITIONED.toString())
+                        .build());
+
+        admin.topics().createSubscription(topicString, subscriptionName, MessageId.earliest);
+    }
+
+    @Test
+    public void testAutoCreationNamespaceOverridesSubscriptionPartitionedTopicCreation() throws Exception {
+        pulsar.getConfiguration().setAllowAutoTopicCreation(false);
+        String topicString = "persistent://prop/ns-abc/partitioned-topic" + System.currentTimeMillis();
+        String subscriptionName = "partitioned-topic-sub";
+        final TopicName topicName = TopicName.get(topicString);
+        pulsar.getAdminClient().namespaces().setAutoTopicCreation(topicName.getNamespace(),
+                AutoTopicCreationOverride.builder()
+                        .allowAutoTopicCreation(true)
+                        .topicType(TopicType.PARTITIONED.toString())
+                        .defaultNumPartitions(3)
+                        .build());
+
+        admin.topics().createSubscription(topicString + "-partition-0", subscriptionName, MessageId.earliest);

Review comment:
       Yes that's the intent. I've seen it done [here](https://github.com/apache/pulsar/blob/da71ec2b2a6682ffbab60843756f638bedbd4460/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/CreateSubscriptionTest.java#L112) so I guess it's OK.
   Also this way the topic is created by `pulsar().getBrokerService().getTopic()` in `internalCreateSubscriptionForNonPartitionedTopic` instead of `pulsar().getBrokerService().fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync()` when you don't specify a partition.




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