Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace non deterministic order data structure #470

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

fix: replace non deterministic order data structure #470

wants to merge 2 commits into from

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
1 participant