Search in sources :

Example 1 with GenericContainer

use of org.testcontainers.containers.GenericContainer in project zipkin by openzipkin.

the class LazyElasticsearchHttpStorage method compute.

@Override
protected ElasticsearchHttpStorage compute() {
    try {
        container = new GenericContainer(image).withExposedPorts(9200).waitingFor(new HttpWaitStrategy().forPath("/"));
        container.start();
        System.out.println("Will use TestContainers Elasticsearch instance");
    } catch (Exception e) {
    // Ignore
    }
    ElasticsearchHttpStorage result = computeStorageBuilder().build();
    Component.CheckResult check = result.check();
    if (check.ok) {
        return result;
    } else {
        throw new AssumptionViolatedException(check.exception.getMessage(), check.exception);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) HttpWaitStrategy(org.testcontainers.containers.wait.HttpWaitStrategy) ElasticsearchHttpStorage(zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage) GenericContainer(org.testcontainers.containers.GenericContainer) Component(zipkin.Component) AssumptionViolatedException(org.junit.AssumptionViolatedException)

Example 2 with GenericContainer

use of org.testcontainers.containers.GenericContainer in project zipkin by openzipkin.

the class LazyElasticsearchTransportStorage method compute.

@Override
protected ElasticsearchStorage compute() {
    try {
        container = new GenericContainer(image).withExposedPorts(9200, 9300).waitingFor(new HttpWaitStrategy().forPath("/"));
        container.start();
        System.out.println("Will use TestContainers Elasticsearch instance");
    } catch (Exception e) {
    // Ignore
    }
    ElasticsearchStorage result = computeStorageBuilder().build();
    Component.CheckResult check = result.check();
    if (check.ok) {
        return result;
    } else {
        throw new AssumptionViolatedException(check.exception.getMessage(), check.exception);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) HttpWaitStrategy(org.testcontainers.containers.wait.HttpWaitStrategy) GenericContainer(org.testcontainers.containers.GenericContainer) Component(zipkin.Component) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException)

Example 3 with GenericContainer

use of org.testcontainers.containers.GenericContainer in project zipkin by openzipkin.

the class LazyElasticsearchHttpStorage method compute.

@Override
protected ElasticsearchStorage compute() {
    try {
        container = new GenericContainer(image).withExposedPorts(9200).waitingFor(new HttpWaitStrategy().forPath("/"));
        container.start();
        System.out.println("Will use TestContainers Elasticsearch instance");
    } catch (Exception e) {
    // Ignore
    }
    ElasticsearchStorage result = computeStorageBuilder().build();
    Component.CheckResult check = result.check();
    if (check.ok) {
        return result;
    } else {
        throw new AssumptionViolatedException(check.exception.getMessage(), check.exception);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) HttpWaitStrategy(org.testcontainers.containers.wait.HttpWaitStrategy) GenericContainer(org.testcontainers.containers.GenericContainer) Component(zipkin.Component) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException)

Example 4 with GenericContainer

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

the class DockerfileTest method verifyImage.

protected void verifyImage(ImageFromDockerfile image) {
    GenericContainer container = new GenericContainer(image);
    try {
        container.start();
        pass("Should start from Dockerfile");
    } finally {
        container.stop();
    }
}
Also used : GenericContainer(org.testcontainers.containers.GenericContainer)

Example 5 with GenericContainer

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

the class GenericContainerRuleTest method createContainerCmdHookTest.

@Test
public void createContainerCmdHookTest() {
    // Use random name to avoid the conflicts between the tests
    String randomName = Base58.randomString(5);
    try (GenericContainer container = new GenericContainer<>("redis:3.0.2").withCommand("redis-server", "--help").withCreateContainerCmdModifier(cmd -> cmd.withName("overrideMe")).withCreateContainerCmdModifier(cmd -> cmd.withName(randomName)).withCreateContainerCmdModifier(cmd -> cmd.withCmd("redis-server", "--port", "6379"))) {
        container.start();
        assertEquals("Name is configured", "/" + randomName, container.getContainerInfo().getName());
        assertEquals("Command is configured", "[redis-server, --port, 6379]", Arrays.toString(container.getContainerInfo().getConfig().getCmd()));
    }
}
Also used : Document(org.bson.Document) Socket(java.net.Socket) Arrays(java.util.Arrays) MongoCollection(com.mongodb.client.MongoCollection) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TimeoutException(java.util.concurrent.TimeoutException) MongoDatabase(com.mongodb.client.MongoDatabase) Matcher(java.util.regex.Matcher) Files(com.google.common.io.Files) Duration(java.time.Duration) VisibleAssertions(org.rnorth.visibleassertions.VisibleAssertions) GenericContainer(org.testcontainers.containers.GenericContainer) TestEnvironment(org.testcontainers.utility.TestEnvironment) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) ImmutableMap(com.google.common.collect.ImmutableMap) com.rabbitmq.client(com.rabbitmq.client) FileUtils(org.apache.commons.io.FileUtils) TimeUnit(java.util.concurrent.TimeUnit) Unreliables(org.rnorth.ducttape.unreliables.Unreliables) SHARED(org.testcontainers.containers.SelinuxContext.SHARED) READ_WRITE(org.testcontainers.containers.BindMode.READ_WRITE) java.io(java.io) MongoClient(com.mongodb.MongoClient) MountableFile(org.testcontainers.utility.MountableFile) org.junit(org.junit) Pattern(java.util.regex.Pattern) Base58(org.testcontainers.utility.Base58) RetryCountExceededException(org.rnorth.ducttape.RetryCountExceededException) READ_ONLY(org.testcontainers.containers.BindMode.READ_ONLY) GenericContainer(org.testcontainers.containers.GenericContainer)

Aggregations

GenericContainer (org.testcontainers.containers.GenericContainer)29 IOException (java.io.IOException)6 ImageFromDockerfile (org.testcontainers.images.builder.ImageFromDockerfile)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Arrays (java.util.Arrays)4 AssumptionViolatedException (org.junit.AssumptionViolatedException)4 Test (org.junit.jupiter.api.Test)4 WaitingConsumer (org.testcontainers.containers.output.WaitingConsumer)4 OneShotStartupCheckStrategy (org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy)4 Path (java.nio.file.Path)3 List (java.util.List)3 BuildResult (org.gradle.testkit.runner.BuildResult)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)3 HttpWaitStrategy (org.testcontainers.containers.wait.HttpWaitStrategy)3 MountableFile (org.testcontainers.utility.MountableFile)3 Component (zipkin.Component)3