You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/03/05 03:57:33 UTC

[GitHub] [pulsar] murong00 commented on a change in pull request #6383: [Issue 6043] Support force deleting subscription

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

 ##########
 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:
   I hava fixed the unit test to cover this.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services