testcontainers/testcontainers-java
Vedi su GitHubSupport hikari data-source-properties in ContainerDatabaseDriver
Open
#1537 aperta il 9 giu 2019
good first issuemodules/jdbcresolution/acknowledgedtype/feature
Metriche repository
- Star
- (7535 star)
- Metriche merge PR
- (Merge medio 2g 17h) (2 PR mergiate in 30 g)
Descrizione
I tried to use test containers with hikari data-source-properties in Spring Boot like this:
spring:
datasource:
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:mysql:5.7.22://testcontainers/hi_perf_java_pers #?rewriteBatchedStatements=true&profileSQL=true&logger=com.mysql.cj.log.Slf4JLogger
hikari:
data-source-properties:
rewriteBatchedStatements: true
profileSQL: true
logger: com.mysql.cj.log.Slf4JLogger
But datasource properties are ignored by connect method inside ContainerDatabaseDriver (info parameter in method connect).
Workaround so far is to include properties directly into connection string (commented part in url #?rewriteBatched...).
MySQL driver is doing it in this way:
/**
* Builds a connection URL cache map key based on the connection string itself plus the string representation of the given connection properties.
*
* @param connString
* the connection string
* @param info
* the connection arguments map
* @return a connection string cache map key
*/
private static String buildConnectionStringCacheKey(String connString, Properties info) {
StringBuilder sbKey = new StringBuilder(connString);
sbKey.append("\u00A7"); // Section sign.
sbKey.append(
info == null ? null : info.stringPropertyNames().stream().map(k -> k + "=" + info.getProperty(k)).collect(Collectors.joining(", ", "{", "}")));
return sbKey.toString();
}