cadonna commented on code in PR #12387: URL: https://github.com/apache/kafka/pull/12387#discussion_r924276012
########## 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 was rather thinking about verifying that removed tasks, failed tasks, and restored tasks cannot be resumed. That means without pausing them beforehand. You just ensure that a task failed and then you try to resume it. The same applies to restored and removed tasks. -- 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