guozhangwang commented on code in PR #12387: URL: https://github.com/apache/kafka/pull/12387#discussion_r923961624
########## streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStateUpdaterTest.java: ########## @@ -428,6 +456,113 @@ private void shouldRemoveStatefulTask(final Task task) throws Exception { verify(changelogReader).unregister(task.changelogPartitions()); } + @Test + public void shouldPauseActiveStatefulTask() throws Exception { + final StreamTask task = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + shouldPauseStatefulTask(task); + verify(changelogReader, never()).transitToUpdateStandby(); + } + + @Test + public void shouldPauseStandbyTask() throws Exception { + final StandbyTask task = createStandbyTaskInStateRunning(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + shouldPauseStatefulTask(task); + verify(changelogReader, times(1)).transitToUpdateStandby(); + } + + @Test + public void shouldPauseActiveTaskAndTransitToUpdateStandby() throws Exception { + final StreamTask task1 = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + final StandbyTask task2 = createStandbyTaskInStateRunning(TASK_0_1, Collections.singletonList(TOPIC_PARTITION_B_0)); + + stateUpdater.start(); + stateUpdater.add(task1); + stateUpdater.add(task2); + + stateUpdater.pause(task1.id()); + + verifyPausedTasks(task1); + verifyCheckpointTasks(true, task1); + verifyRestoredActiveTasks(); + verifyRemovedTasks(); + verifyUpdatingTasks(task2); + verifyExceptionsAndFailedTasks(); + verify(changelogReader, times(1)).enforceRestoreActive(); + verify(changelogReader, times(1)).transitToUpdateStandby(); + } + + private void shouldPauseStatefulTask(final Task task) throws Exception { + stateUpdater.start(); + stateUpdater.add(task); + + stateUpdater.pause(task.id()); + + verifyPausedTasks(task); + verifyCheckpointTasks(true, task); + verifyRestoredActiveTasks(); + verifyRemovedTasks(); + verifyUpdatingTasks(); + verifyExceptionsAndFailedTasks(); + } + + @Test + public void shouldResumeActiveStatefulTask() throws Exception { + final StreamTask task = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + shouldResumeStatefulTask(task); + verify(changelogReader, times(2)).enforceRestoreActive(); + } + + @Test + public void shouldResumeStandbyTask() throws Exception { + final StandbyTask task = createStandbyTaskInStateRunning(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + shouldResumeStatefulTask(task); + verify(changelogReader, times(2)).transitToUpdateStandby(); + } + + private void shouldResumeStatefulTask(final Task task) throws Exception { + stateUpdater.start(); + stateUpdater.add(task); + + stateUpdater.pause(task.id()); + + verifyPausedTasks(task); + verifyUpdatingTasks(); + + stateUpdater.resume(task.id()); + + verifyPausedTasks(); + verifyUpdatingTasks(task); + } + + @Test + public void shouldRemovePausedTask() throws Exception { + final StreamTask task = createActiveStatefulTaskInStateRestoring(TASK_0_0, Collections.singletonList(TOPIC_PARTITION_A_0)); + stateUpdater.start(); + stateUpdater.add(task); + + stateUpdater.pause(task.id()); + + verifyPausedTasks(task); + verifyCheckpointTasks(true, task); + verifyRestoredActiveTasks(); + verifyRemovedTasks(); + verifyUpdatingTasks(); + + stateUpdater.remove(task.id()); + + verifyPausedTasks(); + verifyRemovedTasks(task); + verifyRestoredActiveTasks(); + verifyUpdatingTasks(); + + stateUpdater.resume(task.id()); + + verifyPausedTasks(); + verifyRemovedTasks(task); + verifyRestoredActiveTasks(); + verifyUpdatingTasks(); + } Review Comment: I added the other tests but when trying to cover `shouldNotResumeActiveStatefulTaskInFailedTasks` and `shouldNotResumeStandbyTaskInFailedTasks` I realize they should not happen: this is because we should never fail an non-updating (i.e. paused) task, and in fact we have a check in our code when `handleStreamsExceptionWithTask`, so I removed these tests. -- 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