lianetm commented on code in PR #15877:
URL: https://github.com/apache/kafka/pull/15877#discussion_r1598491917


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -2288,23 +2253,15 @@ public void testRebalanceException(GroupProtocol 
groupProtocol) {
         client.prepareResponseFrom(syncGroupResponse(singletonList(tp0), 
Errors.NONE), coordinator);
 
         // assign throws
-        try {
-            
consumer.updateAssignmentMetadataIfNeeded(time.timer(Long.MAX_VALUE));
-            fail("Should throw exception");
-        } catch (Throwable e) {
-            assertEquals(partitionAssigned + singleTopicPartition, 
e.getCause().getMessage());
-        }
+        Throwable t = assertThrows(Throwable.class, () -> 
consumer.updateAssignmentMetadataIfNeeded(time.timer(Long.MAX_VALUE)));
+        assertEquals(partitionAssigned + singleTopicPartition, 
t.getCause().getMessage());
 
         // the assignment is still updated regardless of the exception
         assertEquals(singleton(tp0), subscription.assignedPartitions());
 
         // close's revoke throws
-        try {
-            consumer.close(Duration.ofMillis(0));
-            fail("Should throw exception");
-        } catch (Throwable e) {
-            assertEquals(partitionRevoked + singleTopicPartition, 
e.getCause().getCause().getMessage());
-        }
+        t = assertThrows(Throwable.class, () -> 
consumer.close(Duration.ofMillis(0)));

Review Comment:
   Not introduced by this PR, but here we could be more specific and 
`assertThrows(KafkaException.class, ...)`. Regardless of the type of exception 
thrown in the rebalance callbacks, a `KafkaException` is what's always 
propagated (legacy and new consumer).
   
   Btw, reviewing this PR I noticed that this KafkaConsumerTest has lots of 
tests not enabled for the new consumer (with lots of TODOs about it). I created 
[KAFKA-16737](https://issues.apache.org/jira/browse/KAFKA-16737) to make sure 
we address it, enable the tests that apply and clean up the code. 



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