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

 ##########
 File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
 ##########
 @@ -312,4 +316,82 @@ 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;
+        LocalZooKeeperCacheService mockLocalZooKeeperCacheService = 
mock(LocalZooKeeperCacheService.class);
+        ZooKeeperChildrenCache mockZooKeeperChildrenCache = 
mock(ZooKeeperChildrenCache.class);
+        
doReturn(mockLocalZooKeeperCacheService).when(pulsar).getLocalZkCacheService();
+        
doReturn(mockZooKeeperChildrenCache).when(mockLocalZooKeeperCacheService).managedLedgerListCache();
 
 Review comment:
   First of all, this logic has no problem with non-partitioned topics.
   
   Let's look at the creation of the partitioned topic first. When we use the 
following command to create a partitioned topic, 
   
   ```
   ./bin/pulsar-admin topics create-partitioned-topic test-topic -p 2
   ```
   
   we will eventually generate the following topic in the zookeeper.
   
   ```
   persistent://public/default/test-topic-partition-0
   persistent://public/default/test-topic-partition-1
   ```
   
    When we use the `./bin/pulsar-admin topics grant-permissions` command to 
authorize for a partitioned topic, we are actually authorizing these topics:
   
   ```
   persistent://public/default/test-topic-partition-0
   persistent://public/default/test-topic-partition-1
   ```
   
   Therefore, at present, when we get permission, we also need to provide the 
following topic name:
   
   ```
   persistent://public/default/test-topic-partition-0
   persistent://public/default/test-topic-partition-1
   ```
   
   However, in actual use, users prefer to provide the following name to get 
all the permissions under the topic.
   
   ```
   persistent://public/default/test-topic
   ```
   
   So we hope that if you have time or are interested, you can provide this 
support in the `internalGetPermissionsOnTopic` function.
   
   ```
   if the topic is partitioned topic
      Loop to get permissions for each topic
   else
      Logic unchanged
   ```

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