@@ -498,3 +498,43 @@ def test__parse_fetched_data__out_of_range(fetcher, topic, mocker):
498498 partition_record = fetcher ._parse_fetched_data (completed_fetch )
499499 assert partition_record is None
500500 assert fetcher ._subscriptions .assignment [tp ].awaiting_reset is True
501+
502+
503+ def test_partition_records_offset ():
504+ """Test that compressed messagesets are handle correctly
505+ when fetch offset is in the middle of the message list
506+ """
507+ batch_start = 120
508+ batch_end = 130
509+ fetch_offset = 123
510+ tp = TopicPartition ('foo' , 0 )
511+ messages = [ConsumerRecord (tp .topic , tp .partition , i ,
512+ None , None , 'key' , 'value' , 'checksum' , 0 , 0 )
513+ for i in range (batch_start , batch_end )]
514+ records = Fetcher .PartitionRecords (fetch_offset , None , messages )
515+ assert len (records ) > 0
516+ msgs = records .take (1 )
517+ assert msgs [0 ].offset == 123
518+ assert records .fetch_offset == 124
519+ msgs = records .take (2 )
520+ assert len (msgs ) == 2
521+ assert len (records ) > 0
522+ records .discard ()
523+ assert len (records ) == 0
524+
525+
526+ def test_partition_records_empty ():
527+ records = Fetcher .PartitionRecords (0 , None , [])
528+ assert len (records ) == 0
529+
530+
531+ def test_partition_records_no_fetch_offset ():
532+ batch_start = 0
533+ batch_end = 100
534+ fetch_offset = 123
535+ tp = TopicPartition ('foo' , 0 )
536+ messages = [ConsumerRecord (tp .topic , tp .partition , i ,
537+ None , None , 'key' , 'value' , 'checksum' , 0 , 0 )
538+ for i in range (batch_start , batch_end )]
539+ records = Fetcher .PartitionRecords (fetch_offset , None , messages )
540+ assert len (records ) == 0
0 commit comments