You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/09/24 20:24:38 UTC
[GitHub] [incubator-shardingsphere] contextshuffling opened a new issue
#3108: Test can fail if HashMap iterates in a different order
contextshuffling opened a new issue #3108: Test can fail if HashMap iterates in a different order
URL: https://github.com/apache/incubator-shardingsphere/issues/3108
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/incubator-shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response **more than 7 days** and we cannot reproduce it on current information, we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
dev branch: 4.0.0-RC3-SNAPSHOT
### Which project did you use? Sharding-JDBC or Sharding-Proxy?
sharding-orchestration
### Expected behavior
Tests that rely on `AUTHENTICATION_YAML` inside [ConfigurationServiceTest](https://github.com/apache/incubator-shardingsphere/blob/48ad82f690e59c4690fca936096b1149558a3880/sharding-orchestration/sharding-orchestration-core/src/test/java/org/apache/shardingsphere/orchestration/internal/registry/config/service/ConfigurationServiceTest.java) should pass regardless of the HashMap iteration orders.
### Actual behavior
Tests can fail if the order changes
### Reason analyze (If you can)
Currently, `YamlAuthenticationConfiguration.java` and `Authentication.java` are using HashMap to map users. However, HashMap does not guarantee any specific order of entries.
Therefore the string version of `Authentication` objects do not always match `AUTHENTICATION_YAML` as expected by the tests.
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
For examples, if `AUTHENTICATION_YAML` has `root2` comes before `root1` in the string, the tests would fail as iteration order is not same as the input.
```
[ERROR] ConfigurationServiceTest.assertPersistConfigurationForShardingRuleWithAuthenticationAndIsOverwrite:190
Argument(s) are different! Wanted:
regCenter.persist(
"/test/config/authentication",
"users:
root2:
authorizedSchemas: sharding_db
password: root1
root1:
authorizedSchemas: sharding_db,ms_db
password: root2
"
);
-> at org.apache.shardingsphere.orchestration.internal.registry.config.service.ConfigurationServiceTest.assertPersistConfigurationForShardingRuleWithAuthenticationAndIsOverwrite(ConfigurationServiceTest.java:190)
Actual invocation has different arguments:
regCenter.persist(
"/test/config/authentication",
"users:
root1:
authorizedSchemas: sharding_db,ms_db
password: root2
root2:
authorizedSchemas: sharding_db
password: root1
"
);
```
### Example codes for reproduce this issue (such as a github link).
Changing `AUTHENTICATION_YAML` to have `root2` come first.
```
private static final String AUTHENTICATION_YAML = "users:\n" + " root2:\n" + " authorizedSchemas: sharding_db\n" + " password: root1\n"
+ " root1:\n" + " authorizedSchemas: sharding_db,ms_db\n" + " password: root2\n";
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services