jeffkbkim commented on code in PR #14467:
URL: https://github.com/apache/kafka/pull/14467#discussion_r1349341227


##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/OffsetMetadataManagerTest.java:
##########
@@ -1763,6 +1803,120 @@ public void testDeleteGroupAllOffsets(Group.GroupType 
groupType) {
         assertEquals(3, numDeleteOffsets);
     }
 
+    @Test
+    public void testIsExpiredOffset() {
+        long currentTimestamp = 1000L;
+        long baseTimestamp = 500L;
+        OptionalLong expireTimestampMs = OptionalLong.of(1500);
+        long offsetsRetentionMs = 500L;
+
+        // Current timestamp >= expire timestamp => should expire
+        assertFalse(OffsetMetadataManager.isExpiredOffset(currentTimestamp, 
baseTimestamp, expireTimestampMs, offsetsRetentionMs));
+
+        // Current timestamp < expire timestamp => should not expire
+        currentTimestamp = 499;
+        assertFalse(OffsetMetadataManager.isExpiredOffset(currentTimestamp, 
baseTimestamp, expireTimestampMs, offsetsRetentionMs));
+
+        // Expire timestamp does not exist (current version with no per 
partition retention)
+        // Current timestamp - base timestamp >= offsets retention => should 
expire
+        expireTimestampMs = OptionalLong.empty();
+        currentTimestamp = 1000L;
+        assertTrue(OffsetMetadataManager.isExpiredOffset(currentTimestamp, 
baseTimestamp, expireTimestampMs, offsetsRetentionMs));
+
+        // Current timestamp - base timestamp < offsets retention => should 
not expire
+        currentTimestamp = 999L;
+        assertFalse(OffsetMetadataManager.isExpiredOffset(currentTimestamp, 
baseTimestamp, expireTimestampMs, offsetsRetentionMs));
+    }
+
+    @Test
+    public void testCleanupExpiredOffsetsGroupDoesNotExist() {
+        OffsetMetadataManagerTestContext context = new 
OffsetMetadataManagerTestContext.Builder()
+            .build();
+
+        List<Record> records = new ArrayList<>();
+        assertTrue(context.cleanupExpiredOffsets("unknown-group-id", records));
+        assertEquals(Collections.emptyList(), records);
+    }
+
+    @Test
+    public void testCleanupExpiredOffsetsGroupEmptyOffsetExpirationCondition() 
{
+        GroupMetadataManager groupMetadataManager = 
mock(GroupMetadataManager.class);
+        Group group = mock(Group.class);
+
+        OffsetMetadataManagerTestContext context = new 
OffsetMetadataManagerTestContext.Builder()
+            .withGroupMetadataManager(groupMetadataManager)
+            .build();
+
+        context.commitOffset("group-id", "topic", 0, 100L, 0);
+
+        when(groupMetadataManager.group("group-id")).thenReturn(group);
+        when(group.offsetExpirationCondition()).thenReturn(Optional.empty());
+
+        List<Record> records = new ArrayList<>();
+        assertFalse(context.cleanupExpiredOffsets("group-id", records));
+        assertEquals(Collections.emptyList(), records);
+    }
+
+    @Test
+    public void testCleanupExpiredOffsets() {

Review Comment:
   that's correct, one topic partition that the group is still subcribed to, 
one that has expired, and one that has not yet expired.



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to