richardstartin commented on code in PR #8691: URL: https://github.com/apache/pinot/pull/8691#discussion_r871794782
########## 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: waiting 5 seconds at a time feels excessive -- 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-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org