Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] Follow up #19230 to tighten the validation scope #19234

Merged
merged 2 commits into from Jan 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1034,6 +1034,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
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
}
}
}