@@ -289,10 +289,13 @@ func TestGetLags(t *testing.T) {
289
289
require .NoError (t , err )
290
290
require .Equal (t , 2 , len (lags ))
291
291
292
+ // We create topic with 2 partitions and send 10 messages. first, last offset for all partitions is 0
293
+ // When we consume 4 messages, 5 is the latest/last/newest offset
294
+ // We consume 2 messages for each partition. Hence member_offset(2) <= last_offset(5)
292
295
for l , lag := range lags {
293
296
assert .Equal (t , l , lag .Partition )
294
- assert .Equal (t , int64 (4 ), lag .NewestOffset )
295
- assert .LessOrEqual (t , lag .MemberOffset , int64 (4 ))
297
+ assert .Equal (t , int64 (5 ), lag .NewestOffset )
298
+ assert .LessOrEqual (t , lag .MemberOffset , int64 (5 ))
296
299
}
297
300
}
298
301
@@ -330,10 +333,12 @@ func TestGetEarliestOrLatestOffset(t *testing.T) {
330
333
331
334
groupPartitions := groupDetails .Members [0 ].TopicPartitions [topicName ]
332
335
336
+ // A topic with 2 partitions and produced 10 messages. first/earliest offset = 0, last/lastest offset = 5
337
+ // Consume 8 messages. first/earliest offset = 0, member offset = 4, last/lastest offset = 5
333
338
for _ , partition := range groupPartitions {
334
339
offset , err := GetEarliestOrLatestOffset (ctx , connector , topicName , LatestResetOffsetsStrategy , partition )
335
340
require .NoError (t , err )
336
- assert .Equal (t , int64 (4 ), offset )
341
+ assert .Equal (t , int64 (5 ), offset )
337
342
338
343
offset , err = GetEarliestOrLatestOffset (ctx , connector , topicName , EarliestResetOffsetsStrategy , partition )
339
344
require .NoError (t , err )
@@ -390,10 +395,10 @@ func TestResetOffsets(t *testing.T) {
390
395
assert .Equal (t , int64 (2 ), lags [0 ].MemberOffset )
391
396
assert .Equal (t , int64 (1 ), lags [1 ].MemberOffset )
392
397
393
- // latest offset of partition 0
398
+ // latest offset of partition 0 -> This should be 5. first offset = 0, last offset = 5 (total 10 messages)
394
399
latestOffset , err := GetEarliestOrLatestOffset (ctx , connector , topicName , LatestResetOffsetsStrategy , 0 )
395
400
require .NoError (t , err )
396
- // earliest offset of partition 1
401
+ // earliest offset of partition 1 -> This should be 0. first offset = 0, last offset = 5 (total 10 messages)
397
402
earliestOffset , err := GetEarliestOrLatestOffset (ctx , connector , topicName , EarliestResetOffsetsStrategy , 1 )
398
403
require .NoError (t , err )
399
404
@@ -413,7 +418,10 @@ func TestResetOffsets(t *testing.T) {
413
418
require .NoError (t , err )
414
419
415
420
require .Equal (t , 2 , len (lags ))
416
- assert .Equal (t , int64 (4 ), lags [0 ].MemberOffset )
421
+ // partiton 0, we reset offset to latestoffset which is 5
422
+ assert .Equal (t , int64 (5 ), lags [0 ].MemberOffset )
423
+
424
+ // partiton 1, we reset offset to earliestoffset which is 0
417
425
assert .Equal (t , int64 (0 ), lags [1 ].MemberOffset )
418
426
419
427
}
0 commit comments