fix: Fixing Non-deterministic Tests caused by HashMap #4043
+55
−8
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.
What is the purpose of the change
Fixes nondeterministic tests in
org.apache.streampipes.extensions.management.connect.adapter.parser.jsonThe test previously performed a full
assertEquals(expected, result)on the entireGuessSchemaobject.However,
GuessSchemaBuilderstores event samples in aHashMap:this.samples = new HashMap<>();Since HashMap does not guarantee key iteration order, the JSON generated in eventPreview may serialize fields in different orders, such as:
{"longitude": 6.94, "latitude": 51.43, "temperature": 5.0}or{"latitude": 51.43, "temperature": 5.0, "longitude": 6.94}These variations are semantically identical but cause strict equality checks to fail, causing nondeterministic failures during repeated runs or under NonDex.
Reproduce Test
The non-deterministic behavior can be reliably reproduced with NonDex using:
The same issue also appears in:
This will intermittently produce failures depending on the map iteration order.
The Fix
Instead of asserting equality on the entire GuessSchema object, it now parses the JSON preview entries into Map<String, Object> then check equivalency using
assertEquals(expectedMap, actualMap);This performs structural JSON comparison, ensuring correctness while ignoring nondeterministic key ordering.
PR introduces (a) breaking change(s): no
PR introduces (a) deprecation(s): no