Search in sources :

Example 1 with WaitingConsumer

use of org.testcontainers.containers.output.WaitingConsumer in project testcontainers-java by testcontainers.

the class OutputStreamTest method testFetchStdout.

@Test
public void testFetchStdout() throws TimeoutException {
    WaitingConsumer consumer = new WaitingConsumer();
    container.followOutput(consumer, STDOUT);
    consumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("seq=2"), 30, TimeUnit.SECONDS);
}
Also used : WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) Test(org.junit.Test)

Example 2 with WaitingConsumer

use of org.testcontainers.containers.output.WaitingConsumer in project testcontainers-java by testcontainers.

the class OutputStreamTest method testFetchStdoutWithTimeout.

@Test
public void testFetchStdoutWithTimeout() throws TimeoutException {
    WaitingConsumer consumer = new WaitingConsumer();
    container.followOutput(consumer, STDOUT);
    assertThrows("a TimeoutException should be thrown", TimeoutException.class, () -> {
        consumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("seq=5"), 2, TimeUnit.SECONDS);
        return true;
    });
}
Also used : WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) Test(org.junit.Test)

Example 3 with WaitingConsumer

use of org.testcontainers.containers.output.WaitingConsumer in project testcontainers-java by testcontainers.

the class OutputStreamTest method testFetchStdoutWithNoLimit.

@Test
public void testFetchStdoutWithNoLimit() throws TimeoutException {
    WaitingConsumer consumer = new WaitingConsumer();
    container.followOutput(consumer, STDOUT);
    consumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("seq=2"));
}
Also used : WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) Test(org.junit.Test)

Example 4 with WaitingConsumer

use of org.testcontainers.containers.output.WaitingConsumer in project testcontainers-java by testcontainers.

the class DirectoryTarResourceTest method simpleRecursiveFileTest.

@Test
public void simpleRecursiveFileTest() throws TimeoutException {
    WaitingConsumer wait = new WaitingConsumer();
    final ToStringConsumer toString = new ToStringConsumer();
    GenericContainer container = new GenericContainer(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder.from("alpine:3.3").copy("/tmp/foo", "/foo").cmd("cat /foo/src/test/resources/test-recursive-file.txt").build()).withFileFromFile("/tmp/foo", // '.' is expected to be the project base directory, so all source code/resources should be copied in
    new File("."))).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(wait.andThen(toString));
    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);
    final String results = toString.toUtf8String();
    assertTrue("The container has a file that was copied in via a recursive copy", results.contains("Used for DirectoryTarResourceTest"));
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) ToStringConsumer(org.testcontainers.containers.output.ToStringConsumer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GenericContainer(org.testcontainers.containers.GenericContainer) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) File(java.io.File) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Example 5 with WaitingConsumer

use of org.testcontainers.containers.output.WaitingConsumer in project testcontainers-java by testcontainers.

the class DirectoryTarResourceTest method simpleRecursiveFileWithPermissionTest.

@Test
public void simpleRecursiveFileWithPermissionTest() throws TimeoutException {
    WaitingConsumer wait = new WaitingConsumer();
    final ToStringConsumer toString = new ToStringConsumer();
    GenericContainer container = new GenericContainer(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder.from("alpine:3.3").copy("/tmp/foo", "/foo").cmd("ls", "-al", "/").build()).withFileFromFile("/tmp/foo", new File("/mappable-resource/test-resource.txt"), 0754)).withStartupCheckStrategy(new OneShotStartupCheckStrategy()).withLogConsumer(wait.andThen(toString));
    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);
    String listing = toString.toUtf8String();
    assertThat("Listing shows that file is copied with mode requested.", Arrays.asList(listing.split("\\n")), exactlyNItems(1, allOf(containsString("-rwxr-xr--"), containsString("foo"))));
}
Also used : ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) ToStringConsumer(org.testcontainers.containers.output.ToStringConsumer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GenericContainer(org.testcontainers.containers.GenericContainer) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) File(java.io.File) OneShotStartupCheckStrategy(org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy) Test(org.junit.Test)

Aggregations

WaitingConsumer (org.testcontainers.containers.output.WaitingConsumer)11 Test (org.junit.Test)9 ToStringConsumer (org.testcontainers.containers.output.ToStringConsumer)5 GenericContainer (org.testcontainers.containers.GenericContainer)4 OutputFrame (org.testcontainers.containers.output.OutputFrame)4 OneShotStartupCheckStrategy (org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy)4 ImageFromDockerfile (org.testcontainers.images.builder.ImageFromDockerfile)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 File (java.io.File)2 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Predicate (java.util.function.Predicate)1 DockerClientFactory (org.testcontainers.DockerClientFactory)1 ContainerLaunchException (org.testcontainers.containers.ContainerLaunchException)1 Slf4jLogConsumer (org.testcontainers.containers.output.Slf4jLogConsumer)1 Transferable (org.testcontainers.images.builder.Transferable)1 LogUtils (org.testcontainers.utility.LogUtils)1