lucasbru commented on code in PR #13957: URL: https://github.com/apache/kafka/pull/13957#discussion_r1258012780
########## streams/src/test/java/org/apache/kafka/streams/processor/internals/tasks/DefaultTaskManagerTest.java: ########## @@ -166,6 +168,44 @@ public void shouldNotAssignAnyLockedTask() { assertNull(taskManager.assignNextTask(taskExecutor)); } + @Test + public void shouldNotSetUncaughtExceptionsForUnassignedTasks() { + taskManager.add(Collections.singleton(task)); + + assertThrows(IllegalArgumentException.class, () -> taskManager.setUncaughtException(exception, task.id())); Review Comment: Done ########## streams/src/test/java/org/apache/kafka/streams/processor/internals/tasks/DefaultTaskManagerTest.java: ########## @@ -166,6 +168,44 @@ public void shouldNotAssignAnyLockedTask() { assertNull(taskManager.assignNextTask(taskExecutor)); } + @Test + public void shouldNotSetUncaughtExceptionsForUnassignedTasks() { + taskManager.add(Collections.singleton(task)); + + assertThrows(IllegalArgumentException.class, () -> taskManager.setUncaughtException(exception, task.id())); + } + + @Test + public void shouldNotSetUncaughtExceptionsTwice() { + taskManager.add(Collections.singleton(task)); + when(tasks.activeTasks()).thenReturn(Collections.singleton(task)); + taskManager.assignNextTask(taskExecutor); + taskManager.setUncaughtException(exception, task.id()); + + assertThrows(IllegalArgumentException.class, () -> taskManager.setUncaughtException(exception, task.id())); Review Comment: Done ########## streams/src/main/java/org/apache/kafka/streams/processor/internals/tasks/DefaultTaskManager.java: ########## @@ -225,6 +227,37 @@ public Set<ReadOnlyTask> getTasks() { return returnWithTasksLocked(() -> tasks.activeTasks().stream().map(ReadOnlyTask::new).collect(Collectors.toSet())); } + @Override + public void setUncaughtException(final StreamsException exception, final TaskId taskId) { + executeWithTasksLocked(() -> { + + if (!assignedTasks.containsKey(taskId)) { + throw new IllegalArgumentException("An uncaught exception can only be set as long as the task is still assigned"); + } + + if (uncaughtExceptions.containsKey(taskId)) { + throw new IllegalArgumentException("The uncaught exception must be cleared before restarting processing"); + } + + uncaughtExceptions.put(taskId, exception); + }); + + log.info("Set an uncaught exception for task {}", taskId); Review Comment: Done -- 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