@@ -125,7 +125,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
125
125
}, msg = s " Could not get partitions assigned. Last response $shareGroupHeartbeatResponse. " )
126
126
127
127
// Verify the response.
128
- assertEquals(2 , shareGroupHeartbeatResponse.data.memberEpoch)
128
+ assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
129
129
assertEquals(expectedAssignment, shareGroupHeartbeatResponse.data.assignment)
130
130
131
131
// Leave the group.
@@ -232,14 +232,26 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
232
232
233
233
// Heartbeats until the partitions are assigned for member 1.
234
234
shareGroupHeartbeatResponse = null
235
+
235
236
TestUtils .waitUntilTrue(() => {
236
237
shareGroupHeartbeatResponse = connectAndReceive(shareGroupHeartbeatRequest)
237
- shareGroupHeartbeatResponse.data.errorCode == Errors .NONE .code && shareGroupHeartbeatResponse.data.assignment != null
238
+ if (shareGroupHeartbeatResponse.data.errorCode == Errors .NONE .code && shareGroupHeartbeatResponse.data().assignment() != null ) {
239
+ true
240
+ } else {
241
+ shareGroupHeartbeatRequest = new ShareGroupHeartbeatRequest .Builder (
242
+ new ShareGroupHeartbeatRequestData ()
243
+ .setGroupId(" grp" )
244
+ .setMemberId(memberId1)
245
+ .setMemberEpoch(shareGroupHeartbeatResponse.data.memberEpoch()),
246
+ true
247
+ ).build()
248
+ false
249
+ }
238
250
}, msg = s " Could not get partitions assigned. Last response $shareGroupHeartbeatResponse. " )
239
251
240
252
val topicPartitionsAssignedToMember1 = shareGroupHeartbeatResponse.data.assignment.topicPartitions()
241
253
// Verify the response.
242
- assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
254
+ assertEquals(4 , shareGroupHeartbeatResponse.data.memberEpoch)
243
255
244
256
// Prepare the next heartbeat for member 2.
245
257
shareGroupHeartbeatRequest = new ShareGroupHeartbeatRequest .Builder (
@@ -259,7 +271,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
259
271
260
272
val topicPartitionsAssignedToMember2 = shareGroupHeartbeatResponse.data.assignment.topicPartitions()
261
273
// Verify the response.
262
- assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
274
+ assertEquals(4 , shareGroupHeartbeatResponse.data.memberEpoch)
263
275
264
276
val partitionsAssigned : util.Set [Integer ] = new util.HashSet [Integer ]()
265
277
topicPartitionsAssignedToMember1.forEach(topicPartition => {
@@ -290,7 +302,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
290
302
}, msg = s " Could not get partitions assigned. Last response $shareGroupHeartbeatResponse. " )
291
303
292
304
// Verify the response.
293
- assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
305
+ assertEquals(4 , shareGroupHeartbeatResponse.data.memberEpoch)
294
306
} finally {
295
307
admin.close()
296
308
}
@@ -369,7 +381,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
369
381
}, msg = s " Could not get partitions assigned. Last response $shareGroupHeartbeatResponse. " )
370
382
371
383
// Verify the response.
372
- assertEquals(2 , shareGroupHeartbeatResponse.data.memberEpoch)
384
+ assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
373
385
374
386
// Member leaves the group.
375
387
shareGroupHeartbeatRequest = new ShareGroupHeartbeatRequest .Builder (
@@ -402,7 +414,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
402
414
shareGroupHeartbeatResponse = connectAndReceive(shareGroupHeartbeatRequest)
403
415
404
416
// Verify the response for member 1.
405
- assertEquals(4 , shareGroupHeartbeatResponse.data.memberEpoch)
417
+ assertEquals(5 , shareGroupHeartbeatResponse.data.memberEpoch)
406
418
assertEquals(memberId, shareGroupHeartbeatResponse.data.memberId)
407
419
// Partition assignment remains intact on rejoining.
408
420
assertEquals(expectedAssignment, shareGroupHeartbeatResponse.data.assignment)
@@ -491,7 +503,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
491
503
shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)
492
504
}, msg = s " Could not get partitions for topic foo and bar assigned. Last response $shareGroupHeartbeatResponse. " )
493
505
// Verify the response.
494
- assertEquals(2 , shareGroupHeartbeatResponse.data.memberEpoch)
506
+ assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
495
507
// Create the topic baz.
496
508
val bazTopicId = TestUtils .createTopicWithAdminRaw(
497
509
admin = admin,
@@ -515,7 +527,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
515
527
new ShareGroupHeartbeatRequestData ()
516
528
.setGroupId(" grp" )
517
529
.setMemberId(memberId)
518
- .setMemberEpoch(2 ),
530
+ .setMemberEpoch(3 ),
519
531
true
520
532
).build()
521
533
@@ -527,7 +539,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
527
539
shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)
528
540
}, msg = s " Could not get partitions for topic baz assigned. Last response $shareGroupHeartbeatResponse. " )
529
541
// Verify the response.
530
- assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
542
+ assertEquals(5 , shareGroupHeartbeatResponse.data.memberEpoch)
531
543
// Increasing the partitions of topic bar which is already being consumed in the share group.
532
544
increasePartitions(admin, " bar" , 6 , Seq .empty)
533
545
@@ -547,7 +559,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
547
559
new ShareGroupHeartbeatRequestData ()
548
560
.setGroupId(" grp" )
549
561
.setMemberId(memberId)
550
- .setMemberEpoch(3 ),
562
+ .setMemberEpoch(5 ),
551
563
true
552
564
).build()
553
565
@@ -559,7 +571,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
559
571
shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)
560
572
}, msg = s " Could not update partitions assignment for topic bar. Last response $shareGroupHeartbeatResponse. " )
561
573
// Verify the response.
562
- assertEquals(4 , shareGroupHeartbeatResponse.data.memberEpoch)
574
+ assertEquals(7 , shareGroupHeartbeatResponse.data.memberEpoch)
563
575
// Delete the topic foo.
564
576
TestUtils .deleteTopicWithAdmin(
565
577
admin = admin,
@@ -581,7 +593,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
581
593
new ShareGroupHeartbeatRequestData ()
582
594
.setGroupId(" grp" )
583
595
.setMemberId(memberId)
584
- .setMemberEpoch(4 ),
596
+ .setMemberEpoch(7 ),
585
597
true
586
598
).build()
587
599
@@ -593,7 +605,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
593
605
shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)
594
606
}, msg = s " Could not update partitions assignment for topic foo. Last response $shareGroupHeartbeatResponse. " )
595
607
// Verify the response.
596
- assertEquals(5 , shareGroupHeartbeatResponse.data.memberEpoch)
608
+ assertEquals(8 , shareGroupHeartbeatResponse.data.memberEpoch)
597
609
} finally {
598
610
admin.close()
599
611
}
@@ -704,12 +716,24 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
704
716
.setTopicId(barId)
705
717
.setPartitions(List [Integer ](0 ).asJava)).asJava)
706
718
719
+ shareGroupHeartbeatResponse = null
720
+
707
721
TestUtils .waitUntilTrue(() => {
708
722
shareGroupHeartbeatResponse = connectAndReceive(shareGroupHeartbeatRequest)
709
- shareGroupHeartbeatResponse.data.errorCode == Errors .NONE .code &&
710
- shareGroupHeartbeatResponse.data.assignment != null &&
723
+ if (shareGroupHeartbeatResponse.data.assignment != null &&
711
724
expectedAssignment.topicPartitions.containsAll(shareGroupHeartbeatResponse.data.assignment.topicPartitions) &&
712
- shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)
725
+ shareGroupHeartbeatResponse.data.assignment.topicPartitions.containsAll(expectedAssignment.topicPartitions)) {
726
+ true
727
+ } else {
728
+ shareGroupHeartbeatRequest = new ShareGroupHeartbeatRequest .Builder (
729
+ new ShareGroupHeartbeatRequestData ()
730
+ .setGroupId(" grp" )
731
+ .setMemberId(memberId)
732
+ .setMemberEpoch(shareGroupHeartbeatResponse.data.memberEpoch),
733
+ true
734
+ ).build()
735
+ false
736
+ }
713
737
}, msg = s " Could not get bar partitions assigned. Last response $shareGroupHeartbeatResponse. " )
714
738
715
739
// Verify the response, the epoch should have been bumped.
@@ -840,7 +864,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
840
864
shareGroupHeartbeatResponse.data.assignment == expectedAssignment
841
865
}, msg = s " Could not get partitions assigned. Last response $shareGroupHeartbeatResponse. " )
842
866
// Verify the response.
843
- assertEquals(2 , shareGroupHeartbeatResponse.data.memberEpoch)
867
+ assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
844
868
845
869
// Restart the only running broker.
846
870
val broker = cluster.brokers().values().iterator().next()
@@ -864,7 +888,7 @@ class ShareGroupHeartbeatRequestTest(cluster: ClusterInstance) {
864
888
865
889
// Verify the response. Epoch should not have changed and null assignments determines that no
866
890
// change in old assignment.
867
- assertEquals(2 , shareGroupHeartbeatResponse.data.memberEpoch)
891
+ assertEquals(3 , shareGroupHeartbeatResponse.data.memberEpoch)
868
892
assertNull(shareGroupHeartbeatResponse.data.assignment)
869
893
} finally {
870
894
admin.close()
0 commit comments