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/06/01 07:29:35 UTC

[GitHub] [pulsar] mattisonchao commented on a diff in pull request #15852: [fix][client] `ZeroQueueConsumer` may not increase the permit after unloading the topic.

mattisonchao commented on code in PR #15852:
URL: https://github.com/apache/pulsar/pull/15852#discussion_r886403707


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ZeroQueueSizeTest.java:
##########
@@ -546,4 +548,48 @@ public void testPauseAndResumeNoReconnection() throws Exception {
             assertEquals(receivedMessages.get(i).intValue(), i);
         }
     }
+
+    @Test(timeOut = 30000)
+    public void testReceiveAsyncWhenUnloadTopic() throws PulsarClientException, ExecutionException, InterruptedException, PulsarAdminException {
+        final String topicName = "persistent://prop/cluster/namespace/topic-" + UUID.randomUUID();
+        int messageNumber = 500;
+        List<MessageId> messages = Collections.synchronizedList(new ArrayList<>());
+        @Cleanup
+        Consumer<byte[]> subscribe = pulsarClient.newConsumer()
+                .topic(topicName)
+                .subscriptionName("sub-11")
+                .subscriptionType(SubscriptionType.Shared)
+                .receiverQueueSize(0)
+                .consumerName("con-11")
+                .subscribe();
+
+        @Cleanup
+        Producer<byte[]> producer = pulsarClient.newProducer()
+                .enableBatching(false)
+                .messageRoutingMode(MessageRoutingMode.RoundRobinPartition)
+                .topic(topicName).create();
+        for (int i = 0; i < messageNumber; i++) {
+            MessageId msgId = producer.newMessage()
+                    .value(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8))
+                    .send();
+            messages.add(msgId);
+        }
+
+        boolean isUnload = false;
+        do {
+            Message<byte[]> message;
+            try {
+                message = subscribe.receiveAsync().get(5, TimeUnit.SECONDS);
+                if (message != null) {
+                    subscribe.acknowledge(message);
+                    messages.remove(message.getMessageId());
+                }
+            } catch (TimeoutException e) {
+            }
+            if (!isUnload) {
+                admin.topics().unload(topicName);
+                isUnload = true;
+            }
+        } while (messages.size() != 0);

Review Comment:
   Got it!



-- 
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