Skip to content

Commit

Permalink
[admin][broker] Fix force delete subscription not working (apache#22423)
Browse files Browse the repository at this point in the history
(cherry picked from commit 110add0)
  • Loading branch information
dao-jun authored and srinath-ctds committed Apr 23, 2024
1 parent 8f3e1fd commit a5b9be3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ protected CompletableFuture<Void> internalDeleteSubscriptionAsync(String subName
for (int i = 0; i < partitionMetadata.partitions; i++) {
TopicName topicNamePartition = topicName.getPartition(i);
futures.add(adminClient.topics()
.deleteSubscriptionAsync(topicNamePartition.toString(), subName, false));
.deleteSubscriptionAsync(topicNamePartition.toString(), subName, force));
}

return FutureUtil.waitForAll(futures).handle((result, exception) -> {
Expand All @@ -1596,8 +1596,7 @@ protected CompletableFuture<Void> internalDeleteSubscriptionAsync(String subName
return null;
});
}
return internalDeleteSubscriptionForNonPartitionedTopicAsync(subName, authoritative,
force);
return internalDeleteSubscriptionForNonPartitionedTopicAsync(subName, authoritative, force);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@
import org.apache.pulsar.client.admin.Topics;
import org.apache.pulsar.client.admin.internal.TopicsImpl;
import org.apache.pulsar.client.api.CompressionType;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.Reader;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.SubscriptionType;
import org.apache.pulsar.client.api.interceptor.ProducerInterceptor;
import org.apache.pulsar.client.impl.BatchMessageIdImpl;
import org.apache.pulsar.client.impl.MessageIdImpl;
Expand Down Expand Up @@ -1781,6 +1783,34 @@ public void testNamespaceResources() throws Exception {
assertTrue(namespaces.contains(ns1V1));
}

@Test
public void testForceDeleteSubscription() throws Exception {
try {
pulsar.getConfiguration().setAllowAutoSubscriptionCreation(false);
String topicName = "persistent://" + testTenant + "/" + testNamespaceLocal + "/testForceDeleteSubscription";
String subName = "sub1";
admin.topics().createNonPartitionedTopic(topicName);
admin.topics().createSubscription(topicName, subName, MessageId.latest);

@Cleanup
Consumer<String> c0 = pulsarClient.newConsumer(Schema.STRING)
.topic(topicName)
.subscriptionName(subName)
.subscriptionType(SubscriptionType.Shared)
.subscribe();
@Cleanup
Consumer<String> c1 = pulsarClient.newConsumer(Schema.STRING)
.topic(topicName)
.subscriptionName(subName)
.subscriptionType(SubscriptionType.Shared)
.subscribe();

admin.topics().deleteSubscription(topicName, subName, true);
} finally {
pulsar.getConfiguration().setAllowAutoSubscriptionCreation(true);
}
}

@Test
public void testUpdatePropertiesOnNonDurableSub() throws Exception {
String topic = "persistent://" + testTenant + "/" + testNamespaceLocal + "/testUpdatePropertiesOnNonDurableSub";
Expand Down

0 comments on commit a5b9be3

Please sign in to comment.