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 2021/01/12 04:09:45 UTC

[GitHub] [pulsar] BewareMyPower commented on a change in pull request #9182: Fix incoming message size issue that introduced in #9113

BewareMyPower commented on a change in pull request #9182:
URL: https://github.com/apache/pulsar/pull/9182#discussion_r555501885



##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java
##########
@@ -3692,4 +3693,88 @@ public void testGetStatsForPartitionedTopic() throws Exception {
         consumer.close();
         producer.close();
     }
+
+    @Test
+    public void testIncomingMessageSizeForNonPartitionedTopic() throws Exception {
+        final String topicName = "persistent://my-property/my-ns/testIncomingMessageSizeForNonPartitionedTopic-" +
+                UUID.randomUUID().toString();
+        final String subName = "my-sub";
+
+        @Cleanup
+        Consumer<byte[]> consumer = pulsarClient.newConsumer()
+                .topic(topicName)
+                .subscriptionName(subName)
+                .subscribe();
+
+        @Cleanup
+        Producer<byte[]> producer = pulsarClient.newProducer()
+                .topic(topicName)
+                .create();
+
+        final int messages = 100;
+        List<CompletableFuture<MessageId>> messageIds = new ArrayList<>(messages);
+        for (int i = 0; i < messages; i++) {
+            messageIds.add(producer.newMessage().value(("Message-" + i).getBytes()).sendAsync());
+        }
+        FutureUtil.waitForAll(messageIds).get();
+
+        Awaitility.await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            long size = ((ConsumerBase<byte[]>) consumer).getIncomingMessageSize();
+            log.info("Check the incoming message size should greater that 0, current size is {}", size);
+            Assert.assertTrue(size > 0);
+        });
+
+        for (int i = 0; i < messages; i++) {
+            consumer.acknowledge(consumer.receive());
+        }
+
+        Awaitility.await().atMost(3, TimeUnit.SECONDS).untilAsserted(() -> {
+            long size = ((ConsumerBase<byte[]>) consumer).getIncomingMessageSize();
+            log.info("Check the incoming message size should be 0, current size is {}", size);
+            Assert.assertEquals(size, 0);
+        });
+    }
+
+    @Test
+    public void testIncomingMessageSizeForPartitionedTopic() throws Exception {
+        final String topicName = "persistent://my-property/my-ns/testIncomingMessageSizeForPartitionedTopic-" +
+                UUID.randomUUID().toString();
+        final String subName = "my-sub";
+
+        admin.topics().createPartitionedTopic(topicName, 3);

Review comment:
       It's the only difference between `testIncomingMessageSizeForPartitionedTopic` and `testIncomingMessageSizeForNonPartitionedTopic`, IMO it's better to use `DataProvider` to reduce repeated logic, see `NullValueTest` for example.




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

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