guozhangwang commented on code in PR #12279: URL: https://github.com/apache/kafka/pull/12279#discussion_r902904075
########## streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java: ########## @@ -603,6 +637,67 @@ public void shouldDrainFailedTasksAndExceptions() throws Exception { verifyDrainingExceptionsAndFailedTasks(expectedExceptionAndTasks2, expectedExceptionAndTasks3, expectedExceptionAndTasks4); } + @Test + public void shouldAutoCommitTasksOnInterval() throws Exception { + final StreamTask task1 = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + final StreamTask task2 = createActiveStatefulTaskInStateRestoring(TASK_0_2, Collections.singletonList(TOPIC_PARTITION_B_0)); + final StandbyTask task3 = createStandbyTaskInStateRunning(TASK_1_0, Collections.singletonList(TOPIC_PARTITION_C_0)); + final StandbyTask task4 = createStandbyTaskInStateRunning(TASK_1_1, Collections.singletonList(TOPIC_PARTITION_D_0)); + when(changelogReader.completedChangelogs()) + .thenReturn(Collections.emptySet()); + when(changelogReader.allChangelogsCompleted()) + .thenReturn(false); + + stateUpdater.add(task1); + stateUpdater.add(task2); + stateUpdater.add(task3); + stateUpdater.add(task4); + + sleep(COMMIT_INTERVAL); + + verifyExceptionsAndFailedTasks(); + verifyCheckpointTasks(false, task1, task2, task3, task4); + } + + @Test + public void shouldNotAutoCommitTasksIfIntervalNotElapsed() throws Exception { + final StreamsConfig config = new StreamsConfig(configProps(Integer.MAX_VALUE)); + final DefaultStateUpdater stateUpdater = new DefaultStateUpdater(config, changelogReader, offsetResetter, Time.SYSTEM); Review Comment: Sounds good, I will remove `final` on that variable then. ########## streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java: ########## @@ -603,6 +637,67 @@ public void shouldDrainFailedTasksAndExceptions() throws Exception { verifyDrainingExceptionsAndFailedTasks(expectedExceptionAndTasks2, expectedExceptionAndTasks3, expectedExceptionAndTasks4); } + @Test + public void shouldAutoCommitTasksOnInterval() throws Exception { + final StreamTask task1 = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + final StreamTask task2 = createActiveStatefulTaskInStateRestoring(TASK_0_2, Collections.singletonList(TOPIC_PARTITION_B_0)); + final StandbyTask task3 = createStandbyTaskInStateRunning(TASK_1_0, Collections.singletonList(TOPIC_PARTITION_C_0)); + final StandbyTask task4 = createStandbyTaskInStateRunning(TASK_1_1, Collections.singletonList(TOPIC_PARTITION_D_0)); + when(changelogReader.completedChangelogs()) + .thenReturn(Collections.emptySet()); + when(changelogReader.allChangelogsCompleted()) + .thenReturn(false); + + stateUpdater.add(task1); + stateUpdater.add(task2); + stateUpdater.add(task3); + stateUpdater.add(task4); + + sleep(COMMIT_INTERVAL); + + verifyExceptionsAndFailedTasks(); + verifyCheckpointTasks(false, task1, task2, task3, task4); + } + + @Test + public void shouldNotAutoCommitTasksIfIntervalNotElapsed() throws Exception { + final StreamsConfig config = new StreamsConfig(configProps(Integer.MAX_VALUE)); + final DefaultStateUpdater stateUpdater = new DefaultStateUpdater(config, changelogReader, offsetResetter, Time.SYSTEM); + + try { + final StreamTask task1 = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + final StreamTask task2 = createActiveStatefulTaskInStateRestoring(TASK_0_2, Collections.singletonList(TOPIC_PARTITION_B_0)); + final StandbyTask task3 = createStandbyTaskInStateRunning(TASK_1_0, Collections.singletonList(TOPIC_PARTITION_C_0)); + final StandbyTask task4 = createStandbyTaskInStateRunning(TASK_1_1, Collections.singletonList(TOPIC_PARTITION_D_0)); + when(changelogReader.completedChangelogs()) + .thenReturn(Collections.emptySet()); + when(changelogReader.allChangelogsCompleted()) + .thenReturn(false); + + stateUpdater.add(task1); + stateUpdater.add(task2); + stateUpdater.add(task3); + stateUpdater.add(task4); + + verifyNeverCheckpointTasks(task1, task2, task3, task4); + } finally { + stateUpdater.shutdown(Duration.ofMinutes(1)); + } + } + + private void verifyCheckpointTasks(final boolean enforceCheckpoint, final Task... tasks) throws Exception { + for (final Task task : tasks) { + verify(task, timeout(VERIFICATION_TIMEOUT).atLeast(1)).maybeCheckpoint(enforceCheckpoint); Review Comment: Ack -- 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