Repository navigation
Fix failed-connection tests on JDK 11 and set up JDK 11 in CI - #692
Conversation
On JDK 11, MysqlFailedConnectionTest and OracleFailedConnectionTest fail because DBSpecificFailedConnectionTest compares raw validation error strings containing Properties.toString(). Java 9+ changed Properties to store entries in an internal ConcurrentHashMap rather than Hashtable, which changes map iteration order when multiple connection properties are present. The GitHub Actions unit test workflow also runs without configuring JDK 11. Normalize the key=value entries inside the connection arguments block in DBSpecificFailedConnectionTest before comparing messages. That keeps assertions strict on the JDBC URL, properties, and error text across JDK 8 and JDK 11. Configure Temurin 11 in the unit test workflow for branches other than release/1.11. Verified mvn clean test -B across all 20 modules on JDK 11 passes RAT, Checkstyle, and all 207 unit tests (186 executed, 21 live-DB suites skipped).
There was a problem hiding this comment.
Code Review
This pull request introduces a normalization helper, normalizeConnectionArguments, in DBSpecificFailedConnectionTest along with a new test class DBSpecificFailedConnectionMessageTest to verify its behavior. This normalization sorts connection arguments in error messages to prevent test failures caused by non-deterministic argument ordering across different JDK versions. The feedback suggests a minor optimization to simplify the sorting logic by using Arrays.sort directly on the array instead of converting it to a list, which also allows removing an unused import.
| List<String> entries = Arrays.asList(argsContent.split(", ", -1)); | ||
| Collections.sort(entries); | ||
| return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd); |
There was a problem hiding this comment.
We can simplify this logic by sorting the array directly using Arrays.sort instead of wrapping it in a list via Arrays.asList and calling Collections.sort. This avoids unnecessary object allocation and simplifies the code. If you apply this change, the import java.util.Collections on line 30 will also become unused and can be removed.
| List<String> entries = Arrays.asList(argsContent.split(", ", -1)); | |
| Collections.sort(entries); | |
| return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd); | |
| String[] entries = argsContent.split(", ", -1); | |
| Arrays.sort(entries); | |
| return errorMsg.substring(0, contentStart) + String.join(", ", entries) + errorMsg.substring(argsEnd); |
| normalizeConnectionArguments(validationFailures.get(0).getMessage())); | ||
| } | ||
|
|
||
| static String normalizeConnectionArguments(String errorMsg) { |
There was a problem hiding this comment.
nit: Can be simplified
Option 1
static String normalizeConnectionArguments(String errorMsg) {
if (errorMsg == null) {
return null;
}
int argsStart = errorMsg.indexOf(ARGS_PREFIX);
if (argsStart < 0) {
return errorMsg;
}
int contentStart = argsStart + ARGS_PREFIX.length();
int argsEnd = errorMsg.indexOf(ARGS_SUFFIX, contentStart);
if (argsEnd <= contentStart) { // Combines missing suffix (< 0) and empty content (== contentStart)
return errorMsg;
}
String sortedArgs = Arrays.stream(errorMsg.substring(contentStart, argsEnd).split(", ", -1))
.sorted()
.collect(Collectors.joining(", "));
return errorMsg.substring(0, contentStart) + sortedArgs + errorMsg.substring(argsEnd);
}Option 2
private static final Pattern ARGS_PATTERN = Pattern.compile(
Pattern.quote(ARGS_PREFIX) + "(.+?)" + Pattern.quote(ARGS_SUFFIX),
Pattern.DOTALL
);
static String normalizeConnectionArguments(String errorMsg) {
if (errorMsg == null) {
return null;
}
return ARGS_PATTERN.matcher(errorMsg).replaceFirst(match -> {
String sorted = Arrays.stream(match.group(1).split(", ", -1))
.sorted()
.collect(Collectors.joining(", "));
return Matcher.quoteReplacement(ARGS_PREFIX + sorted + ARGS_SUFFIX);
});
}
On JDK 11,
MysqlFailedConnectionTestandOracleFailedConnectionTestfail becauseDBSpecificFailedConnectionTestcompares raw validation error strings containingProperties.toString(). Java 9+ changedPropertiesto store entries in an internalConcurrentHashMaprather thanHashtable, which changes map iteration order when multiple connection properties are present. The GitHub Actions unit test workflow also runs without configuring JDK 11.Normalize the
key=valueentries inside the connection arguments block inDBSpecificFailedConnectionTestbefore comparing messages. That keeps assertions strict on the JDBC URL, properties, and error text across JDK 8 and JDK 11. Configure Temurin 11 in the unit test workflow for branches other thanrelease/1.11.Verified
mvn clean test -Bacross all 20 modules on JDK 11 passes RAT, Checkstyle, and all 207 unit tests (186 executed, 21 live-DB suites skipped).