You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xi...@apache.org on 2022/12/07 08:04:14 UTC

[pulsar] 01/02: Revert "[improve][admin] add topic name and sub name for NotFound error message (#15606)"

This is an automated email from the ASF dual-hosted git repository.

xiangying pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit d21f842ff36ae7f30a3768b74ad2a80d472c8ee0
Author: xiangying <19...@qq.com>
AuthorDate: Wed Dec 7 16:03:34 2022 +0800

    Revert "[improve][admin] add topic name and sub name for NotFound error message (#15606)"
    
    This reverts commit 6d86b0aa02345e4057aff86c1d970fd2e08848cf.
---
 .../apache/pulsar/broker/admin/AdminResource.java  |   8 --
 .../broker/admin/impl/PersistentTopicsBase.java    | 109 ++++++++-------------
 .../apache/pulsar/broker/admin/AdminApi2Test.java  |   2 -
 .../broker/admin/AdminApiSubscriptionTest.java     |  12 +--
 .../apache/pulsar/broker/admin/AdminApiTest.java   |  31 +-----
 .../pulsar/broker/admin/PersistentTopicsTest.java  |   3 +-
 .../org/apache/pulsar/broker/admin/TopicsTest.java |   4 +-
 7 files changed, 50 insertions(+), 119 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
index 08ca6c7f23e..6b964fafe7e 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
@@ -839,12 +839,4 @@ public abstract class AdminResource extends PulsarWebResource {
     protected static String getTopicNotFoundErrorMessage(String topic) {
         return String.format("Topic %s not found", topic);
     }
-
-    protected static String getPartitionedTopicNotFoundErrorMessage(String topic) {
-        return String.format("Partitioned Topic %s not found", topic);
-    }
-
-    protected static String getSubNotFoundErrorMessage(String topic, String subscription) {
-        return String.format("Subscription %s not found for topic %s", subscription, topic);
-    }
 }
\ No newline at end of file
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 196586fec96..956679df95b 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
@@ -591,7 +591,7 @@ public class PersistentTopicsBase extends AdminResource {
         return pulsar().getNamespaceService().checkTopicExists(topicName)
                 .thenAccept(exist -> {
                     if (!exist) {
-                        throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
+                        throw new RestException(Status.NOT_FOUND, "Topic not exist");
                     }
                 });
     }
