chia7712 commented on code in PR #23402:
URL: https://github.com/apache/kafka/pull/23402#discussion_r3962373860


##########
tools/src/main/java/org/apache/kafka/tools/EndToEndLatency.java:
##########
@@ -136,55 +136,48 @@ static void execute(String[] args) throws Exception {
             }
 
             printResults(numRecords, totalTime, latencies);
-            consumer.commitSync();
         }
     }
 
     // Visible for testing
     static void validate(KafkaConsumer<byte[], byte[]> consumer, byte[] 
sentRecordValue, ConsumerRecords<byte[], byte[]> records, byte[] sentRecordKey, 
Iterable<Header> sentHeaders) {
         if (records.isEmpty()) {
-            commitAndThrow(consumer, "poll() timed out before finding a result 
(timeout:[" + POLL_TIMEOUT_MS + "ms])");
+            throw new RuntimeException("poll() timed out before finding a 
result (timeout:[" + POLL_TIMEOUT_MS + "ms])");
         }
 
         ConsumerRecord<byte[], byte[]> record = records.iterator().next();
         String sent = new String(sentRecordValue, StandardCharsets.UTF_8);
         String read = new String(record.value(), StandardCharsets.UTF_8);
 
         if (!read.equals(sent)) {
-            commitAndThrow(consumer, "The message value read [" + read + "] 
did not match the message value sent [" + sent + "]");
+            throw new RuntimeException("The message value read [" + read + "] 
did not match the message value sent [" + sent + "]");
         }
 
         if (sentRecordKey != null) {
             if (record.key() == null) {
-                commitAndThrow(consumer, "Expected message key but received 
null");
+                throw new RuntimeException("Expected message key but received 
null");
             }
             String sentKey = new String(sentRecordKey, StandardCharsets.UTF_8);
             String readKey = new String(record.key(), StandardCharsets.UTF_8);
             if (!readKey.equals(sentKey)) {
-                commitAndThrow(consumer, "The message key read [" + readKey + 
"] did not match the message key sent [" + sentKey + "]");
+                throw new RuntimeException("The message key read [" + readKey 
+ "] did not match the message key sent [" + sentKey + "]");
             }
         } else if (record.key() != null) {
-            commitAndThrow(consumer, "Expected null message key but received 
[" + new String(record.key(), StandardCharsets.UTF_8) + "]");
+            throw new RuntimeException("Expected null message key but received 
[" + new String(record.key(), StandardCharsets.UTF_8) + "]");
         }
 
         validateHeaders(consumer, sentHeaders, record);
 
         //Check we only got the one message
         if (records.count() != 1) {
-            int count = records.count();
-            commitAndThrow(consumer, "Only one result was expected during this 
test. We found [" + count + "]");
+            throw new RuntimeException("Only one result was expected during 
this test. We found [" + records.count() + "]");
         }
     }
 
-    private static void commitAndThrow(KafkaConsumer<byte[], byte[]> consumer, 
String message) {
-        consumer.commitSync();
-        throw new RuntimeException(message);
-    }
-
     private static void validateHeaders(KafkaConsumer<byte[], byte[]> 
consumer, Iterable<Header> sentHeaders, ConsumerRecord<byte[], byte[]> record) {

Review Comment:
   The `consumer` is unused now, and I will open a follow-up PR to do some more 
cleanup :)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to