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());
}
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")));
}
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);
}
}
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);
}
}
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);
}
Aggregations