testcontainers/testcontainers-java

Support hikari data-source-properties in ContainerDatabaseDriver

Open

#1,537 创建于 2019年6月9日

在 GitHub 查看
 (12 评论) (2 反应) (0 负责人)Java (7,535 star) (1,588 fork)batch import
good first issuemodules/jdbcresolution/acknowledgedtype/feature

描述

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();
    }

贡献者指南

Support hikari data-source-properties in ContainerDatabaseDriver · testcontainers/testcontainers-java#1537 | Good First Issue