From d3bed6a77d0d3538ad7e3deceba24f05d8bde56b Mon Sep 17 00:00:00 2001 From: houbonan Date: Thu, 28 Nov 2024 17:53:50 +0800 Subject: [PATCH] [fix][admin] Fix exception loss in getMessageId method --- .../pulsar/broker/admin/impl/PersistentTopicsBase.java | 7 ++++--- .../apache/pulsar/broker/admin/PersistentTopicsTest.java | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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 1300cd3449c27..4b9fea05cd885 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 @@ -2774,9 +2774,10 @@ protected CompletableFuture internalGetMessageById(long ledgerId, long public void readEntryFailed(ManagedLedgerException exception, Object ctx) { if (exception instanceof ManagedLedgerException.LedgerNotExistException) { - throw new RestException(Status.NOT_FOUND, "Message id not found"); + results.completeExceptionally( + new RestException(Status.NOT_FOUND, "Message id not found")); } - throw new RestException(exception); + results.completeExceptionally(new RestException(exception)); } @Override @@ -2784,7 +2785,7 @@ public void readEntryComplete(Entry entry, Object ctx) { try { results.complete(generateResponseWithEntry(entry, (PersistentTopic) topic)); } catch (IOException exception) { - throw new RestException(exception); + results.completeExceptionally(new RestException(exception)); } finally { if (entry != null) { entry.release(); 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 302948903442c..258c0183114fd 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 @@ -1419,6 +1419,10 @@ public void testGetMessageById() throws Exception { Assert.expectThrows(PulsarAdminException.NotFoundException.class, () -> { admin.topics().getMessageById(topicName1, id2.getLedgerId(), id2.getEntryId()); }); + + Assert.expectThrows(PulsarAdminException.ServerSideErrorException.class, () -> { + admin.topics().getMessageById(topicName1, id1.getLedgerId(), id1.getEntryId() + 10); + }); } @Test