contextshuffling commented on a change in pull request #3164: changing HashMap
to LinkedHashMap for deterministic iterations
URL:
https://github.com/apache/incubator-shardingsphere/pull/3164#discussion_r331205271
##########
File path:
sharding-jdbc/sharding-jdbc-core/src/test/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/statement/EncryptPreparedStatementTest.java
##########
@@ -59,7 +59,7 @@ public void assertInsertWithExecute() throws SQLException {
statement.setObject(2, 'b');
statement.execute();
}
- assertResultSet(3, 2, "encryptValue", "assistedEncryptValue");
+ assertResultSet(0, 2, "encryptValue", "assistedEncryptValue");
Review comment:
@terrymanu Thanks for pointing this out. We set the value to 0 because we
observed after changing to LinkedHashMap to make iteration order deterministic
that the test only passes with result set count as 0. However, after looking at
it in more detail, we believe that what the tests want is to check the results
in "encrypt" connection.
Currently, the code seems to be getting the "encrypt" connection by assuming
it is the first connection stored in the HashMap: [e.g., L152 of
EncryptPreparedStatementTest.java](https://github.com/apache/incubator-shardingsphere/blob/382653d8b229cfb46be2219868b94821a2cef2b1/sharding-jdbc/sharding-jdbc-core/src/test/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/statement/EncryptPreparedStatementTest.java#L152).
However, given that the HashMap does not iterate deterministically, the first
connection may not always be that "encrypt" one. Instead of iterating to get
the first element, maybe it should explicitly get the "encrypt" connection by
accessing the map?
For example,
```
Connection conn =
getDatabaseTypeMap().get(DatabaseTypes.getActualDatabaseType("H2")).get("encrypt").getConnection()
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services