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

 ##########
 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:
   Mock is not required here.
   
   The following code can be used to check:
   
   ```
       @Test
       public void testGrantPartitionedTopic() throws Exception {
           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);
           for (int i=0; i < numPartitions; i++) {
               Map<String, Set<AuthAction>> partitionPermissions = 
persistentTopics.getPermissionsOnTopic(testTenant,
                       testNamespace, partitionedTopicName + "-partition-" + i);
               Assert.assertEquals(partitionPermissions.get(role), 
expectActions);
           }
       }
   ```
   The `getPermissionsOnTopic` function does not seem to support searching 
partitioned topic yet. I think you can consider adding a feature to the 
`getPermissionsOnTopic` function to support searching partition topic in this 
pr or by opening a new pr.
   
   If the `getPermissionsOnTopic` function supports finding partitioned topic, 
you can directly call the `getPermissionsOnTopic` function to get the value of 
permissions, so this loop is not needed.

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


With regards,
Apache Git Services

Reply via email to