Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
KAFKA-10789: Streamlining Tests in ChangeLoggingKeyValueBytesStoreTest #18816
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
base: trunk
Are you sure you want to change the base?
KAFKA-10789: Streamlining Tests in ChangeLoggingKeyValueBytesStoreTest #18816
Changes from all commits
181091c
6265440
f128915
d493559
05cc362
84c49c0
d205133
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why are we using
mockMap
? It seems unnecessarily complex? -- It seems much more straightforward to just "expect" calls into theinnerMock
store?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 pointing that out!
We're using mockMap here to simulate the internal state of the underlying store, since the tests in CachingInMemoryKeyValueStoreTest are being streamlined to rely on a mocked underlyingStore as per the KIP-614 review discussion.
Because innerMock is a mock and doesn’t retain state on its own, we use mockMap to mimic how the real store would behave across multiple interactions — especially for verifying behavior like reads after writes. This lets us preserve the semantics of the store while still keeping the actual store mocked, as requested.
That said, I'm open to simplifying it further if there's a cleaner way to preserve the same test coverage and behavior expectations.
https://issues.apache.org/jira/browse/KAFKA-10789
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, we want to mock, but we use two different techniques and mix them...
First you use
For this case, to me, all call a test make into this mock, should be stubbed via corresponding
when(...).thanAnswer(...)
code setup and the mock itself is stateless.If we make the mock stateful, we can just keep using
new InMemoryKeyValueStore
to begin with, that is just anMap<Bytes, bytes[]>
internally, too.\cc @cadonna who requested to rewrite this using mocks to clarify, in cases I misunderstand the purpose of the ticket.
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.
Why do we use
doAnswer(...).when(...)
here?In
mockGet
we usewhen(...).thanAnswer(...)
what I find much easier to read.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 question!
We use doAnswer(...).when(...) here because put is a void method. Mockito requires this syntax for mocking void methods — when(...).thenAnswer(...) only works for methods that return a value.
In contrast, get returns a value, so we can use when(...).thenAnswer(...) there, which I agree is a bit more readable.
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.
Ah. My bad. Thanks.
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.
Seems you forgot the add empty lines between methods. More of the same below.