mjsax commented on code in PR #19669:
URL: https://github.com/apache/kafka/pull/19669#discussion_r2083381315


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -2253,44 +2262,49 @@ public void testPollAuthenticationFailure(GroupProtocol 
groupProtocol) throws In
     @ParameterizedTest
     @EnumSource(value = GroupProtocol.class, names = "CLASSIC")
     public void testOffsetsForTimesAuthenticationFailure(GroupProtocol 
groupProtocol) {
-        final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol);
-        assertThrows(AuthenticationException.class, () -> 
consumer.offsetsForTimes(singletonMap(tp0, 0L)));
+        try (final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol)) {
+            assertThrows(AuthenticationException.class, () -> 
consumer.offsetsForTimes(singletonMap(tp0, 0L)));
+        }
     }
 
     // TODO: this test triggers a bug with the CONSUMER group protocol 
implementation.
     //       The bug will be investigated and fixed so this test can use both 
group protocols.
     @ParameterizedTest
     @EnumSource(value = GroupProtocol.class, names = "CLASSIC")
     public void testCommitSyncAuthenticationFailure(GroupProtocol 
groupProtocol) {
-        final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol);
-        Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
-        offsets.put(tp0, new OffsetAndMetadata(10L));
-        assertThrows(AuthenticationException.class, () -> 
consumer.commitSync(offsets));
+        try (final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol)) {
+            Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
+            offsets.put(tp0, new OffsetAndMetadata(10L));
+            assertThrows(AuthenticationException.class, () -> 
consumer.commitSync(offsets));
+        }
     }
 
     // TODO: this test triggers a bug with the CONSUMER group protocol 
implementation.
     //       The bug will be investigated and fixed so this test can use both 
group protocols.
     @ParameterizedTest
     @EnumSource(value = GroupProtocol.class, names = "CLASSIC")
     public void testCommittedAuthenticationFailure(GroupProtocol 
groupProtocol) {
-        final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol);
-        assertThrows(AuthenticationException.class, () -> 
consumer.committed(Collections.singleton(tp0)).get(tp0));
+        try (final KafkaConsumer<String, String> consumer = 
consumerWithPendingAuthenticationError(groupProtocol)) {
+            assertThrows(AuthenticationException.class, () -> 
consumer.committed(Collections.singleton(tp0)).get(tp0));
+        }
     }
 
     @ParameterizedTest
     @EnumSource(value = GroupProtocol.class)
     public void testMeasureCommitSyncDurationOnFailure(GroupProtocol 
groupProtocol) {
-        final KafkaConsumer<String, String> consumer
-            = consumerWithPendingError(groupProtocol, new 
MockTime(Duration.ofSeconds(1).toMillis()));
+        try (final KafkaConsumer<String, String> consumer
+            = consumerWithPendingError(groupProtocol, new 
MockTime(Duration.ofSeconds(1).toMillis()))) {
 
-        try {
-            consumer.commitSync(Collections.singletonMap(tp0, new 
OffsetAndMetadata(10L)));
-        } catch (final RuntimeException e) {
-        }
+            try {
+                consumer.commitSync(Collections.singletonMap(tp0, new 
OffsetAndMetadata(10L)));

Review Comment:
   Ack. Will apply throughout the whole class.



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to