This is an automated email from the ASF dual-hosted git repository.
technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 5cabcacbfa8 [improve][admin] Fix the `createMissingPartitions` doesn't
response correctly (#22311)
5cabcacbfa8 is described below
commit 5cabcacbfa8874931d501cd040f7a8ac3d6d1923
Author: Jiwei Guo <[email protected]>
AuthorDate: Thu Mar 21 15:24:50 2024 +0800
[improve][admin] Fix the `createMissingPartitions` doesn't response
correctly (#22311)
---
.../org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java | 4 +++-
.../java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
index 10cf5edd3c3..86993f749b5 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
@@ -487,7 +487,7 @@ public class PersistentTopicsBase extends AdminResource {
protected void internalCreateMissedPartitions(AsyncResponse asyncResponse)
{
getPartitionedTopicMetadataAsync(topicName, false,
false).thenAccept(metadata -> {
- if (metadata != null) {
+ if (metadata != null && metadata.partitions > 0) {
CompletableFuture<Void> future =
validateNamespaceOperationAsync(topicName.getNamespaceObject(),
NamespaceOperation.CREATE_TOPIC);
future.thenCompose(__ ->
tryCreatePartitionsAsync(metadata.partitions)).thenAccept(v -> {
@@ -497,6 +497,8 @@ public class PersistentTopicsBase extends AdminResource {
resumeAsyncResponseExceptionally(asyncResponse, e);
return null;
});
+ } else {
+ throw new RestException(Status.NOT_FOUND, String.format("Topic
%s does not exist", topicName));
}
}).exceptionally(ex -> {
// If the exception is not redirect exception we need to log it.
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
index 23cb413614f..9a292175caa 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -1779,4 +1780,10 @@ public class PersistentTopicsTest extends
MockedPulsarServiceBaseTest {
assertTrue(namespaces.contains(ns1V2));
assertTrue(namespaces.contains(ns1V1));
}
+
+ @Test
+ public void testCreateMissingPartitions() throws Exception {
+ String topicName = "persistent://" + testTenant + "/" +
testNamespaceLocal + "/testCreateMissingPartitions";
+ assertThrows(PulsarAdminException.NotFoundException.class, () ->
admin.topics().createMissedPartitions(topicName));
+ }
}