You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/19 05:59:19 UTC

[GitHub] [pulsar] tisonkun commented on a diff in pull request #16655: fix:ReconsumeLater will hang up if retryLetterProducer exception

tisonkun commented on code in PR #16655:
URL: https://github.com/apache/pulsar/pull/16655#discussion_r924087864


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/RetryTopicTest.java:
##########
@@ -457,4 +462,58 @@ public void testRetryTopicByCustomTopicName() throws Exception {
         checkConsumer.close();
     }
 
+
+    @Test
+    public void testRetryTopicException() throws Exception {
+        final String topic = "persistent://my-property/my-ns/retry-topic";
+        final int maxRedeliveryCount = 2;
+        final int sendMessages = 1;
+        // subscribe before publish
+        Consumer<byte[]> consumer = pulsarClient.newConsumer(Schema.BYTES)
+                .topic(topic)
+                .subscriptionName("my-subscription")
+                .subscriptionType(SubscriptionType.Shared)
+                .enableRetry(true)
+                .receiverQueueSize(100)
+                .deadLetterPolicy(DeadLetterPolicy.builder()
+                        .maxRedeliverCount(maxRedeliveryCount)
+                        .retryLetterTopic("persistent://my-property/my-ns/my-subscription-custom-Retry")
+                        .build())
+                .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
+                .subscribe();
+
+        Producer<byte[]> producer = pulsarClient.newProducer(Schema.BYTES)
+                .topic(topic)
+                .create();
+        for (int i = 0; i < sendMessages; i++) {
+            producer.send(String.format("Hello Pulsar [%d]", i).getBytes());
+        }
+        producer.close();
+
+        // mock a retry producer exception when reconsumelater is called
+        MultiTopicsConsumerImpl multiTopicsConsumer = (MultiTopicsConsumerImpl) consumer;
+        List<ConsumerImpl> consumers = multiTopicsConsumer.getConsumers();
+        for (ConsumerImpl c : consumers) {
+            Set<Field> deadLetterPolicyField =
+                    ReflectionUtils.getAllFields(c.getClass(), ReflectionUtils.withName("deadLetterPolicy"));
+
+            if (deadLetterPolicyField.size() != 0) {
+                Field field = deadLetterPolicyField.iterator().next();
+                field.setAccessible(true);
+                DeadLetterPolicy deadLetterPolicy = (DeadLetterPolicy) field.get(c);
+                deadLetterPolicy.setRetryLetterTopic("#persistent://invlaid-topic#");
+            }
+        }

Review Comment:
   ```suggestion
           MultiTopicsConsumerImpl<byte[]> multiTopicsConsumer = (MultiTopicsConsumerImpl<byte[]>) consumer;
           List<ConsumerImpl<byte[]>> consumers = multiTopicsConsumer.getConsumers();
           for (ConsumerImpl<byte[]> c : consumers) {
               c.getDeadLetterPolicy().setRetryLetterTopic("#persistent://invlaid-topic#");
           }
   ```
   
   Instead of depending on reflection, I'd prefer to add a `@VisibleForTesting` method `getDeadLetterPolicy` in `ConsumerImpl`. I don't know whether it's the conventions in Pulsar, though.



##########
pulsar-broker/src/test/java/org/apache/pulsar/client/api/RetryTopicTest.java:
##########
@@ -457,4 +462,58 @@ public void testRetryTopicByCustomTopicName() throws Exception {
         checkConsumer.close();
     }
 
+
+    @Test

Review Comment:
   ```suggestion
       @Test(timeOut = 30000L)
   ```
   
   Since the original failure is hanging, we should add a timeout field here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org