Replies: 3 comments 1 reply
|
Hi @aabeling You've actually done the hard diagnostic work already, you confirmed The most reliable workaround right now is to bypass the URL-based container creation entirely and instantiate the @Testcontainers
@SpringBootTest
class YourIntegrationTest {
@Container
static MariaDBContainer<?> mariaDB = new MariaDBContainer<>("mariadb:10.6.21")
.withDatabaseName("workflow")
.withUsername("test")
.withPassword("test")
.withEnv("TZ", "Europe/Berlin"); // this is the key line
@DynamicPropertySource
static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.r2dbc.url", () ->
String.format("r2dbc:mariadb://%s:%d/%s",
mariaDB.getHost(),
mariaDB.getMappedPort(3306),
mariaDB.getDatabaseName()
)
);
registry.add("spring.r2dbc.username", mariaDB::getUsername);
registry.add("spring.r2dbc.password", mariaDB::getPassword);
}
}This works because If you want to keep the URL-based approach, there is a second option, use the MariaDB R2DBC connector's own The values it accepts are For your specific scenario where |
|
The R2DBC URL provider ( @Container
static MariaDBContainer<?> mariadb = new MariaDBContainer<>("mariadb:10.6.21")
.withEnv("TZ", "Europe/Berlin")
.withCommand("--default-time-zone=Europe/Berlin");Then configure your R2DBC connection factory using the container's host and mapped port instead of the ConnectionFactory connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(DRIVER, "mariadb")
.option(HOST, mariadb.getHost())
.option(PORT, mariadb.getMappedPort(3306))
.option(DATABASE, "workflow")
.option(USER, mariadb.getUsername())
.option(PASSWORD, mariadb.getPassword())
.build()
);The If you prefer keeping the |
Uh oh!
There was an error while loading. Please reload this page.
I am able to start a mariadb testcontainer with a jdbc url like
r2dbc:tc:mariadb:///workflow?TC_IMAGE_TAG=10.6.21.But it does not have the correct timezone I need for my application and my tests.
Tests for queries using
NOW()make problems.With
jdbc:tc:mysql:8.0.36://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_overrideit is possible to provide amy.cnfwith something likeThe same is possible with
jdbc:tc:mariadb.How can I set the timezone for the database container with "r2dbc"?
#4687 says it does not support TC_INITSCRIPT, but this would not help to set the timezone anyway since the timezone must be defined at the start of the database server.
All reactions