Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ public void deletePartitionedTopic(
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,4 +75,30 @@ public void testAutoCreatePartitionTopicWithKeywordAndDeleteIt()
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
}
}
}