This is an automated email from the ASF dual-hosted git repository.
mattisonchao pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.11 by this push:
new 155df661476 [improve][broker] Follow up #19230 to tighten the
validation scope (#19234) (#19839)
155df661476 is described below
commit 155df661476021eb7c320d11ccbd192a81416a4f
Author: Qiang Zhao <[email protected]>
AuthorDate: Fri Mar 17 12:32:14 2023 +0800
[improve][broker] Follow up #19230 to tighten the validation scope (#19234)
(#19839)
---
.../pulsar/broker/admin/v2/PersistentTopics.java | 5 ++++
.../PartitionKeywordCompatibilityTest.java | 27 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
index 09d6e53974b..f5b120f67a5 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
@@ -995,6 +995,11 @@ public class PersistentTopics extends PersistentTopicsBase
{
@QueryParam("authoritative") @DefaultValue("false") boolean
authoritative) {
try {
validateTopicName(tenant, namespace, encodedTopic);
+ if (topicName.isPartitioned()) {
+ // There's no way to create the partition topic with
`-partition-{index}`, So we can reject it.
+ throw new RestException(Response.Status.PRECONDITION_FAILED,
+ "Partitioned Topic Name should not contain
'-partition-'");
+ }
internalDeletePartitionedTopic(asyncResponse, authoritative,
force);
} catch (WebApplicationException wae) {
asyncResponse.resume(wae);
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
index f815fef1c87..afa5231c939 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
@@ -19,6 +19,7 @@
package org.apache.pulsar.broker.service.persistent;
+import static org.testng.Assert.fail;
import lombok.Cleanup;
import org.apache.pulsar.broker.service.BrokerTestBase;
import org.apache.pulsar.client.admin.PulsarAdminException;
@@ -74,4 +75,30 @@ public class PartitionKeywordCompatibilityTest extends
BrokerTestBase {
Assert.assertFalse(topics.contains(topicName));
Assert.assertFalse(partitionedTopicList.contains(topicName));
}
+
+ @Test
+ public void testDeletePartitionedTopicValidation() throws
PulsarAdminException {
+ final String topicName =
"persistent://public/default/testDeletePartitionedTopicValidation";
+ final String partitionKeywordTopic =
"persistent://public/default/testDelete-partition-edTopicValidation";
+ final String partitionedTopic =
"persistent://public/default/testDeletePartitionedTopicValidation-partition-0";
+ try {
+ admin.topics().deletePartitionedTopic(topicName);
+ fail("expect not found!");
+ } catch (PulsarAdminException.NotFoundException ex) {
+ //ok
+ }
+ try {
+ admin.topics().deletePartitionedTopic(partitionKeywordTopic);
+ fail("expect not found!");
+ } catch (PulsarAdminException.NotFoundException ex) {
+ //ok
+ }
+ try {
+ admin.topics().deletePartitionedTopic(partitionedTopic);
+ fail("expect illegal argument");
+ } catch (PulsarAdminException.PreconditionFailedException ex) {
+ Assert.assertTrue(ex.getMessage().contains("should not contain
'-partition-'"));
+ // ok
+ }
+ }
}