-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
I am trying to use MySQLContainer to create a MySQL container using a specific time zone.
Reading the documentation (see https://dev.mysql.com/doc/refman/8.0/en/timezone-problems.html and https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html) this should work by setting the environment variable TZ, which I can achieve using GenericContainer#withEnv(String, String). When I do this, (e.g. by calling withEnv("TZ", "Europe/Zurich")) the container fails to start properly and I run into a timeout in my JUnit test, without any helpful log messages.
After some more testing and reading I found out that I should also set the serverTimezone property (see https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html). Unfortunately the only simple way of achieving this I found was to subclass MySQLContainer and override constructUrlForConnection(String).
To me it seems like it could be useful to add some kind of JdbcDatabaseContainer#addProperty(String, String) (or withProperty()?) method and then use the supplied properties in JdbcDatabaseContainer#createConnection(String). Or possibly have a protected getProperties() method? Or am I going about this the wrong way?