Skip to content

Conversation

@shunfan-shao
Copy link

@shunfan-shao shunfan-shao commented Oct 29, 2021

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.

Shao and others added 2 commits September 5, 2021 09:56
fix: replace non deterministic order data structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant