-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19683: Some more test replacements [7/N] #20889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@lucasbru, tagging for review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request continues a series of test refactorings in TaskManagerTest.java, replacing tests that use StateMachineTask with tests that use mocked StreamTask instances created via the statefulTask builder pattern. This modernizes the testing approach to use better test utilities and mocking frameworks.
Key Changes:
- Consolidated two separate tests (
shouldComputeOffsetSumFromCheckpointFileForUninitializedTaskandshouldComputeOffsetSumFromCheckpointFileForClosedTask) into a single parameterized test - Replaced multiple tests that used
StateMachineTaskwith mockedStreamTaskinstances configured via builder pattern - Removed unused
assertNullimport
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| when(task01.process(anyLong())) | ||
| .thenThrow(timeoutException.get()) // throws TimeoutException | ||
| .thenReturn(true) | ||
| .thenReturn(true) | ||
| .thenReturn(false); |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock behavior is evaluated at setup time, so timeoutException.get() will always return the TimeoutException. Setting timeoutException.set(null) on line 4218 won't change the mock's behavior. The second call to taskManager.process(1, time) will still throw the TimeoutException instead of processing records.
Consider using thenThrow(...).thenReturn(true).thenReturn(true).thenReturn(false) without the AtomicReference, or reconfigure the mock after clearing the timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I don't think the atomic reference makes sense now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 931852e
| timeoutException.set(null); | ||
| assertThat(taskManager.process(1, time), is(3)); |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting timeoutException.set(null) doesn't update the mock's behavior. The mock's thenThrow() at line 4198 was configured at setup time with the exception object and will continue to throw it. The test expects the retry on line 4219 to succeed, but it will still encounter the TimeoutException.
The test needs to either reconfigure the mock after line 4218 or avoid using the AtomicReference approach entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - this is not working as you intended it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 931852e
lucasbru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Minor comments only
| when(task01.process(anyLong())) | ||
| .thenThrow(timeoutException.get()) // throws TimeoutException | ||
| .thenReturn(true) | ||
| .thenReturn(true) | ||
| .thenReturn(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I don't think the atomic reference makes sense now
| timeoutException.set(null); | ||
| assertThat(taskManager.process(1, time), is(3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - this is not working as you intended it
| mkEntry(new TopicPartition("changelog", 1), 10L) | ||
| ); | ||
| final Map<TaskId, Long> expectedOffsetSums = mkMap(mkEntry(taskId00, 15L)); | ||
| when(tasks.allTasksPerId()).thenReturn(mkMap(mkEntry(taskId00, task))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird that you add tasks to the stateUpdater first, and then mock it. I would reverse the order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! my bad, addressed in 931852e
62a0dc1 to
931852e
Compare
Rewrote more tests in
TaskManagerTest.javaReviewers: Lucas Brutschy [email protected]