testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

[Enhancement]: ContainerDatabaseDriver ignores additional JDBC properties

Open zarebski-m opened this issue 3 years ago • 2 comments

Module

MySQL

Proposal

Happens for MySQL, but the issue is more general. JDBC allows specifying additional properties as a key/value pair when connecting to the DB:

https://docs.oracle.com/javase/7/docs/api/java/sql/Driver.html#connect(java.lang.String,%20java.util.Properties)

Those should be used as if they were appended to JDBC URL, e.g.:

var info = new Properties();
info.put("allowMultiQueries", "true");
driver.connect("jdbc:tc:mysql:5.7:///?TC_TMPFS=/var/lib/mysql:rw", info);

This should have the same effect as JDBC URL jdbc:tc:mysql:5.7:///?TC_TMPFS=/var/lib/mysql:rw&allowMultiQueries=true.

For example in Spring Boot, one can define JDBC properties through application properties, without changing the original JDBC URL:

spring:
  datasource:
    url: jdbc:mysql://localhost/test
    hikari:
      data-source-properties:
        characterEncoding: UTF-8
        useUnicode: true

This configuration does not work in Testcontainers because data-source-properties are passed as the second argument of Driver#connect method, and ContainerDatabaseDriver is simply ignoring them.

zarebski-m avatar Jul 30 '22 22:07 zarebski-m

Any progress on this?

s-jepsen avatar Sep 02 '22 04:09 s-jepsen

var info = new Properties();
info.put("allowMultiQueries", "true");
driver.connect("jdbc:tc:mysql:5.7:///?TC_TMPFS=/var/lib/mysql:rw", info);

I've been able to reproduce this on my end. It looks like ContainerDatabaseDriver#connect ignores the info argument completely. Thanks for the issue @zarebski-m. Let me look into this.

aidando73 avatar Sep 08 '22 11:09 aidando73