[ 
https://issues.apache.org/jira/browse/NIFI-9964?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xinyu Wu updated NIFI-9964:
---------------------------
    Description: 
The test 
`org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess`
 can fail based on the order of iteration in `HashMap`. 
In line 437 to 441:
```
        final List<RecordField> fields = new ArrayList<>();
        fields.add(new RecordField("favorite", 
RecordFieldType.STRING.getDataType(), false));
        fields.add(new RecordField("least", 
RecordFieldType.STRING.getDataType(), true));
        final RecordSchema schema = new SimpleRecordSchema(fields);
        final Record sports = new MapRecord(schema, new HashMap<>());
```
It creates two `RecordField` `favorite` and `least` and adds them into `Record` 
`sports`. Since `sports` is created by a HashMap, the order of `favorite` and 
`least` are indeterminate in `sports`. Therefore, in the actual `MockFlowFile` 
content, the order of "soccer" and "basketball" is also indeterminate.
I found the issue using 
[NonDex](https://github.com/TestingResearchIllinois/NonDex):
```
mvn install -DskipTests -pl 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors -am
mvn -pl nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors 
edu.illinois:nondex-maven-plugin:1.1.2:nondex 
-Dtest=org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess
```
The proposed fix changes the assertion to endure the indeterminacy.


  was:
The test 
`org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess`
 can fail based on the order of iteration in `HashMap`. 
In line 437 to 441:
```
        final List<RecordField> fields = new ArrayList<>();
        fields.add(new RecordField("favorite", 
RecordFieldType.STRING.getDataType(), false));
        fields.add(new RecordField("least", 
RecordFieldType.STRING.getDataType(), true));
        final RecordSchema schema = new SimpleRecordSchema(fields);
        final Record sports = new MapRecord(schema, new HashMap<>());
```
It creates two ```RecordField``` ```favorite``` and ```least``` and adds them 
into ```Record``` ```sports```. Since ```sports``` is created by a HashMap, the 
order of ```favorite``` and ```least``` are indeterminate in ```sports```. 
Therefore, in the actual ```MockFlowFile``` content, the order of "soccer" and 
"basketball" is also indeterminate.
I found the issue using 
[NonDex](https://github.com/TestingResearchIllinois/NonDex):
```
mvn install -DskipTests -pl 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors -am
mvn -pl nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors 
edu.illinois:nondex-maven-plugin:1.1.2:nondex 
-Dtest=org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess
```
The proposed fix changes the assertion to endure the indeterminacy.



> TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess failing due to 
> indeterminate map ordering
> ------------------------------------------------------------------------------------------------------
>
>                 Key: NIFI-9964
>                 URL: https://issues.apache.org/jira/browse/NIFI-9964
>             Project: Apache NiFi
>          Issue Type: Bug
>            Reporter: Xinyu Wu
>            Priority: Minor
>
> The test 
> `org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess`
>  can fail based on the order of iteration in `HashMap`. 
> In line 437 to 441:
> ```
>         final List<RecordField> fields = new ArrayList<>();
>         fields.add(new RecordField("favorite", 
> RecordFieldType.STRING.getDataType(), false));
>         fields.add(new RecordField("least", 
> RecordFieldType.STRING.getDataType(), true));
>         final RecordSchema schema = new SimpleRecordSchema(fields);
>         final Record sports = new MapRecord(schema, new HashMap<>());
> ```
> It creates two `RecordField` `favorite` and `least` and adds them into 
> `Record` `sports`. Since `sports` is created by a HashMap, the order of 
> `favorite` and `least` are indeterminate in `sports`. Therefore, in the 
> actual `MockFlowFile` content, the order of "soccer" and "basketball" is also 
> indeterminate.
> I found the issue using 
> [NonDex](https://github.com/TestingResearchIllinois/NonDex):
> ```
> mvn install -DskipTests -pl 
> nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors -am
> mvn -pl nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors 
> edu.illinois:nondex-maven-plugin:1.1.2:nondex 
> -Dtest=org.apache.nifi.processors.standard.TestLookupRecord#testAddFieldsToExistingRecordRouteToSuccess
> ```
> The proposed fix changes the assertion to endure the indeterminacy.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to