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 @@ -660,8 +660,10 @@ private CompletableFuture<Void> internalUpdateNonPartitionedTopicProperties(Map<
pulsar().getBrokerService().getTopicIfExists(topicName.toString())
.thenAccept(opt -> {
if (!opt.isPresent()) {
throw new RestException(Status.NOT_FOUND,
getTopicNotFoundErrorMessage(topicName.toString()));
future.completeExceptionally(
new WebApplicationException(getTopicNotFoundErrorMessage(topicName.toString()),
Status.NOT_FOUND));
return;
}
ManagedLedger managedLedger = ((PersistentTopic) opt.get()).getManagedLedger();
managedLedger.asyncSetProperties(properties, new AsyncCallbacks.UpdatePropertiesCallback() {
Expand All @@ -681,6 +683,9 @@ public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx)
future.completeExceptionally(exception);
}
}, null);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Expand Down Expand Up @@ -717,8 +722,10 @@ private CompletableFuture<Void> internalRemoveNonPartitionedTopicProperties(Stri
pulsar().getBrokerService().getTopicIfExists(topicName.toString())
.thenAccept(opt -> {
if (!opt.isPresent()) {
throw new RestException(Status.NOT_FOUND,
getTopicNotFoundErrorMessage(topicName.toString()));
future.completeExceptionally(
new WebApplicationException(getTopicNotFoundErrorMessage(topicName.toString()),
Status.NOT_FOUND));
return;
}
ManagedLedger managedLedger = ((PersistentTopic) opt.get()).getManagedLedger();
managedLedger.asyncDeleteProperty(key, new AsyncCallbacks.UpdatePropertiesCallback() {
Expand All @@ -733,6 +740,9 @@ public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx)
future.completeExceptionally(exception);
}
}, null);
}).exceptionally(ex -> {
future.completeExceptionally(ex);
return null;
});
return future;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,35 @@ public void testUpdateNonPartitionedTopicProperties() throws Exception {
Assert.assertEquals(properties.get("key2"), "value2");
}

@Test
public void testUpdatePropertiesOnNonExistentTopic() throws Exception {
final String namespace = newUniqueName(defaultTenant + "/ns2");
final String topicName = "persistent://" + namespace + "/testUpdatePropertiesOnNonExistentTopic";
admin.namespaces().createNamespace(namespace, 20);

// Test updateProperties on non-existent topic should return 404 Not Found
Map<String, String> topicProperties = new HashMap<>();
topicProperties.put("key1", "value1");
try {
admin.topics().updateProperties(topicName, topicProperties);
fail("Should have thrown an exception for non-existent topic");
} catch (Exception e) {
Assert.expectThrows(PulsarAdminException.NotFoundException.class, () -> {
throw e;
});
}

// Test removeProperties on non-existent topic should return 404 Not Found
try {
admin.topics().removeProperties(topicName, "key1");
fail("Should have thrown an exception for non-existent topic");
} catch (PulsarAdminException.NotFoundException e) {
Assert.expectThrows(PulsarAdminException.NotFoundException.class, () -> {
throw e;
});
}
}

@Test
public void testNonPersistentTopics() throws Exception {
final String namespace = newUniqueName(defaultTenant + "/ns2");
Expand Down
Loading