testcontainers

Mongo in testcontainers

孤街浪徒 提交于 2020-07-23 08:03:09
问题 I started playing with testcontainers and at the beginning of my journey I faced some issue (below). I did similar thing for mysql db and it worked fine. Do I miss some mongo specific config? According to [docs][1] there is not much to do. Thanks in advance for any tips / examples. com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-3.11.2.jar:na] at com.mongodb.internal.connection

Mongo in testcontainers

六眼飞鱼酱① 提交于 2020-07-23 08:03:03
问题 I started playing with testcontainers and at the beginning of my journey I faced some issue (below). I did similar thing for mysql db and it worked fine. Do I miss some mongo specific config? According to [docs][1] there is not much to do. Thanks in advance for any tips / examples. com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-3.11.2.jar:na] at com.mongodb.internal.connection

Is there a way to pass docker flags in GenericContainer from test containers

梦想的初衷 提交于 2020-06-29 04:31:25
问题 Is there a way to pass those flags from this command in GenericContainer object from test-containers lib ? docker container run \ --publish 9092:9082 \ --detach \ --name h2 \ nemerosa/h2 @ClassRule public static GenericContainer h2db = new GenericContainer("nemerosa/h2") .withStartupTimeout(Duration.ofSeconds(Constants.TIMEOUT_DURATION)); 回答1: For exposing ports, Testcontainers offers a method on the GenericContainer : @ClassRule public static GenericContainer h2db = new GenericContainer(

Populate a database with TestContainers in a SpringBoot integration test

社会主义新天地 提交于 2020-06-25 09:51:14
问题 I am testing TestContainers and I would like to know how to populate a database executing a .sql file to create the structure and add some rows. How to do it? @Rule public PostgreSQLContainer postgres = new PostgreSQLContainer(); Many thanks in advance Juan Antonio 回答1: When using Spring Boot, I find it easiest to use the JDBC URL support of TestContainers. You can create a application-integration-test.properties file (typically in src/test/resources with something like this: spring

Testcontainer issue with Bitbucket pipelines

三世轮回 提交于 2020-06-01 05:25:46
问题 I configured bitbucket-pipelines.yml and used image: gradle:6.3.0-jdk11 . My project built on Java11 and Gradle 6.3. Everything was Ok till starting test cases. Because I used Testontainers to test the application. Bitbucket could not start up the Testcontainer. The error is: org.testcontainers.containers.ContainerLaunchException: Container startup failed How can be fixed the issue? 回答1: If used Testcontainers inside the Bitbucket pipelines, There might be some issues. For instance, some

Using testcontainers in a Jenkins Docker Agent: containers fail to start, NoRouteToHostException

随声附和 提交于 2019-12-20 04:13:19
问题 I'm using a Jenkins declarative pipeline with Docker Agents to build and test my software, including running integration tests using testcontainers. I can run my testcontainers tests OK in my development environment (not using Jenkins), but they fail under Jenkins. The testcontainers Ryuk resource reaping daemon does not work 16:29:20.255 [testcontainers-ryuk] WARN o.t.utility.ResourceReaper - Can not connect to Ryuk at 172.17.0.1:32769 java.net.NoRouteToHostException: No route to host (Host

How fix mounting issue while using docker-compose.yml on test containers

落花浮王杯 提交于 2019-12-14 04:04:50
问题 I am using test containers to run some tests and using https://www.testcontainers.org/modules/docker_compose/ to spin some containers used for my tests. Similar to generic containers support, it's also possible to run a bespoke set of services specified in a docker-compose.yml file. This is intended to be useful on projects where Docker Compose is already used in dev or other environments to define services that an application may be dependent upon. Here is my code to include docker-compose

Can Testcontainers create docker network for me if it does not exist?

五迷三道 提交于 2019-12-12 13:37:06
问题 Looks like I need a network because I would like to reference one container by hostname from another. I could also use the --link but it is deprecated and can disappear soon. That's why I wonder if Testcontainers can create a docker network for me. With command line I would just execute docker network create bridge2 and then I can start containers like this: docker run -it --rm --net=bridge2 --name alpine1 alpine docker run -it --rm --net=bridge2 --name alpine2 alpine and resolve nslookup

Running a single test from a Suite with @ClassRule fails

放肆的年华 提交于 2019-12-11 17:03:32
问题 To create the environment just once and to avoid inheritance I have defined a JUnit Suite class with a @ClassRule : @RunWith(Suite.class) @Suite.SuiteClasses({ SuiteTest1.class }) public class JUnitTest { @ClassRule private static DockerComposeContainer env = ... @BeforeClass public static void init(){ ... } ... } And there's a Test class that uses env in a test method: public class SuiteTest1 { @Test public void method(){ client.query(...);// Executes a query against docker container } }

Reading a file from resources not working in gitlab CI

流过昼夜 提交于 2019-12-04 06:47:54
问题 I am getting an error while running tests on gitlab CI using the command: ./gradlew clean test I am using test containers to run my tests: https://www.testcontainers.org/modules/docker_compose/ Here is the code I am using to load the docker compose file which is at src/test/resources. @ClassRule public static DockerComposeContainer container = new DockerComposeContainer(new File(BaseServiceTest.class.getClassLoader().getResource("docker-compose.yml").getFile())); It runs fine when I run