[ 
https://issues.apache.org/jira/browse/KAFKA-7616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16683060#comment-16683060
 ] 

ASF GitHub Bot commented on KAFKA-7616:
---------------------------------------

srdo opened a new pull request #5901: KAFKA-7616: Make MockConsumer only add 
entries to the partition map r…
URL: https://github.com/apache/kafka/pull/5901
 
 
   …eturned by poll() if there are any records to return
   
   The MockConsumer behaves unlike the real consumer in that it can return a 
non-empty ConsumerRecords from poll, that also has a count of 0. This change 
makes the MockConsumer only add partitions to the ConsumerRecords if there are 
records to return for those partitions.
   
   A unit test in MockConsumerTest demonstrates the issue.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> MockConsumer can return ConsumerRecords objects with a non-empty map but no 
> records
> -----------------------------------------------------------------------------------
>
>                 Key: KAFKA-7616
>                 URL: https://issues.apache.org/jira/browse/KAFKA-7616
>             Project: Kafka
>          Issue Type: Bug
>          Components: clients
>    Affects Versions: 2.0.1
>            Reporter: Stig Rohde Døssing
>            Assignee: Stig Rohde Døssing
>            Priority: Trivial
>
> The ConsumerRecords returned from MockConsumer.poll can return false for 
> isEmpty while not containing any records. This behavior is because 
> MockConsumer.poll eagerly adds entries to the returned Map<TopicPartition, 
> List<ConsumerRecord>>, based on which partitions have been added. If no 
> records are returned for a partition, e.g. because the position was too far 
> ahead, the entry for that partition will still be there.
>  
> The MockConsumer should lazily add entries to the map as they are needed, 
> since it is more in line with how the real consumer behaves.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to