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)
  • Loading branch information
Technoboy- authored Mar 21, 2024
1 parent fd34d4a commit 5cabcac
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 @@ -487,7 +487,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 @@ -497,6 +497,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 @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -1779,4 +1780,10 @@ public void testNamespaceResources() throws Exception {
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));
}
}

0 comments on commit 5cabcac

Please sign in to comment.