Hello. For me, Testcontainers is a completely new topic, so a question arose. I have a Spring / Hibernate application. I have a docker image (h2testbase) with a custom mysql database (myTestDb) for tests (it is already ready with data). I run this image in docker with -p 6161: 3306. In the test / resources folder I have application.properties with the following content
jdbc.driverClassName=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:6161/myTestDb?allowPublicKeyRetrieval=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Europe/Moscow&&useSSL=false jdbc.username=root jdbc.cred=admin hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=true I run tests with mvn test - everything works. Now I want to run these tests using Testcontainers. Added to pom
<dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> <version>1.9.1</version> </dependency> <dependency> <groupId>org.testcontainers</groupId> <artifactId>mysql</artifactId> <version>1.9.1</version> <scope>test</scope> </dependency> I inherited the MySQLContainer class
public class TestMySQL extends MySQLContainer { public TestMySQL() { super(); } public TestMySQL(String dockerImageName) { super(dockerImageName); } @Override public String getDriverClassName() { return "com.mysql.cj.jdbc.Driver"; } } since MySQLContainer itself uses com.mysql.jdbc.Driver and maven does not accept it as deprecated. In the test I write
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { HibernateConfiguration.class, SecurityConfiguration.class, SecurityInitializer.class, ViewConfiguration.class, ViewInitializer.class}) @WebAppConfiguration public class ControllerServiceJTest { @ClassRule public static TestMySQL container = new TestMySQL("h2testbase"); @Autowired ControllerService controllerService; @Test public void stationPagination() { Map<String, Object> pag = controllerService.stationPagination(4); Assert.assertTrue(((List<Station>)pag.get("stations")).size() == 8); } @Test public void trainPagination() { Map<String, Object> pag = controllerService.trainPagination(1); Assert.assertTrue(((List<Train>)pag.get("trains")).size() == 20); } @Test public void switchHelper() { Assert.assertTrue(controllerService.stationSwitchHelper("BLUE").equals(URLs.REDIRECT_DASHSTATION + "/2")); } } And here I have a stupor. If I run the mvn test, then through docker ps I see that the container starts (but to some left-hand ports of type 328xx), and several instances are launched, but after a while the maven issues the following
org.testcontainers.containers.ContainerLaunchException: Container startup failed Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container Caused by: org.rnorth.ducttape.TimeoutException: org.rnorth.ducttape.TimeoutException: java.util.concurrent.TimeoutException Caused by: org.rnorth.ducttape.TimeoutException: java.util.concurrent.TimeoutException Caused by: java.util.concurrent.TimeoutException What to do next? How to specify a container to be created on which port to map? How to pass parameters to it that are registered in application.properties? I am not able to find a single code example where I would use an image with a ready base. Thank you in advance.