codelipenghui commented on a change in pull request #12215:
URL: https://github.com/apache/pulsar/pull/12215#discussion_r718577943



##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/DeleteAuthenticationPoliciesTest.java
##########
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.auth;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.AuthAction;
+import org.apache.pulsar.common.policies.data.ClusterData;
+import org.apache.pulsar.common.policies.data.TenantInfoImpl;
+import org.apache.pulsar.metadata.api.MetadataStoreException;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class DeleteAuthenticationPoliciesTest extends 
MockedPulsarServiceBaseTest {

Review comment:
       Add a test group?

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -632,25 +632,29 @@ protected void 
internalDeletePartitionedTopic(AsyncResponse asyncResponse, boole
                     return;
                 }
             }
+            // Only tries to delete the authentication policies for 
partitioned topic when all its partitions are
+            // successfully deleted
+            
pulsar().getBrokerService().deleteTopicAuthenticationWithRetry(topicName.toString());

Review comment:
       @gaoran10 I think ok here, If users want to delete a topic, but it 
failed. users should try to delete it again. But if delete the topic succeed, 
delete the authentication failed, the authentication will be permanently 
retained in Zookeeper

##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/DeleteAuthenticationPoliciesTest.java
##########
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.auth;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.AuthAction;
+import org.apache.pulsar.common.policies.data.ClusterData;
+import org.apache.pulsar.common.policies.data.TenantInfoImpl;
+import org.apache.pulsar.metadata.api.MetadataStoreException;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class DeleteAuthenticationPoliciesTest extends 
MockedPulsarServiceBaseTest {
+
+    public DeleteAuthenticationPoliciesTest() {
+        super();
+    }
+
+    @BeforeClass
+    @Override
+    public void setup() throws Exception {
+        conf.setClusterName("c1");
+
+        internalSetup();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    public void cleanup() throws Exception {
+        internalCleanup();
+    }
+    @Test
+    public void testDeleteAuthenticationPoliciesOfTopic() throws 
PulsarAdminException, MetadataStoreException {
+        admin.clusters().createCluster("c1", ClusterData.builder().build());
+        admin.tenants().createTenant("p1",
+                new TenantInfoImpl(Collections.emptySet(), new 
HashSet<>(admin.clusters().getClusters())));
+        waitForChange();
+        admin.namespaces().createNamespace("p1/ns1");
+
+        // test for non-partitioned topic
+        String topic = "persistent://p1/ns1/topic";
+        admin.topics().createNonPartitionedTopic(topic);
+        admin.topics().grantPermission(topic, "test-user", 
EnumSet.of(AuthAction.consume));
+        waitForChange();
+
+        
assertTrue(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                
.get().auth_policies.getTopicAuthentication().containsKey(topic));
+
+        admin.topics().delete(topic);
+        waitForChange();
+
+        
assertFalse(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                
.get().auth_policies.getTopicAuthentication().containsKey(topic));
+
+        // test for partitioned topic
+        String partitionedTopic = "persistent://p1/ns1/partitioned-topic";
+        int numPartitions = 5;
+
+        admin.topics().createPartitionedTopic(partitionedTopic, numPartitions);
+        admin.topics()
+                .grantPermission(partitionedTopic, "test-user", 
EnumSet.of(AuthAction.consume));
+        waitForChange();
+
+        
assertTrue(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                
.get().auth_policies.getTopicAuthentication().containsKey(partitionedTopic));
+
+        for (int i = 0; i < numPartitions; i++) {
+            
assertTrue(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                    .get().auth_policies.getTopicAuthentication()
+                    
.containsKey(TopicName.get(partitionedTopic).getPartition(i).toString()));
+        }
+
+        
admin.topics().deletePartitionedTopic("persistent://p1/ns1/partitioned-topic");
+        waitForChange();
+
+        
assertFalse(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                
.get().auth_policies.getTopicAuthentication().containsKey(partitionedTopic));
+        for (int i = 0; i < numPartitions; i++) {
+            
assertFalse(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
+                    .get().auth_policies.getTopicAuthentication()
+                    
.containsKey(TopicName.get(partitionedTopic).getPartition(i).toString()));
+        }
+
+        admin.namespaces().deleteNamespace("p1/ns1");
+        admin.tenants().deleteTenant("p1");
+        admin.clusters().deleteCluster("c1");
+
+    }
+
+    private static void waitForChange() {
+        try {
+            Thread.sleep(100);

Review comment:
       Please avoid sleep, it's better to use Awaitbility to instead.

##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/auth/DeleteAuthenticationPoliciesTest.java
##########
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.auth;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.naming.NamespaceName;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.AuthAction;
+import org.apache.pulsar.common.policies.data.ClusterData;
+import org.apache.pulsar.common.policies.data.TenantInfoImpl;
+import org.apache.pulsar.metadata.api.MetadataStoreException;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class DeleteAuthenticationPoliciesTest extends 
MockedPulsarServiceBaseTest {

Review comment:
       And we already have `AuthenticatedProducerConsumerTest` there, it's 
better to move the test to `AuthenticatedProducerConsumerTest` which will bring 
convenience to test maintenance




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to