annhchen89 opened a new pull request, #4043:
URL: https://github.com/apache/streampipes/pull/4043

   <!--
     ~ Licensed to the Apache Software Foundation (ASF) under one or more
     ~ contributor license agreements.  See the NOTICE file distributed with
     ~ this work for additional information regarding copyright ownership.
     ~ The ASF licenses this file to You under the Apache License, Version 2.0
     ~ (the "License"); you may not use this file except in compliance with
     ~ the License.  You may obtain a copy of the License at
     ~
     ~    http://www.apache.org/licenses/LICENSE-2.0
     ~
     ~ Unless required by applicable law or agreed to in writing, software
     ~ distributed under the License is distributed on an "AS IS" BASIS,
     ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     ~ See the License for the specific language governing permissions and
     ~ limitations under the License.
     ~
     -->
   
     <!--
   Thanks for contributing! Here are some tips you can follow to help us 
incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/community/get-involved/
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title 
...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
`[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the 
`Development` section in the right menu bar.
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a 
faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### What is the purpose of the change
   
   Fixes nondeterministic tests in  
   `org.apache.streampipes.extensions.management.connect.adapter.parser.json`
   ```
   .GeoJsonParserTest#getGuessSchema
   .JsonArrayKeyParserTest#getGuessSchema
   .JsonArrayParserTest#getGuessSchema
   .JsonObjectParsersTest#getGuessSchema
   ```
   
   The test previously performed a full `assertEquals(expected, result)` on the 
entire `GuessSchema` object.  
   However, `GuessSchemaBuilder` stores event samples in a `HashMap`:
   
   `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:
   
   ```bash
   mvn edu.illinois:nondex-maven-plugin:2.2.1:nondex \
     
-Dtest=org.apache.streampipes.extensions.management.connect.adapter.parser.json.GeoJsonParserTest#getGuessSchema
   ```
   The same issue also appears in:
   ```
   .JsonArrayKeyParserTest#getGuessSchema
   .JsonArrayParserTest#getGuessSchema
   .JsonObjectParsersTest#getGuessSchema
   ```
   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.
   
   ---
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, 
or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): no
   
   PR introduces (a) deprecation(s): no
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to