tuteng commented on a change in pull request #5767: Support batch authorization 
of partitioned topic
URL: https://github.com/apache/pulsar/pull/5767#discussion_r352318147
 
 

 ##########
 File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
 ##########
 @@ -312,4 +316,74 @@ public void testGetPartitionedTopicsList() throws 
KeeperException, InterruptedEx
         Assert.assertEquals(nonPersistentPartitionedTopics.size(), 1);
         
Assert.assertEquals(TopicName.get(nonPersistentPartitionedTopics.get(0)).getDomain().value(),
 TopicDomain.non_persistent.value());
     }
+
+    @Test
+    public void testGrantNonPartitionedTopic() {
+        final String topicName = "non-partitioned-topic";
+        persistentTopics.createNonPartitionedTopic(testTenant, testNamespace, 
topicName, true);
+        String role = "role";
+        Set<AuthAction> expectActions = new HashSet<>();
+        expectActions.add(AuthAction.produce);
+        persistentTopics.grantPermissionsOnTopic(testTenant, testNamespace, 
topicName, role, expectActions);
+        Map<String, Set<AuthAction>> permissions = 
persistentTopics.getPermissionsOnTopic(testTenant, testNamespace, topicName);
+        Assert.assertEquals(permissions.get(role), expectActions);
+    }
+
+    @Test
+    public void testGrantPartitionedTopic() {
+        final String partitionedTopicName = "partitioned-topic";
+        final int numPartitions = 5;
+        persistentTopics.createPartitionedTopic(testTenant, testNamespace, 
partitionedTopicName, numPartitions);
+
+        String role = "role";
+        Set<AuthAction> expectActions = new HashSet<>();
+        expectActions.add(AuthAction.produce);
+        persistentTopics.grantPermissionsOnTopic(testTenant, testNamespace, 
partitionedTopicName, role, expectActions);
+        Map<String, Set<AuthAction>> permissions = 
persistentTopics.getPermissionsOnTopic(testTenant, testNamespace,
+                partitionedTopicName);
+        Assert.assertEquals(permissions.get(role), expectActions);
+        TopicName topicName = TopicName.get(partitionedTopicName);
+        for (int i = 0; i < numPartitions; i++) {
+            TopicName partition = topicName.getPartition(i);
+            Map<String, Set<AuthAction>> partitionPermissions = 
persistentTopics.getPermissionsOnTopic(testTenant,
 
 Review comment:
   `partition` here is a full-path topic, so the splice is wrong.
   The following wrong path will be spliced here:
   ```
   
persistent://my-tenant/my-namespace/persistent://my-tenant/my-namespace/partitioned-topic-partition-0
   
persistent://my-tenant/my-namespace/persistent://my-tenant/my-namespace/partitioned-topic-partition-1
   
persistent://my-tenant/my-namespace/persistent://my-tenant/my-namespace/partitioned-topic-partition-2
   
persistent://my-tenant/my-namespace/persistent://my-tenant/my-namespace/partitioned-topic-partition-3
   
persistent://my-tenant/my-namespace/persistent://my-tenant/my-namespace/partitioned-topic-partition-4
   ```
   The correct path should look like this:
   ```
   persistent://my-tenant/my-namespace/partitioned-topic-partition-0
   persistent://my-tenant/my-namespace/partitioned-topic-partition-1
   persistent://my-tenant/my-namespace/partitioned-topic-partition-2
   persistent://my-tenant/my-namespace/partitioned-topic-partition-3
   persistent://my-tenant/my-namespace/partitioned-topic-partition-4
   ```
   
   ```
   public TopicName getPartition(int index) {
           if (index == -1 || 
this.toString().contains(PARTITIONED_TOPIC_SUFFIX)) {
               return this;
           }
           String partitionName = this.toString() + PARTITIONED_TOPIC_SUFFIX + 
index;
           return get(partitionName);
       }
    @Override
       public String toString() {
           return completeTopicName;
       }
   if (isV2()) {
               this.completeTopicName = String.format("%s://%s/%s/%s",
                                                      domain, tenant, 
namespacePortion, localName);
   ```
   

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


With regards,
Apache Git Services

Reply via email to