GH-4422: Add test coverage for null/empty override properties in DefaultKafkaConsumerFactory#4433
GH-4422: Add test coverage for null/empty override properties in DefaultKafkaConsumerFactory#4433Flicko75 wants to merge 2 commits into
Conversation
…perties in DefaultKafkaConsumerFactory Fixes spring-projectsGH-4422 (spring-projects#4422) * add test verifying null value in Properties overrides throws NullPointerException * add test verifying empty string value in Properties overrides is applied to consumer config Signed-off-by: Sayan Sarkar <sarkarsayan749@gmail.com>
|
Thanks for adding the tests! I noticed a couple of things:
Maybe we should:
Happy to help refine or extend the tests if needed. |
|
Thanks for the feedback! Regarding the null test, I initially tried testing that null values are ignored by the factory, but Could you clarify what specific scenario you had in mind for null values reaching the factory? |
|
Good point you're right that What I had in mind was more around defining expected behavior at the factory boundary, in case null values are introduced indirectly (e.g., via custom map manipulation or future changes in how overrides are handled internally). That said, given the current API constraints, it probably makes more sense to focus on:
So I think the empty string test is definitely valid and useful, while the null case may not be applicable in practice unless there's a different entry point I'm missing. Let me know your thoughts. |
…in DefaultKafkaConsumerFactory * remove null value test as Properties.put(key, null) throws at JDK level before reaching factory * update empty string test to use mock Consumer instead of null * add test verifying new keys in override Properties are added to consumer config" Signed-off-by: Sayan Sarkar <sarkarsayan749@gmail.com>
|
This looks much cleaner now, thanks for the updates! One thing I’m unsure about is the expected behavior for empty string overrides:
So it seems like we’re treating empty string both as:
Could you clarify which behavior is intended? If empty string is considered a valid override, then the second test might need to assert "" instead of "10". |
|
Maybe we should explicitly document the behavior:
and align all tests accordingly |
|
@Gautam-aman So I removed the null test entirely and added another test that checks if new keys that are not already in the config are added or not; addressing the missing keys point you mentioned. Please check if anything else is needed or feel free to improve the tests. |
|
Thanks for pointing this out. I see where the confusion is coming from. In the second test So the current behavior is consistent with:
If you think we should explicitly document or test the behavior for empty string overrides on existing keys more clearly, I can add an additional test to make that intent explicit. |
|
Got it , thanks for clarifying, that makes sense. I had assumed The current tests look good to me 👍 |
| } | ||
|
|
||
| @Test | ||
| public void testNewKeyInOverridePropertiesIsAddedToConfig() { |
There was a problem hiding this comment.
I don't think this test is related to the issue in #4422 - the scenarios you're testing here are already covered by other tests in this class. I suggest dropping it.
Also, the PR description in one of the commit messages says you've added a test for the null-value case, but I don't see one in the diff. There isn't really a meaningful "null value" path through DefaultKafkaConsumerFactory to test since Properties.put(key, null) throws NPE. Please fix that message.
There was a problem hiding this comment.
Will drop testNewKeyInOverridePropertiesIsAddedToConfig as suggested. I'll also fix the commit message to remove the reference to the null value test.
| props.setProperty("max.poll.records", ""); | ||
| factory.createConsumer(null, null, null, props); | ||
|
|
||
| assertThat(capturedConfig.get("max.poll.records")).isEqualTo(""); |
There was a problem hiding this comment.
Any reason why you didn't follow the same strategies used in testMixedTypeOverridesApplied for example where it uses and AtomicReference to capture the consumer config and then set it using the captured config? That way, we assert against the real Kafka ConsumerConfig.
There was a problem hiding this comment.
I tried updating the test to use AtomicReference<ConsumerConfig> pattern, but ran into an issue : ConsumerConfig validates field values strictly, so empty string fails validation for standard Kafka config fields like max.poll.records and auto.offset.reset. Could you suggest a specific config key that would work for testing empty string override behavior, or should we keep the raw map assertion for this case?
|
@Flicko75 Any chance to address my concerns above? Our release is almost around the corner and we only have a few days to address this. |
Fixes GH-4422 (#4422)