testcontainers / testcontainers/testcontainers-java

Support hikari data-source-properties in ContainerDatabaseDriver

Open
#1,537 12 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue modules/jdbc resolution/acknowledged type/feature
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ContainerDatabaseDriver.connect and inspect how its info parameter is handled when creating the database connection. Compare that behavior with the MySQL driver's use of connection properties, using the Spring Boot Hikari configuration in the issue as the reproduction case. Done means hikari data-source-properties reach the underlying connection without requiring them in the JDBC URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, mysql, spring-boot
Domain
database, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.