You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/06/25 04:01:05 UTC

[pulsar] 02/07: When topic does not exist, optimize the prompt message (#10845)

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

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

commit b20da1c64a3135af98b72ca6dd3367ee24806525
Author: feynmanlin <fe...@tencent.com>
AuthorDate: Tue Jun 8 20:02:07 2021 +0800

    When topic does not exist, optimize the prompt message (#10845)
    
    ### Motivation
    If we set enableRetry=true, the client will subscribe to the retry topic.
    If we set AllowAutoTopicCreation=false, the client will receive `Topic dose not exists`, which means that the retry Topic does not exists.
    This makes users very confused. My topic clearly exists, why is it still prompted like this?
    Therefore, the prompt information is improved to facilitate users to troubleshoot problems.
    
    ### Modifications
    add topic name to the returning message
    
    (cherry picked from commit e72a0d8d63baf336ac4fd4bf045e40de365e58eb)
---
 .../org/apache/pulsar/broker/service/ServerCnx.java |  3 ++-
 .../client/api/SimpleProducerConsumerTest.java      | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index 4445f64..c446833 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -986,7 +986,8 @@ public class ServerCnx extends PulsarHandler implements TransportCnx {
                                 .thenCompose(optTopic -> {
                                     if (!optTopic.isPresent()) {
                                         return FutureUtil
-                                                .failedFuture(new TopicNotFoundException("Topic does not exist"));
+                                                .failedFuture(new TopicNotFoundException(
+                                                        "Topic " + topicName + " does not exist"));
                                     }
 
                                     Topic topic = optTopic.get();
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
index f66f222..5ebb2fb 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
@@ -4051,6 +4051,27 @@ public class SimpleProducerConsumerTest extends ProducerConsumerBase {
         assertEquals(1, res.getFields().size());
     }
 
+    @Test
+    public void testTopicDoesNotExists() throws Exception {
+        cleanup();
+        conf.setAllowAutoTopicCreation(false);
+        setup();
+        String topic = "persistent://my-property/my-ns/none" + UUID.randomUUID();
+        admin.topics().createPartitionedTopic(topic, 3);
+        try {
+            @Cleanup
+            Consumer<byte[]> consumer = pulsarClient.newConsumer()
+                    .enableRetry(true)
+                    .topic(topic).subscriptionName("sub").subscribe();
+            fail("should fail");
+        } catch (Exception e) {
+            String retryTopic = topic + "-sub-RETRY";
+            assertTrue(e.getMessage().contains("Topic " + retryTopic + " does not exist"));
+        } finally {
+            conf.setAllowAutoTopicCreation(true);
+        }
+    }
+
     /**
      * Test validates that consumer of partitioned-topic utilizes threads of all partitioned-consumers and slow-listener
      * of one of the partition doesn't impact listener-processing of other partition.