Reputation: 1386
When constructing a JUnit test using Testcontainers my test hangs until timeout after the message "Waiting for database connection to become available at" and the container logs, then helpfully shown, do not yield any error. I can even connect to the running docker container with my favourite JDBC-query-tool.
Currently I'm using the MySQL container.
Upvotes: 4
Views: 5687
Reputation: 11
I had the same problem but with a different solution. You might have to check the version of the mysql docker image or versions of the Testcontainers dependencies. So this worked for me:
pom.xml:
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>
TestClass
@Testcontainers
public class TestClass {
@Container
private static final MySQLContainer<?> mysqlContainer
= new MySQLContainer<>("mysql:9.2.0")
.withDatabaseName("testdatabase")
.withUsername("test")
.withPassword("test");
}
Upvotes: 1
Reputation: 1386
This is because I did not include the MySQL JDBC driver in my classpath. The Testcontainers does not log the fact that the 'SELECT 1', it suggests it's doing, is going wrong because of the missing driver. Normally it should fail with some timeout first until the container is up-and-running. But now it fails due to the missing driver and it somehow does not make a distinction.
Upvotes: 2