|
129 | 129 | import org.apache.kafka.server.authorizer.Action;
|
130 | 130 | import org.apache.kafka.server.authorizer.AuthorizationResult;
|
131 | 131 | import org.apache.kafka.server.authorizer.Authorizer;
|
| 132 | +import org.apache.kafka.server.common.ApiMessageAndVersion; |
132 | 133 | import org.apache.kafka.server.share.persister.DeleteShareGroupStateParameters;
|
133 | 134 | import org.apache.kafka.server.share.persister.InitializeShareGroupStateParameters;
|
134 | 135 | import org.apache.kafka.server.share.persister.PartitionIdData;
|
@@ -20744,7 +20745,7 @@ barTopicName, new TopicMetadata(barTopicId, barTopicName, 3)
|
20744 | 20745 | }
|
20745 | 20746 |
|
20746 | 20747 | @Test
|
20747 |
| - public void testShareGroupDeleteRequest() { |
| 20748 | + public void testShareGroupDeleteRequestNoDeletingTopics() { |
20748 | 20749 | MockPartitionAssignor assignor = new MockPartitionAssignor("range");
|
20749 | 20750 | assignor.prepareGroupAssignment(new GroupAssignment(Map.of()));
|
20750 | 20751 | GroupMetadataManagerTestContext context = new GroupMetadataManagerTestContext.Builder()
|
@@ -20807,6 +20808,74 @@ public void testShareGroupDeleteRequest() {
|
20807 | 20808 | assertRecordsEquals(expectedRecords, records);
|
20808 | 20809 | }
|
20809 | 20810 |
|
| 20811 | + @Test |
| 20812 | + public void testShareGroupDeleteRequestWithAlreadyDeletingTopics() { |
| 20813 | + MockPartitionAssignor assignor = new MockPartitionAssignor("range"); |
| 20814 | + assignor.prepareGroupAssignment(new GroupAssignment(Map.of())); |
| 20815 | + GroupMetadataManagerTestContext context = new GroupMetadataManagerTestContext.Builder() |
| 20816 | + .withConfig(GroupCoordinatorConfig.CONSUMER_GROUP_ASSIGNORS_CONFIG, List.of(assignor)) |
| 20817 | + .build(); |
| 20818 | + |
| 20819 | + Uuid t1Uuid = Uuid.randomUuid(); |
| 20820 | + Uuid t2Uuid = Uuid.randomUuid(); |
| 20821 | + Uuid t3Uuid = Uuid.randomUuid(); |
| 20822 | + String t1Name = "t1"; |
| 20823 | + String t2Name = "t2"; |
| 20824 | + String t3Name = "t3"; |
| 20825 | + |
| 20826 | + String groupId = "share-group"; |
| 20827 | + ShareGroup shareGroup = mock(ShareGroup.class); |
| 20828 | + when(shareGroup.groupId()).thenReturn(groupId); |
| 20829 | + when(shareGroup.isEmpty()).thenReturn(false); |
| 20830 | + |
| 20831 | + MetadataImage image = new MetadataImageBuilder() |
| 20832 | + .addTopic(t1Uuid, t1Name, 2) |
| 20833 | + .addTopic(t2Uuid, t2Name, 2) |
| 20834 | + .addTopic(t3Uuid, t3Name, 2) |
| 20835 | + .build(); |
| 20836 | + |
| 20837 | + MetadataDelta delta = new MetadataDelta(image); |
| 20838 | + context.groupMetadataManager.onNewMetadataImage(image, delta); |
| 20839 | + |
| 20840 | + context.replay(GroupCoordinatorRecordHelpers.newShareGroupEpochRecord(groupId, 0)); |
| 20841 | + |
| 20842 | + context.replay( |
| 20843 | + GroupCoordinatorRecordHelpers.newShareGroupStatePartitionMetadataRecord( |
| 20844 | + groupId, |
| 20845 | + Map.of(t1Uuid, Map.entry(t1Name, Set.of(0, 1))), |
| 20846 | + Map.of(t2Uuid, Map.entry(t2Name, Set.of(0, 1))), |
| 20847 | + Map.of(t3Uuid, t3Name) |
| 20848 | + ) |
| 20849 | + ); |
| 20850 | + |
| 20851 | + context.commit(); |
| 20852 | + |
| 20853 | + Map<Uuid, Set<Integer>> expectedTopicPartitionMap = Map.of( |
| 20854 | + t1Uuid, Set.of(0, 1), |
| 20855 | + t2Uuid, Set.of(0, 1), |
| 20856 | + t3Uuid, Set.of(0, 1) |
| 20857 | + ); |
| 20858 | + |
| 20859 | + List<CoordinatorRecord> expectedRecords = List.of( |
| 20860 | + newShareGroupStatePartitionMetadataRecord( |
| 20861 | + groupId, |
| 20862 | + Map.of(), |
| 20863 | + Map.of(), |
| 20864 | + Map.of(t1Uuid, t1Name, t2Uuid, t2Name, t3Uuid, t3Name) // Existing deleting topics should be included here. |
| 20865 | + ) |
| 20866 | + ); |
| 20867 | + |
| 20868 | + List<CoordinatorRecord> records = new ArrayList<>(); |
| 20869 | + Optional<DeleteShareGroupStateParameters> params = context.groupMetadataManager.shareGroupBuildPartitionDeleteRequest(groupId, records); |
| 20870 | + verifyShareGroupDeleteRequest( |
| 20871 | + params, |
| 20872 | + expectedTopicPartitionMap, |
| 20873 | + groupId, |
| 20874 | + true |
| 20875 | + ); |
| 20876 | + assertRecordsEquals(expectedRecords, records); |
| 20877 | + } |
| 20878 | + |
20810 | 20879 | @Test
|
20811 | 20880 | public void testSharePartitionsEligibleForOffsetDeletionSuccess() {
|
20812 | 20881 | MockPartitionAssignor assignor = new MockPartitionAssignor("range");
|
@@ -21351,6 +21420,69 @@ public void testShareGroupHeartbeatNoPersisterRequestWithInitializing() {
|
21351 | 21420 | );
|
21352 | 21421 | }
|
21353 | 21422 |
|
| 21423 | + @Test |
| 21424 | + public void testShareGroupInitializingClearsCommonDeleting() { |
| 21425 | + MockPartitionAssignor assignor = new MockPartitionAssignor("range"); |
| 21426 | + assignor.prepareGroupAssignment(new GroupAssignment(Map.of())); |
| 21427 | + GroupMetadataManagerTestContext context = new GroupMetadataManagerTestContext.Builder() |
| 21428 | + .withShareGroupAssignor(assignor) |
| 21429 | + .build(); |
| 21430 | + |
| 21431 | + Uuid t1Uuid = Uuid.randomUuid(); |
| 21432 | + String t1Name = "t1"; |
| 21433 | + MetadataImage image = new MetadataImageBuilder() |
| 21434 | + .addTopic(t1Uuid, t1Name, 2) |
| 21435 | + .build(); |
| 21436 | + |
| 21437 | + String groupId = "share-group"; |
| 21438 | + |
| 21439 | + context.groupMetadataManager.onNewMetadataImage(image, mock(MetadataDelta.class)); |
| 21440 | + context.groupMetadataManager.replay( |
| 21441 | + new ShareGroupMetadataKey() |
| 21442 | + .setGroupId(groupId), |
| 21443 | + new ShareGroupMetadataValue() |
| 21444 | + .setEpoch(0) |
| 21445 | + ); |
| 21446 | + |
| 21447 | + // Replay a deleting record. |
| 21448 | + context.groupMetadataManager.replay( |
| 21449 | + new ShareGroupStatePartitionMetadataKey() |
| 21450 | + .setGroupId(groupId), |
| 21451 | + new ShareGroupStatePartitionMetadataValue() |
| 21452 | + .setInitializingTopics(List.of()) |
| 21453 | + .setInitializedTopics(List.of()) |
| 21454 | + .setDeletingTopics(List.of( |
| 21455 | + new ShareGroupStatePartitionMetadataValue.TopicInfo() |
| 21456 | + .setTopicId(t1Uuid) |
| 21457 | + .setTopicName(t1Name) |
| 21458 | + )) |
| 21459 | + ); |
| 21460 | + |
| 21461 | + List<CoordinatorRecord> records = new ArrayList<>(); |
| 21462 | + context.groupMetadataManager.addInitializingTopicsRecords(groupId, records, Map.of(t1Uuid, Set.of(0, 1))); |
| 21463 | + |
| 21464 | + List<CoordinatorRecord> expectedRecords = List.of( |
| 21465 | + CoordinatorRecord.record( |
| 21466 | + new ShareGroupStatePartitionMetadataKey() |
| 21467 | + .setGroupId(groupId), |
| 21468 | + new ApiMessageAndVersion( |
| 21469 | + new ShareGroupStatePartitionMetadataValue() |
| 21470 | + .setInitializingTopics(List.of( |
| 21471 | + new ShareGroupStatePartitionMetadataValue.TopicPartitionsInfo() |
| 21472 | + .setTopicId(t1Uuid) |
| 21473 | + .setTopicName(t1Name) |
| 21474 | + .setPartitions(List.of(0, 1)) |
| 21475 | + )) |
| 21476 | + .setInitializedTopics(List.of()) |
| 21477 | + .setDeletingTopics(List.of()), |
| 21478 | + (short) 0 |
| 21479 | + ) |
| 21480 | + ) |
| 21481 | + ); |
| 21482 | + |
| 21483 | + assertEquals(expectedRecords, records); |
| 21484 | + } |
| 21485 | + |
21354 | 21486 | @Test
|
21355 | 21487 | public void testShareGroupInitializeSuccess() {
|
21356 | 21488 | String groupId = "groupId";
|
|
0 commit comments