Skip to content

Commit

Permalink
[improve][admin] Fix the createMissingPartitions doesn't response c…
Browse files Browse the repository at this point in the history
…orrectly (apache#22311)

(cherry picked from commit 5cabcac)
(cherry picked from commit d4c0543)
  • Loading branch information
Technoboy- authored and mukesh-ctds committed Apr 19, 2024
1 parent 4014599 commit 3cbcd6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ protected CompletableFuture<Void> internalCreateNonPartitionedTopicAsync(boolean

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 -> {
Expand All @@ -510,6 +510,8 @@ protected void internalCreateMissedPartitions(AsyncResponse asyncResponse) {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertThrows;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -1811,4 +1812,10 @@ public void testUpdatePropertiesOnNonDurableSub() throws Exception {
assertEquals(cursor.getCursorProperties().size(), 1);
assertEquals(cursor.getCursorProperties().get("foo"), "bar");
}

@Test
public void testCreateMissingPartitions() throws Exception {
String topicName = "persistent://" + testTenant + "/" + testNamespaceLocal + "/testCreateMissingPartitions";
assertThrows(PulsarAdminException.NotFoundException.class, () -> admin.topics().createMissedPartitions(topicName));
}
}

0 comments on commit 3cbcd6f

Please sign in to comment.