Search in sources :

Example 1 with DockerComposeContainer

use of org.testcontainers.containers.DockerComposeContainer in project integration-test-demo by xeraa.

the class TestcontainersGeneralTest method startElasticsearchRestClient.

@BeforeClass
public static void startElasticsearchRestClient() throws IOException {
    final int TEST_CLUSTER_PORT = 9200;
    final String TEST_CLUSTER_HOST = "localhost";
    final String TEST_CLUSTER_SCHEME = "http";
    // Get the Elasticsearch version from the POM
    Properties properties = new Properties();
    properties.load(TestcontainersGeneralTest.class.getClassLoader().getResourceAsStream("elasticsearch.configuration.properties"));
    String elasticsearchVersion = properties.getProperty("version");
    // Start the Elasticsearch process
    logger.info("Start Elasticsearch with Docker Compose");
    container = new DockerComposeContainer(new File("src/test/resources/docker-compose.yml")).withEnv("ELASTIC_VERSION", elasticsearchVersion).withExposedService("elasticsearch_1", TEST_CLUSTER_PORT, Wait.forHttp("/").forStatusCode(200).withStartupTimeout(Duration.ofSeconds(90)));
    container.start();
    logger.info("Docker Compose instance started");
    // Start a client
    logger.info("Starting a client on {}://{}:{}", TEST_CLUSTER_SCHEME, TEST_CLUSTER_HOST, TEST_CLUSTER_PORT);
    RestClientBuilder builder = getClientBuilder(new HttpHost(TEST_CLUSTER_HOST, TEST_CLUSTER_PORT, TEST_CLUSTER_SCHEME));
    client = new RestHighLevelClient(builder);
    MainResponse info = client.info(RequestOptions.DEFAULT.toBuilder().build());
    logger.info("Client is running against an Elasticsearch cluster {}", info.getVersion().toString());
}
Also used : MainResponse(org.elasticsearch.client.core.MainResponse) DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Properties(java.util.Properties) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 2 with DockerComposeContainer

use of org.testcontainers.containers.DockerComposeContainer in project testcontainers-java by testcontainers.

the class DockerComposeWaitStrategyTest method testWaitingFails.

@Test
public void testWaitingFails() {
    final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml")).withExposedService("redis_1", REDIS_PORT, Wait.forHttp("/test").withStartupTimeout(Duration.ofSeconds(10)));
    VisibleAssertions.assertThrows("waiting on an invalid http path times out", RuntimeException.class, () -> environment.starting(Description.createTestDescription(Object.class, "name")));
}
Also used : DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) File(java.io.File) Test(org.junit.Test)

Example 3 with DockerComposeContainer

use of org.testcontainers.containers.DockerComposeContainer in project testcontainers-java by testcontainers.

the class DockerComposeWaitStrategyTest method testWaitOnListeningPort.

@Test
public void testWaitOnListeningPort() {
    final DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/compose-test.yml")).withExposedService("redis_1", REDIS_PORT, Wait.forListeningPort());
    try {
        environment.starting(Description.createTestDescription(Object.class, "name"));
        VisibleAssertions.pass("Docker compose should start after waiting for listening port");
    } catch (RuntimeException e) {
        VisibleAssertions.fail("Docker compose should start after waiting for listening port with failed with: " + e);
    }
}
Also used : DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) File(java.io.File) Test(org.junit.Test)

Example 4 with DockerComposeContainer

use of org.testcontainers.containers.DockerComposeContainer in project testcontainers-java by testcontainers.

the class DockerComposeLogConsumerTest method testLogConsumer.

@Test
public void testLogConsumer() throws TimeoutException {
    WaitingConsumer logConsumer = new WaitingConsumer();
    DockerComposeContainer environment = new DockerComposeContainer(new File("src/test/resources/v2-compose-test.yml")).withExposedService("redis_1", 6379).withLogConsumer("redis_1", logConsumer);
    try {
        environment.starting(Description.EMPTY);
        logConsumer.waitUntil(frame -> {
            return (frame.getType() == OutputType.STDOUT && frame.getUtf8String().contains("Ready to accept connections"));
        }, 5, TimeUnit.SECONDS);
    } finally {
        environment.finished(Description.EMPTY);
    }
}
Also used : DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) File(java.io.File) Test(org.junit.Test)

Example 5 with DockerComposeContainer

use of org.testcontainers.containers.DockerComposeContainer in project testcontainers-java by testcontainers.

the class DockerComposeContainerTest method shouldCreateContainerWhenFileNotPrefixedWithPath.

@Test
public void shouldCreateContainerWhenFileNotPrefixedWithPath() throws IOException {
    String validYaml = "version: '2.2'\n" + "services:\n" + "  http:\n" + "    build: .\n" + "    image: python:latest\n" + "    ports:\n" + "    - 8080:8080";
    File filePathNotStartWithDotSlash = new File("docker-compose-test.yml");
    filePathNotStartWithDotSlash.createNewFile();
    filePathNotStartWithDotSlash.deleteOnExit();
    Files.write(filePathNotStartWithDotSlash.toPath(), validYaml.getBytes(StandardCharsets.UTF_8));
    final DockerComposeContainer<?> dockerComposeContainer = new DockerComposeContainer<>(filePathNotStartWithDotSlash);
    assertNotNull("Container could not be created using docker compose file", dockerComposeContainer);
}
Also used : DockerComposeContainer(org.testcontainers.containers.DockerComposeContainer) File(java.io.File) Test(org.junit.Test)

Aggregations

DockerComposeContainer (org.testcontainers.containers.DockerComposeContainer)21 File (java.io.File)20 Test (org.junit.Test)10 BeforeAll (org.junit.jupiter.api.BeforeAll)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Slf4jLogConsumer (org.testcontainers.containers.output.Slf4jLogConsumer)2 ResultCallback (com.github.dockerjava.api.async.ResultCallback)1 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)1 ListContainersCmd (com.github.dockerjava.api.command.ListContainersCmd)1 DockerException (com.github.dockerjava.api.exception.DockerException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)1 ExposedPort (com.github.dockerjava.api.model.ExposedPort)1 PullResponseItem (com.github.dockerjava.api.model.PullResponseItem)1 ResponseItem (com.github.dockerjava.api.model.ResponseItem)1 TigerGlobalConfiguration (de.gematik.test.tiger.common.config.TigerGlobalConfiguration)1 TigerSerializationUtil (de.gematik.test.tiger.common.util.TigerSerializationUtil)1