Search in sources :

Example 11 with WaitingConsumer

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

the class LogMessageWaitStrategy method waitUntilReady.

@Override
protected void waitUntilReady() {
    WaitingConsumer waitingConsumer = new WaitingConsumer();
    LogUtils.followOutput(DockerClientFactory.instance().client(), waitStrategyTarget.getContainerId(), waitingConsumer);
    Predicate<OutputFrame> waitPredicate = outputFrame -> outputFrame.getUtf8String().matches(regEx);
    try {
        waitingConsumer.waitUntil(waitPredicate, startupTimeout.getSeconds(), TimeUnit.SECONDS, times);
    } catch (TimeoutException e) {
        throw new ContainerLaunchException("Timed out waiting for log output matching '" + regEx + "'");
    }
}
Also used : ContainerLaunchException(org.testcontainers.containers.ContainerLaunchException) TimeUnit(java.util.concurrent.TimeUnit) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) Predicate(java.util.function.Predicate) LogUtils(org.testcontainers.utility.LogUtils) TimeoutException(java.util.concurrent.TimeoutException) DockerClientFactory(org.testcontainers.DockerClientFactory) OutputFrame(org.testcontainers.containers.output.OutputFrame) ContainerLaunchException(org.testcontainers.containers.ContainerLaunchException) OutputFrame(org.testcontainers.containers.output.OutputFrame) WaitingConsumer(org.testcontainers.containers.output.WaitingConsumer) TimeoutException(java.util.concurrent.TimeoutException)

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