frankvicky commented on code in PR #17150:
URL: https://github.com/apache/kafka/pull/17150#discussion_r1765190740


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/events/ApplicationEventProcessorTest.java:
##########
@@ -208,6 +206,110 @@ public void testSeekUnvalidatedEventWithException() {
         assertInstanceOf(IllegalStateException.class, e.getCause());
     }
 
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    public void testSyncCommitEventWithOffsets(boolean withGroupId) {
+        final long deadlineMs = 12345;
+        TopicPartition tp = new TopicPartition("topic", 0);
+        Map<TopicPartition, OffsetAndMetadata> offsets = 
Collections.singletonMap(tp, new OffsetAndMetadata(10, Optional.of(1), null));
+        SyncCommitEvent event = new SyncCommitEvent(offsets, false, 
deadlineMs);
+
+        setupProcessor(withGroupId);
+        if (withGroupId) {
+            doReturn(true).when(metadata).updateLastSeenEpochIfNewer(tp, 1);
+            
doReturn(CompletableFuture.completedFuture(null)).when(commitRequestManager).commitSync(offsets,
 deadlineMs);
+        }
+
+        processor.process(event);
+        verify(subscriptionState, never()).allConsumed();
+        if (withGroupId) {
+            verify(metadata).updateLastSeenEpochIfNewer(tp, 1);
+            verify(commitRequestManager).commitSync(offsets, deadlineMs);
+        } else {
+            verify(metadata, never()).updateLastSeenEpochIfNewer(tp, 1);
+            verify(commitRequestManager, never()).commitSync(offsets, 
deadlineMs);
+        }
+        assertDoesNotThrow(() -> event.future().get());
+    }
+
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    public void testSyncCommitEventWithCommitAllConsumed(boolean withGroupId) {
+        final long deadlineMs = 12345;
+        TopicPartition tp = new TopicPartition("topic", 0);
+        Map<TopicPartition, OffsetAndMetadata> offsets = 
Collections.singletonMap(tp, new OffsetAndMetadata(10, Optional.of(1), null));
+        SyncCommitEvent event = new SyncCommitEvent(Collections.emptyMap(), 
true, deadlineMs);
+
+        setupProcessor(withGroupId);
+        if (withGroupId) {
+            doReturn(offsets).when(subscriptionState).allConsumed();
+            doReturn(true).when(metadata).updateLastSeenEpochIfNewer(tp, 1);
+            
doReturn(CompletableFuture.completedFuture(null)).when(commitRequestManager).commitSync(offsets,
 deadlineMs);
+        }
+
+        processor.process(event);
+        if (withGroupId) {
+            verify(subscriptionState).allConsumed();
+            verify(metadata).updateLastSeenEpochIfNewer(tp, 1);
+            verify(commitRequestManager).commitSync(offsets, deadlineMs);
+        } else {
+            verify(metadata, never()).updateLastSeenEpochIfNewer(tp, 1);
+            verify(commitRequestManager, never()).commitSync(offsets, 
deadlineMs);

Review Comment:
   nit: I noticed that the handling logic when groupId is absent is almost 
identical across multiple tests. Maybe you could extract a helper method like 
`verifyNoInteractions(metadata, commitRequestManager, isSynced)`. WYDT ?



-- 
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