You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces a configurable KeyMatchStrategy enum in ktestify-core that allows expectedRecordKey to be matched using strategies other than exact equality: CONTAINS, STARTS_WITH, ENDS_WITH, and REGEX.
Previously, expectedRecordKey was hardcoded to String.equals() in five locations: the fetch-time pre-filter (KafkaRecordFetcher.passesKeyFilter()) and four assertion-time matchers (KeyRecordMatcher, FileKeyRecordMatcher, AvroKeyRecordMatcher, AvroFileKeyRecordMatcher). This made it impossible to validate dynamically generated keys (UUIDs, prefixed keys, etc.) without knowing the exact value upfront.
The new KeyMatchStrategy enum encapsulates the comparison logic in a single matches(expected, actual) method. It flows through both layers identically to how expectedRecordKey already flows: ConsumerContext (fetch-time filter) and MatchContext (assertion). The default is EXACT, preserving full backward compatibility.
✨ New feature — non-breaking change that adds functionality
✅ Pre-Merge Checklist
Code Quality
My code follows the Palantir Java Format style (passes mvn spotless:check)
I have added or updated Javadoc on public types and methods
Tests
I have added unit tests that cover the new / changed behaviour
All existing and new tests pass locally (mvn verify)
JaCoCo line coverage ≥ 70 % is maintained
Tests using Testcontainers are isolated and do not leave containers running
Licensing
Apache 2.0 license header has been added to every new source file (using spotless)
🧪 How to Test Locally
# 1. Build and run all tests (requires Docker for Testcontainers)
mvn verify
# 2. Check code style
mvn spotless:check
# 3. Run only the new strategy tests
mvn test -Dtest=KeyMatchStrategyTest
mvn test -Dtest=KeyRecordMatcherTest
📸 Screenshots / Logs
All tests pass:
mvn spotless:check test → BUILD SUCCESS
KeyMatchStrategyTest → 30+ parameterized cases (5 strategies + fromString parsing)
KeyRecordMatcherTest → 10 new strategy cases added to existing suite
📚 Additional Context
Files Changed
New file:
match/KeyMatchStrategy.java : Enum with EXACT, CONTAINS, STARTS_WITH, ENDS_WITH, REGEX. Includes fromString() for parsing DataTable values (case-insensitive, tolerant of hyphens/underscores/spaces, defaults to EXACT).
Modified (main):
File
Change
io/kafka/ConsumerContext.java
Added keyMatchStrategy field + builder method (defaults to EXACT)
io/kafka/KafkaRecordFetcher.java
passesKeyFilter() uses strategy.matches() instead of equals()
io/kafka/AbstractKafkaConsumer.java
buildMatchContext() propagates keyMatchStrategy to MatchContext
match/MatchContext.java
Added keyMatchStrategy field with @Builder.Default = EXACT
match/impl/KeyRecordMatcher.java
Uses strategy.matches()
match/impl/FileKeyRecordMatcher.java
Uses strategy.matches()
match/impl/AvroKeyRecordMatcher.java
Uses strategy.matches()
match/impl/AvroFileKeyRecordMatcher.java
Uses strategy.matches()
Modified (test):
File
Change
match/KeyMatchStrategyTest.java
New — 30+ cases covering all strategies and fromString() parsing
match/impl/KeyRecordMatcherTest.java
Added KeyStrategies nested class with 10 strategy tests
match/impl/MatcherTestSupport.java
Added ctxWithKeyAndStrategy() helper
Backward Compatibility
The default strategy is EXACT everywhere. Existing feature files and code paths that do not set keyMatchStrategy behave exactly as before. No breaking changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
📝 Description
This PR introduces a configurable
KeyMatchStrategyenum inktestify-corethat allowsexpectedRecordKeyto be matched using strategies other than exact equality:CONTAINS,STARTS_WITH,ENDS_WITH, andREGEX.Previously,
expectedRecordKeywas hardcoded toString.equals()in five locations: the fetch-time pre-filter (KafkaRecordFetcher.passesKeyFilter()) and four assertion-time matchers (KeyRecordMatcher,FileKeyRecordMatcher,AvroKeyRecordMatcher,AvroFileKeyRecordMatcher). This made it impossible to validate dynamically generated keys (UUIDs, prefixed keys, etc.) without knowing the exact value upfront.The new
KeyMatchStrategyenum encapsulates the comparison logic in a singlematches(expected, actual)method. It flows through both layers identically to howexpectedRecordKeyalready flows:ConsumerContext(fetch-time filter) andMatchContext(assertion). The default isEXACT, preserving full backward compatibility.Resolves #46
🔄 Type of Change
✅ Pre-Merge Checklist
Code Quality
mvn spotless:check)Tests
mvn verify)Licensing
🧪 How to Test Locally
📸 Screenshots / Logs
All tests pass:
📚 Additional Context
Files Changed
New file:
match/KeyMatchStrategy.java: Enum withEXACT,CONTAINS,STARTS_WITH,ENDS_WITH,REGEX. IncludesfromString()for parsing DataTable values (case-insensitive, tolerant of hyphens/underscores/spaces, defaults toEXACT).Modified (main):
io/kafka/ConsumerContext.javakeyMatchStrategyfield + builder method (defaults toEXACT)io/kafka/KafkaRecordFetcher.javapassesKeyFilter()usesstrategy.matches()instead ofequals()io/kafka/AbstractKafkaConsumer.javabuildMatchContext()propagateskeyMatchStrategytoMatchContextmatch/MatchContext.javakeyMatchStrategyfield with@Builder.Default=EXACTmatch/impl/KeyRecordMatcher.javastrategy.matches()match/impl/FileKeyRecordMatcher.javastrategy.matches()match/impl/AvroKeyRecordMatcher.javastrategy.matches()match/impl/AvroFileKeyRecordMatcher.javastrategy.matches()Modified (test):
match/KeyMatchStrategyTest.javafromString()parsingmatch/impl/KeyRecordMatcherTest.javaKeyStrategiesnested class with 10 strategy testsmatch/impl/MatcherTestSupport.javactxWithKeyAndStrategy()helperBackward Compatibility
The default strategy is
EXACTeverywhere. Existing feature files and code paths that do not setkeyMatchStrategybehave exactly as before. No breaking changes.