murong00 commented on a change in pull request #6383: [Issue 6043] Support
force deleting subscription
URL: https://github.com/apache/pulsar/pull/6383#discussion_r382900619
##########
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:
yes, maybe we can disable this line in this pr first and then refine it
later when the ability to disable the subscription auto-creation is available?
----------------------------------------------------------------
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