NicoleYWDu commented on code in PR #24071:
URL: https://github.com/apache/kafka/pull/24071#discussion_r4619719521


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorShardTest.java:
##########
@@ -2823,4 +2828,72 @@ public void testFetchOffsets(boolean fetchAllOffsets) {
 
         assertEquals(result, coordinator.fetchOffsets(request, 
Long.MAX_VALUE));
     }
+
+    @Test
+    public void testListGroupsWithRequireCommittedOffsets() {
+        GroupMetadataManager groupMetadataManager = 
mock(GroupMetadataManager.class);
+        OffsetMetadataManager offsetMetadataManager = 
mock(OffsetMetadataManager.class);
+        GroupCoordinatorShard coordinator = new GroupCoordinatorShard(
+            new LogContext(),
+            groupMetadataManager,
+            offsetMetadataManager,
+            Time.SYSTEM,
+            new MockCoordinatorTimer<>(Time.SYSTEM),
+            mock(GroupCoordinatorConfig.class),
+            mock(CoordinatorMetrics.class),
+            mock(CoordinatorMetricsShard.class)
+        );
+
+        @SuppressWarnings("unchecked")
+        ArgumentCaptor<Predicate<String>> groupIdFilterCaptor = 
ArgumentCaptor.forClass(Predicate.class);
+        List<ListGroupsResponseData.ListedGroup> groups = List.of(new 
ListGroupsResponseData.ListedGroup().setGroupId("with-offsets"));
+        when(groupMetadataManager.listGroups(eq(Set.of()), eq(Set.of()), 
groupIdFilterCaptor.capture(), eq(100L))).thenReturn(groups);
+
+        // Without the filter, every group matches and the offsets are not 
read.
+        assertEquals(groups, coordinator.listGroups(List.of(), List.of(), 
false, 100L));
+        assertTrue(groupIdFilterCaptor.getValue().test("with-offsets"));
+        assertTrue(groupIdFilterCaptor.getValue().test("without-offsets"));
+        verifyNoInteractions(offsetMetadataManager);
+
+        // With the filter, the offsets are read at the same committed offset 
as the groups.
+        when(offsetMetadataManager.hasCommittedOffsets("with-offsets", 
100L)).thenReturn(true);
+        when(offsetMetadataManager.hasCommittedOffsets("without-offsets", 
100L)).thenReturn(false);
+        assertEquals(groups, coordinator.listGroups(List.of(), List.of(), 
true, 100L));
+        assertTrue(groupIdFilterCaptor.getValue().test("with-offsets"));
+        assertFalse(groupIdFilterCaptor.getValue().test("without-offsets"));
+    }
+
+    @Test
+    public void 
testListGroupsWithRequireCommittedOffsetsAndStatesAndTypesFilters() {
+        OffsetMetadataManagerTest.OffsetMetadataManagerTestContext context =
+            new 
OffsetMetadataManagerTest.OffsetMetadataManagerTestContext.Builder().build();
+        GroupCoordinatorShard coordinator = new GroupCoordinatorShard(
+            new LogContext(),
+            context.groupMetadataManager,
+            context.offsetMetadataManager,
+            context.time,
+            context.timer,
+            mock(GroupCoordinatorConfig.class),
+            mock(CoordinatorMetrics.class),
+            mock(CoordinatorMetricsShard.class)
+        );
+
+        // All four groups are empty. Committing an offset to an unknown group 
creates a simple classic group.
+        context.commitOffset("classic-with-offsets", "foo", 0, 100L, 1);
+        context.getOrMaybeCreateGroup(Group.GroupType.CLASSIC, 
"classic-without-offsets");
+        context.getOrMaybeCreateGroup(Group.GroupType.CONSUMER, 
"consumer-with-offsets");
+        context.commitOffset("consumer-with-offsets", "foo", 0, 100L, 1);
+        context.getOrMaybeCreateGroup(Group.GroupType.CONSUMER, 
"consumer-without-offsets");
+
+        BiFunction<List<String>, List<String>, Set<String>> listGroupIds = 
(statesFilter, typesFilter) ->
+            coordinator.listGroups(statesFilter, typesFilter, true, 
Long.MAX_VALUE).stream()

Review Comment:
   Done in 21c5b67e34. The test now reads at `context.lastCommittedOffset` with 
an offset commit and an offset deletion that are not committed yet, and covers 
a streams group with an offset and a share group. A final `commit()` checks 
that the pending writes become visible.



##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/OffsetMetadataManagerTest.java:
##########
@@ -338,6 +338,13 @@ public boolean cleanupExpiredOffsets(String groupId, 
List<CoordinatorRecord> rec
             return isOffsetsEmptyForGroup;
         }
 
+        public boolean hasCommittedOffsets(String groupId) {
+            // The runtime keeps a snapshot at the last written offset; 
replay() in this
+            // context only snapshots the state before each record, so create 
it here.
+            snapshotRegistry.idempotentCreateSnapshot(lastWrittenOffset);

Review Comment:
   #24301 is merged. Rebased on trunk and removed the workaround in 21c5b67e34.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to