@@ -664,8 +664,7 @@ public class PersistentTopicsBase extends AdminResource {
                     } else if (realCause instanceof MetadataStoreException.NotFoundException) {
                         log.warn("Namespace policies of {} not found", topicName.getNamespaceObject());
                         asyncResponse.resume(new RestException(
-                                new RestException(Status.NOT_FOUND,
-                                        getPartitionedTopicNotFoundErrorMessage(topicName.toString()))));
+                                new RestException(Status.NOT_FOUND, "Partitioned topic does not exist")));
                     } else if (realCause instanceof PulsarAdminException) {
                         asyncResponse.resume(new RestException((PulsarAdminException) realCause));
                     } else if (realCause instanceof MetadataStoreException.BadVersionException) {
@@ -1081,7 +1080,7 @@ public class PersistentTopicsBase extends AdminResource {
             if (t instanceof TopicBusyException) {
                 throw new RestException(Status.PRECONDITION_FAILED, "Topic has active producers/subscriptions");
             } else if (isManagedLedgerNotFoundException(e)) {
-                throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
+                throw new RestException(Status.NOT_FOUND, "Topic not found");
             } else {
                 throw new RestException(t);
             }
@@ -1307,8 +1306,7 @@ public class PersistentTopicsBase extends AdminResource {
                             if (exception != null) {
                                 Throwable t = exception.getCause();
                                 if (t instanceof NotFoundException) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getTopicNotFoundErrorMessage(topicName.toString())));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                                 } else {
                                     log.error("[{}] Failed to get managed info for {}", clientAppId(), topicName, t);
                                     asyncResponse.resume(new RestException(t));
@@ -1380,8 +1378,7 @@ public class PersistentTopicsBase extends AdminResource {
         future.thenCompose(__ -> getPartitionedTopicMetadataAsync(topicName,
                 authoritative, false)).thenAccept(partitionMetadata -> {
             if (partitionMetadata.partitions == 0) {
-                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                        getPartitionedTopicNotFoundErrorMessage(topicName.toString())));
+                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Partitioned Topic not found"));
                 return;
             }
             PartitionedTopicStatsImpl stats = new PartitionedTopicStatsImpl(partitionMetadata);
@@ -1455,8 +1452,7 @@ public class PersistentTopicsBase extends AdminResource {
         future.thenCompose(__ -> getPartitionedTopicMetadataAsync(topicName, authoritative, false))
                 .thenAccept(partitionMetadata -> {
             if (partitionMetadata.partitions == 0) {
-                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                        getPartitionedTopicNotFoundErrorMessage(topicName.toString())));
+                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Partitioned Topic not found"));
                 return;
             }
 
@@ -1544,8 +1540,7 @@ public class PersistentTopicsBase extends AdminResource {
                             if (exception != null) {
                                 Throwable t = exception.getCause();
                                 if (t instanceof NotFoundException) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                                     return null;
                                 } else if (t instanceof PreconditionFailedException) {
                                     asyncResponse.resume(new RestException(Status.PRECONDITION_FAILED,
@@ -1591,8 +1586,7 @@ public class PersistentTopicsBase extends AdminResource {
                 Topic topic = getTopicReference(topicName);
                 Subscription sub = topic.getSubscription(subName);
                 if (sub == null) {
-                    throw new RestException(Status.NOT_FOUND,
-                            getSubNotFoundErrorMessage(topicName.toString(), subName));
+                    throw new RestException(Status.NOT_FOUND, "Subscription not found");
                 }
                 return sub.delete();
             }).thenRun(() -> {
@@ -1707,8 +1701,7 @@ public class PersistentTopicsBase extends AdminResource {
                             if (exception != null) {
                                 Throwable t = exception.getCause();
                                 if (t instanceof NotFoundException) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                                     return null;
                                 } else {
                                     log.error("[{}] Failed to delete subscription forcefully {} {}",
@@ -1754,8 +1747,7 @@ public class PersistentTopicsBase extends AdminResource {
                     Topic topic = getTopicReference(topicName);
                     Subscription sub = topic.getSubscription(subName);
                     if (sub == null) {
-                        throw new RestException(Status.NOT_FOUND,
-                                getSubNotFoundErrorMessage(topicName.toString(), subName));
+                        throw new RestException(Status.NOT_FOUND, "Subscription not found");
                     }
                     return sub.deleteForcefully();
                 }).thenRun(() -> {
@@ -1813,8 +1805,7 @@ public class PersistentTopicsBase extends AdminResource {
                                     Throwable t = exception.getCause();
                                     if (t instanceof NotFoundException) {
                                         asyncResponse.resume(
-                                            new RestException(Status.NOT_FOUND,
-                                                    getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                            new RestException(Status.NOT_FOUND, "Subscription not found"));
                                     } else {
                                         log.error("[{}] Failed to skip all messages {} {}",
                                             clientAppId(), topicName, subName, t);
@@ -1862,16 +1853,14 @@ public class PersistentTopicsBase extends AdminResource {
                         PersistentReplicator repl =
                             (PersistentReplicator) topic.getPersistentReplicator(remoteCluster);
                         if (repl == null) {
-                            asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                    getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                            asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                             return CompletableFuture.completedFuture(null);
                         }
                         return repl.clearBacklog().whenComplete(biConsumer);
                     } else {
                         PersistentSubscription sub = topic.getSubscription(subName);
                         if (sub == null) {
-                            asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                    getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                            asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                             return CompletableFuture.completedFuture(null);
                         }
                         return sub.clearBacklog().whenComplete(biConsumer);
@@ -1907,8 +1896,7 @@ public class PersistentTopicsBase extends AdminResource {
                          return getTopicReferenceAsync(topicName).thenCompose(t -> {
                              PersistentTopic topic = (PersistentTopic) t;
                              if (topic == null) {
-                                 throw new RestException(new RestException(Status.NOT_FOUND,
-                                         getTopicNotFoundErrorMessage(topicName.toString())));
+                                 throw new RestException(new RestException(Status.NOT_FOUND, "Topic not found"));
                              }
                              if (subName.startsWith(topic.getReplicatorPrefix())) {
                                  String remoteCluster = PersistentReplicator.getRemoteCluster(subName);
@@ -1928,8 +1916,7 @@ public class PersistentTopicsBase extends AdminResource {
                                  PersistentSubscription sub = topic.getSubscription(subName);
                                  if (sub == null) {
                                      return FutureUtil.failedFuture(
-                                             new RestException(Status.NOT_FOUND,
-                                                     getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                             new RestException(Status.NOT_FOUND, "Subscription not found"));
                                  }
                                  return sub.skipMessages(numMessages).thenAccept(unused -> {
                                      log.info("[{}] Skipped {} messages on {} {}", clientAppId(), numMessages,
@@ -2030,7 +2017,7 @@ public class PersistentTopicsBase extends AdminResource {
                 .thenCompose(__ -> getTopicReferenceAsync(topicName).thenAccept(t -> {
                      if (t == null) {
                          resumeAsyncResponseExceptionally(asyncResponse, new RestException(Status.NOT_FOUND,
-                                 getTopicNotFoundErrorMessage(topicName.toString())));
+                                 "Topic not found"));
                          return;
                      }
                     if (!(t instanceof PersistentTopic)) {
@@ -2176,7 +2163,7 @@ public class PersistentTopicsBase extends AdminResource {
             .thenCompose(topic -> {
                 Subscription sub = topic.getSubscription(subName);
                 if (sub == null) {
-                   throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
+                   throw new RestException(Status.NOT_FOUND, "Subscription not found");
                 }
                 return sub.resetCursor(timestamp);
             })
@@ -2537,14 +2524,12 @@ public class PersistentTopicsBase extends AdminResource {
                         .thenCompose(ignore -> getTopicReferenceAsync(topicName))
                         .thenAccept(topic -> {
                                 if (topic == null) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getTopicNotFoundErrorMessage(topicName.toString())));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                                     return;
                                 }
                                 PersistentSubscription sub = ((PersistentTopic) topic).getSubscription(subName);
                                 if (sub == null) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                                     return;
                                 }
                                 CompletableFuture<Integer> batchSizeFuture = new CompletableFuture<>();
@@ -3109,7 +3094,7 @@ public class PersistentTopicsBase extends AdminResource {
                                                 messageId.getEntryId());
                                         if (topic == null) {
                                             asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                                    getTopicNotFoundErrorMessage(topicName.toString())));
+                                                    "Topic not found"));
                                             return;
                                         }
                                         ManagedLedgerImpl managedLedger =
@@ -3507,7 +3492,7 @@ public class PersistentTopicsBase extends AdminResource {
                 .thenCompose(__ -> checkTopicExistsAsync(topicName))
                 .thenCompose(exist -> {
                     if (!exist) {
-                        throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
+                        throw new RestException(Status.NOT_FOUND, "Topic not found");
                     } else {
                         return getPartitionedTopicMetadataAsync(topicName, false, false)
                             .thenCompose(metadata -> {
@@ -3639,8 +3624,7 @@ public class PersistentTopicsBase extends AdminResource {
                             if (exception != null) {
                                 Throwable t = exception.getCause();
                                 if (t instanceof NotFoundException) {
-                                    asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                            getTopicNotFoundErrorMessage(topicName.toString())));
+                                    asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                                 } else {
                                     log.error("[{}] Failed to terminate topic {}", clientAppId(), topicName, t);
                                     asyncResponse.resume(new RestException(t));
@@ -3716,8 +3700,7 @@ public class PersistentTopicsBase extends AdminResource {
                                                         Throwable t = exception.getCause();
                                                         if (t instanceof NotFoundException) {
                                                             asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                                                    getSubNotFoundErrorMessage(topicName.toString(),
-                                                                            subName)));
+                                                                    "Subscription not found"));
                                                             return null;
                                                         } else {
                                                             log.error("[{}] Failed to expire messages up "
@@ -3760,8 +3743,7 @@ public class PersistentTopicsBase extends AdminResource {
             final CompletableFuture<Void> resultFuture = new CompletableFuture<>();
             getTopicReferenceAsync(topicName).thenAccept(t -> {
                  if (t == null) {
-                     resultFuture.completeExceptionally(new RestException(Status.NOT_FOUND,
-                             getTopicNotFoundErrorMessage(topicName.toString())));
+                     resultFuture.completeExceptionally(new RestException(Status.NOT_FOUND, "Topic not found"));
                      return;
                  }
                 if (!(t instanceof PersistentTopic)) {
@@ -3786,8 +3768,7 @@ public class PersistentTopicsBase extends AdminResource {
                     PersistentSubscription sub = topic.getSubscription(subName);
                     if (sub == null) {
                         resultFuture.completeExceptionally(
-                                new RestException(Status.NOT_FOUND,
-                                        getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                new RestException(Status.NOT_FOUND, "Subscription not found"));
                         return;
                     }
                     issued = sub.expireMessages(expireTimeInSeconds);
@@ -3871,15 +3852,14 @@ public class PersistentTopicsBase extends AdminResource {
         return getTopicReferenceAsync(topicName).thenAccept(t -> {
             PersistentTopic topic = (PersistentTopic) t;
             if (topic == null) {
-                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                        getTopicNotFoundErrorMessage(topicName.toString())));
+                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                 return;
             }
             try {
                 PersistentSubscription sub = topic.getSubscription(subName);
                 if (sub == null) {
                     asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                            getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                            "Subscription not found"));
                     return;
                 }
                 CompletableFuture<Integer> batchSizeFuture = new CompletableFuture<>();
@@ -4208,7 +4188,7 @@ public class PersistentTopicsBase extends AdminResource {
 
     private RestException topicNotFoundReason(TopicName topicName) {
         if (!topicName.isPartitioned()) {
-            return new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString()));
+            return new RestException(Status.NOT_FOUND, "Topic not found");
         }
 
         PartitionedTopicMetadata partitionedTopicMetadata = getPartitionedTopicMetadata(
@@ -4221,13 +4201,12 @@ public class PersistentTopicsBase extends AdminResource {
         } else if (!internalGetList(Optional.empty()).contains(topicName.toString())) {
             return new RestException(Status.NOT_FOUND, "Topic partitions were not yet created");
         }
-        return new RestException(Status.NOT_FOUND, getPartitionedTopicNotFoundErrorMessage(topicName.toString()));
+        return new RestException(Status.NOT_FOUND, "Partitioned Topic not found");
     }
 
     private CompletableFuture<Topic> topicNotFoundReasonAsync(TopicName topicName) {
         if (!topicName.isPartitioned()) {
-            return FutureUtil.failedFuture(new RestException(Status.NOT_FOUND,
-                    getTopicNotFoundErrorMessage(topicName.toString())));
+            return FutureUtil.failedFuture(new RestException(Status.NOT_FOUND, "Topic not found"));
         }
 
         return getPartitionedTopicMetadataAsync(
@@ -4241,8 +4220,7 @@ public class PersistentTopicsBase extends AdminResource {
                     } else if (!internalGetList(Optional.empty()).contains(topicName.toString())) {
                         throw new RestException(Status.NOT_FOUND, "Topic partitions were not yet created");
                     }
-                    throw new RestException(Status.NOT_FOUND,
-                            getPartitionedTopicNotFoundErrorMessage(topicName.toString()));
+                    throw new RestException(Status.NOT_FOUND, "Partitioned Topic not found");
                 });
     }
 
@@ -4264,7 +4242,7 @@ public class PersistentTopicsBase extends AdminResource {
 
             return checkNotNull(sub);
         } catch (Exception e) {
-            throw new RestException(Status.NOT_FOUND, getSubNotFoundErrorMessage(topicName.toString(), subName));
+            throw new RestException(Status.NOT_FOUND, "Subscription not found");
         }
     }
 
@@ -4542,8 +4520,7 @@ public class PersistentTopicsBase extends AdminResource {
                 .thenCompose(__ -> getTopicReferenceAsync(topicName))
                 .thenAccept(topic -> {
                     if (topic == null) {
-                        asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                getTopicNotFoundErrorMessage(topicName.toString())));
+                        asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                         return;
                     }
                     if (!(topic instanceof PersistentTopic)) {
@@ -5002,15 +4979,13 @@ public class PersistentTopicsBase extends AdminResource {
                 .thenCompose(__ -> getTopicReferenceAsync(topicName))
                 .thenAccept(topic -> {
                             if (topic == null) {
-                                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                        getTopicNotFoundErrorMessage(topicName.toString())));
+                                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                                 return;
                             }
 
                             Subscription sub = topic.getSubscription(subName);
                             if (sub == null) {
-                                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                        getSubNotFoundErrorMessage(topicName.toString(), subName)));
+                                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
                                 return;
                             }
 
@@ -5141,17 +5116,15 @@ public class PersistentTopicsBase extends AdminResource {
 
             Topic topic = getTopicReference(topicName);
             if (topic == null) {
-                asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                 getTopicNotFoundErrorMessage(topicName.toString())));
+                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Topic not found"));
                 return;
             }
 
-                    Subscription sub = topic.getSubscription(subName);
-                    if (sub == null) {
-                        asyncResponse.resume(new RestException(Status.NOT_FOUND,
-                                getSubNotFoundErrorMessage(topicName.toString(), subName)));
-                        return;
-                    }
+            Subscription sub = topic.getSubscription(subName);
+            if (sub == null) {
+                asyncResponse.resume(new RestException(Status.NOT_FOUND, "Subscription not found"));
+                return;
+            }
 
             if (topic instanceof PersistentTopic && sub instanceof PersistentSubscription) {
                 Map res = Maps.newHashMap();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
index 8399074886d..3cb67eada5e 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
@@ -585,7 +585,6 @@ public class AdminApi2Test extends MockedPulsarServiceBaseTest {
             admin.topics().resetCursor(topicName + "invalid", "my-sub", messageId);
             fail("It should have failed due to invalid topic name");
         } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains(topicName));
             // Ok
         }
 
@@ -594,7 +593,6 @@ public class AdminApi2Test extends MockedPulsarServiceBaseTest {
             admin.topics().resetCursor(topicName, "invalid-sub", messageId);
             fail("It should have failed due to invalid subscription name");
         } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains("invalid-sub"));
             // Ok
         }
 
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiSubscriptionTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiSubscriptionTest.java
index 411565521d9..521ef4df1c8 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiSubscriptionTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiSubscriptionTest.java
@@ -72,18 +72,18 @@ public class AdminApiSubscriptionTest extends MockedPulsarServiceBaseTest {
     @Test
     public void testExpireMessageWithNonExistTopicAndNonExistSub() {
         String uuid = UUID.randomUUID().toString();
-        String topic = "persistent://public/default/test-expire-messages-non-exist-topic-" + uuid;
+        String topic = "test-expire-messages-non-exist-topic-" + uuid;
         String subscriptionName = "test-expire-messages-non-exist-sub-" + uuid;
 
         PulsarAdminException exception = expectThrows(PulsarAdminException.class,
                 () -> admin.topics().expireMessages(topic, subscriptionName, 1));
         assertEquals(exception.getStatusCode(), Response.Status.NOT_FOUND.getStatusCode());
-        assertEquals(exception.getMessage(), String.format("Topic %s not found", topic));
+        assertEquals(exception.getMessage(), "Topic not found");
 
         exception = expectThrows(PulsarAdminException.class,
                 () -> admin.topics().expireMessagesForAllSubscriptions(topic, 1));
         assertEquals(exception.getStatusCode(), Response.Status.NOT_FOUND.getStatusCode());
-        assertEquals(exception.getMessage(), String.format("Topic %s not found", topic));
+        assertEquals(exception.getMessage(), "Topic not found");
     }
 
     @Test
@@ -100,18 +100,18 @@ public class AdminApiSubscriptionTest extends MockedPulsarServiceBaseTest {
     @Test
     public void tesSkipMessageWithNonExistTopicAndNotExistSub() {
         String uuid = UUID.randomUUID().toString();
-        String topic = "persistent://public/default/test-skip-messages-non-exist-topic-" + uuid;
+        String topic = "test-skip-messages-non-exist-topic-" + uuid;
         String subscriptionName = "test-skip-messages-non-exist-sub-" + uuid;
 
         PulsarAdminException exception = expectThrows(PulsarAdminException.class,
                 () -> admin.topics().skipMessages(topic, subscriptionName, 1));
         assertEquals(exception.getStatusCode(), Response.Status.NOT_FOUND.getStatusCode());
-        assertEquals(exception.getMessage(), String.format("Topic %s not found", topic));
+        assertEquals(exception.getMessage(), "Topic not found");
 
         exception = expectThrows(PulsarAdminException.class,
                 () -> admin.topics().skipAllMessages(topic, subscriptionName));
         assertEquals(exception.getStatusCode(), Response.Status.NOT_FOUND.getStatusCode());
-        assertEquals(exception.getMessage(), String.format("Topic %s not found", topic));
+        assertEquals(exception.getMessage(), "Topic not found");
     }
 
     @DataProvider(name = "partitioned")
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
index b2ebd2c1f6d..1c6e469935d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
@@ -892,7 +892,6 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
         try {
             admin.topics().skipAllMessages(persistentTopicName, subName);
         } catch (NotFoundException e) {
-            assertTrue(e.getMessage().contains(subName));
         }
 
         admin.topics().delete(persistentTopicName);
@@ -901,7 +900,6 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
             admin.topics().delete(persistentTopicName);
             fail("Should have received 404");
         } catch (NotFoundException e) {
-            assertTrue(e.getMessage().contains(persistentTopicName));
         }
 
         assertEquals(admin.topics().getList("prop-xyz/ns1"), Lists.newArrayList());
@@ -1102,7 +1100,6 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
             admin.topics().deletePartitionedTopic(anotherTopic);
             fail("Should have failed as the partitioned topic was not created");
         } catch (NotFoundException nfe) {
-            assertTrue(nfe.getMessage().contains(anotherTopic));
         }
 
         admin.topics().deletePartitionedTopic(partitionedTopicName);
@@ -1936,7 +1933,7 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
             admin.topics().getStats("persistent://prop-xyz/ns1/ghostTopic");
             fail("The topic doesn't exist");
         } catch (NotFoundException e) {
-            assertTrue(e.getMessage().contains("persistent://prop-xyz/ns1/ghostTopic"));
+            // OK
         }
     }
 
@@ -2026,20 +2023,6 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
 
         topicName = "persistent://prop-xyz/ns1/" + topicName;
 
-        try {
-            admin.topics().resetCursor(topicName, "my-sub", System.currentTimeMillis());
-        } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains(topicName));
-        }
-
-        admin.topics().createNonPartitionedTopic(topicName);
-
-        try {
-            admin.topics().resetCursor(topicName, "my-sub", System.currentTimeMillis());
-        } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains("my-sub"));
-        }
-
         // create consumer and subscription
         Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName)
                 .subscriptionName("my-sub").startMessageIdInclusive()
@@ -2232,20 +2215,8 @@ public class AdminApiTest extends MockedPulsarServiceBaseTest {
         admin.namespaces().setRetention("prop-xyz/ns1", new RetentionPolicies(10, 10));
         topicName = "persistent://prop-xyz/ns1/" + topicName;
 
-        try {
-            admin.topics().resetCursor(topicName, "my-sub", System.currentTimeMillis());
-        } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains(topicName));
-        }
-
         admin.topics().createPartitionedTopic(topicName, 4);
 
-        try {
-            admin.topics().resetCursor(topicName, "my-sub", System.currentTimeMillis());
-        } catch (PulsarAdminException.NotFoundException e) {
-            assertTrue(e.getMessage().contains("my-sub"));
-        }
-
         // create consumer and subscription
         Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName)
                 .subscriptionName("my-sub").startMessageIdInclusive()
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 44de487113d..bd86a666c0f 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
@@ -172,8 +172,7 @@ public class PersistentTopicsTest extends MockedPulsarServiceBaseTest {
         verify(response, timeout(5000).times(1)).resume(errorCaptor.capture());
         Assert.assertEquals(errorCaptor.getValue().getResponse().getStatus(),
                 Response.Status.NOT_FOUND.getStatusCode());
-        Assert.assertEquals(errorCaptor.getValue().getMessage(), String.format("Topic %s not found",
-                "persistent://my-tenant/my-namespace/topic-not-found"));
+        Assert.assertEquals(errorCaptor.getValue().getMessage(), "Topic not found");
 
         // 2) Confirm that the partitioned topic does not exist
         response = mock(AsyncResponse.class);
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicsTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicsTest.java
index 3327b83b6ae..35e205f2dc9 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicsTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicsTest.java
@@ -383,9 +383,7 @@ public class TopicsTest extends MockedPulsarServiceBaseTest {
         topics.produceOnPersistentTopic(asyncResponse, testTenant, testNamespace, testTopicName, false, producerMessages);
         ArgumentCaptor<RestException> responseCaptor = ArgumentCaptor.forClass(RestException.class);
         verify(asyncResponse, timeout(5000).times(1)).resume(responseCaptor.capture());
-        System.out.println(responseCaptor.getValue().getMessage());
-        Assert.assertTrue(responseCaptor.getValue().getMessage()
-                .contains(String.format("Topic %s not found", topicName)));
+        Assert.assertTrue(responseCaptor.getValue().getMessage().contains("Topic not exist"));
     }
 
     @Test