testcontainers-java
testcontainers-java copied to clipboard
[Enhancement]: ContainerDatabaseDriver ignores additional JDBC properties
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.
Any progress on this?
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.