cayenne
cayenne copied to clipboard
fix: replace non deterministic order data structure
The test org.apache.cayenne.log.CompactSlf4jJdbcEventLoggerTest.compactBindings will fail under NonDex tool that detect flakiness under non-deterministic order.
In function CompactSlf4jJdbcEventLogger .collectBindings, the function is declared with the usage of HashMap.
protected void appendParameters(StringBuilder buffer, String label, ParameterBinding[] bindings) {
...
buildBinding(buffer, label, collectBindings(bindings));
}
private Map<String, List<String>> collectBindings(ParameterBinding[] bindings) {
Map<String, List<String>> bindingsMap = new HashMap<>();
...
bindingsMap.computeIfAbsent(key, k -> new ArrayList<>());
...
return bindingsMap;
}
Whereas the test relies on the result of the HashMap to determine the output, whereas toString should not be able to guarantee the order of insertion.
logger.appendParameters(buffer, "bind", bindings);
assertEquals(buffer.toString(), ...);
I proposed to use LinkedHashMap to keep the hash property while maintaining some kind of ordering.