codelipenghui commented on a change in pull request #6383: [Issue 6043] Support 
force deleting subscription
URL: https://github.com/apache/pulsar/pull/6383#discussion_r382888885
 
 

 ##########
 File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
 ##########
 @@ -1304,6 +1304,46 @@ public void testNamespaceBundleUnload(Integer 
numBundles) throws Exception {
         admin.topics().delete("persistent://prop-xyz/ns1-bundles/ds2");
     }
 
+    @Test(dataProvider = "topicName")
+    public void testDeleteSubscription(String topicName) throws Exception {
+        final String subName = topicName;
+        final String persistentTopicName = "persistent://prop-xyz/ns1/" + 
topicName;
+
+        // create a topic and produce some messages
+        publishMessagesOnPersistentTopic("persistent://prop-xyz/ns1/" + 
topicName, 5);
+        assertEquals(admin.topics().getList("prop-xyz/ns1"),
+            Lists.newArrayList("persistent://prop-xyz/ns1/" + topicName));
+
+        // create consumer and subscription
+        PulsarClient client = PulsarClient.builder()
+            .serviceUrl(pulsar.getWebServiceAddress())
+            .statsInterval(0, TimeUnit.SECONDS)
+            .build();
+        Consumer<byte[]> consumer = 
client.newConsumer().topic(persistentTopicName).subscriptionName(subName)
+            .subscriptionType(SubscriptionType.Exclusive).subscribe();
+
+        assertEquals(admin.topics().getSubscriptions(persistentTopicName), 
Lists.newArrayList(subName));
+
+        // try to delete the subscription with a connected consumer
+        try {
+            admin.topics().deleteSubscription(persistentTopicName, subName);
+            fail("should have failed");
+        } catch (PulsarAdminException.PreconditionFailedException e) {
+            assertEquals(e.getStatusCode(), 
Status.PRECONDITION_FAILED.getStatusCode());
+        }
+
+        // failed to delete the subscription
+        assertEquals(admin.topics().getSubscriptions(persistentTopicName), 
Lists.newArrayList(subName));
+
+        // try to delete the subscription with a connected consumer forcefully
+        admin.topics().deleteSubscription(persistentTopicName, subName, true);
+
+        // delete the subscription successfully
+        
assertEquals(admin.topics().getSubscriptions(persistentTopicName).size(), 0);
 
 Review comment:
   This will be a flaky test since the consumer can create a subscription when 
they reconnect to the broker.

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