david-parkk opened a new pull request, #22651:
URL: https://github.com/apache/kafka/pull/22651

   ## Summary
   `KafkaConsumerTest.fetchResponseWithUnexpectedPartitionIsIgnored` was 
annotated with `@EnumSource(GroupProtocol.class)`, but the CONSUMER protocol 
case passed for the wrong reason.                                               
                                                                                
                                                 
   
   The CONSUMER protocol uses `FetchRequestManager` and relies on 
`ConsumerGroupHeartbeat` for rebalancing. Since the test does not set up 
heartbeat-based rebalancing, partition assignment never completes and 0 records 
are returned — not because `FetchSessionHandler` correctly rejected the 
response.
   
   ## Analysis
   While writing the CONSUMER protocol test, we first attempted to use 
`AsyncKafkaConsumerTest` as a reference. However, it was not suitable because 
`fetchCollector` is replaced with a Mock, meaning `FetchSessionHandler`'s 
actual rejection logic is never exercised.
   
   We also found that naively adding the CONSUMER case to `KafkaConsumerTest` 
does not work either. The test uses `prepareResponse()` for the Join and Sync 
group requests, but these responses were never consumed — because the CONSUMER 
protocol does not go through the classic Join/Sync rebalance flow. As a result, 
the fetch phase was never reached. `FetchRequestManagerTest` is the correct 
location for this test, as it directly runs `FetchSessionHandler` without 
mocking.
   
   ## Changes
   - **`KafkaConsumerTest`**: Restrict 
`fetchResponseWithUnexpectedPartitionIsIgnored` to `CLASSIC` protocol only, 
where the existing setup correctly exercises `FetchSessionHandler`'s unexpected 
partition rejection logic.                                                      
                                                                                
                     
   - **`FetchRequestManagerTest`**: Add 
`testFetchResponseWithUnexpectedPartitionIsIgnored` to properly cover the 
CONSUMER protocol path. The test verifies that when a `FetchResponse` contains 
a partition not included in the `FetchRequest`, `FetchSessionHandler` rejects 
the entire response and no records are returned to the consumer.
   
   ---
   I'm happy to make any adjustments based on your feedback. Thank you to the 
maintainers for taking the time to review this contribution!


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