You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/05/12 20:51:41 UTC

[GitHub] [pinot] xiangfu0 commented on a diff in pull request #8691: Fix PulsarConsumerTest

xiangfu0 commented on code in PR #8691:
URL: https://github.com/apache/pinot/pull/8691#discussion_r871799307


##########
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/test/java/org/apache/pinot/plugin/stream/pulsar/PulsarConsumerTest.java:
##########
@@ -164,52 +165,70 @@ public void publishRecords()
       throws Exception {
     for (int p = 0; p < NUM_PARTITION; p++) {
       final int partition = p;
-      Producer<String> producer =
-          _pulsarClient.newProducer(Schema.STRING).topic(TEST_TOPIC).messageRouter(new MessageRouter() {
+      try (Producer<String> producer = _pulsarClient.newProducer(Schema.STRING).topic(TEST_TOPIC)
+          .messageRouter(new MessageRouter() {
             @Override
             public int choosePartition(Message<?> msg, TopicMetadata metadata) {
               return partition;
             }
-          }).create();
-
-      for (int i = 0; i < NUM_RECORDS_PER_PARTITION; i++) {
-        MessageId messageId = producer.send(MESSAGE_PREFIX + "_" + i);
-        if (!_partitionToFirstMessageIdMap.containsKey(partition)) {
-          _partitionToFirstMessageIdMap.put(partition, messageId);
+          }).create()) {
+        for (int i = 0; i < NUM_RECORDS_PER_PARTITION; i++) {
+          MessageId messageId = producer.send(MESSAGE_PREFIX + "_" + i);
+          if (!_partitionToFirstMessageIdMap.containsKey(partition)) {
+            _partitionToFirstMessageIdMap.put(partition, messageId);
+          }
         }
+        producer.flush();
       }
-
-      producer.flush();
     }
   }
 
   public void publishRecordsBatch()
       throws Exception {
     for (int p = 0; p < NUM_PARTITION; p++) {
       final int partition = p;
-      Producer<String> producer =
+      try (Producer<String> producer =
           _pulsarClient.newProducer(Schema.STRING).topic(TEST_TOPIC_BATCH).messageRouter(new MessageRouter() {
             @Override
             public int choosePartition(Message<?> msg, TopicMetadata metadata) {
               return partition;
             }
-          }).batchingMaxMessages(BATCH_SIZE).batchingMaxPublishDelay(1, TimeUnit.SECONDS).create();
-
-      for (int i = 0; i < NUM_RECORDS_PER_PARTITION; i++) {
-        CompletableFuture<MessageId> messageIdCompletableFuture = producer.sendAsync(MESSAGE_PREFIX + "_" + i);
-        messageIdCompletableFuture.thenAccept(messageId -> {
-
-          List<BatchMessageIdImpl> batchMessageIdList = _partitionToMessageIdMapping
-              .getOrDefault(partition, new ArrayList<>());
-          batchMessageIdList.add((BatchMessageIdImpl) messageId);
-          _partitionToMessageIdMapping.put(partition, batchMessageIdList);
-
-          if (!_partitionToFirstMessageIdMapBatch.containsKey(partition)) {
-            _partitionToFirstMessageIdMapBatch.put(partition, messageId);
-          }
-        });
+          }).batchingMaxMessages(BATCH_SIZE).batchingMaxPublishDelay(1, TimeUnit.SECONDS).create()) {
+        for (int i = 0; i < NUM_RECORDS_PER_PARTITION; i++) {
+          CompletableFuture<MessageId> messageIdCompletableFuture = producer.sendAsync(MESSAGE_PREFIX + "_" + i);
+          messageIdCompletableFuture.thenAccept(messageId -> {
+
+            List<BatchMessageIdImpl> batchMessageIdList = _partitionToMessageIdMapping
+                .getOrDefault(partition, new ArrayList<>());
+            batchMessageIdList.add((BatchMessageIdImpl) messageId);
+            _partitionToMessageIdMapping.put(partition, batchMessageIdList);
+
+            if (!_partitionToFirstMessageIdMapBatch.containsKey(partition)) {
+              _partitionToFirstMessageIdMapBatch.put(partition, messageId);
+            }
+          });
+        }
+        producer.flush();
       }
-      producer.flush();
+      waitForCondition(input -> validatePartitionMessageCount(partition, NUM_RECORDS_PER_PARTITION), 5 * 1000L,

Review Comment:
   just a different way to try :p 



-- 
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@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org