use of org.testcontainers.containers.output.OutputFrame in project testcontainers-java by testcontainers.
the class DockerNetworkModeTest method getContainerOutput.
private String getContainerOutput(GenericContainer container) throws TimeoutException {
WaitingConsumer waitingConsumer = new WaitingConsumer();
ToStringConsumer toStringConsumer = new ToStringConsumer();
Consumer<OutputFrame> composedConsumer = waitingConsumer.andThen(toStringConsumer);
container.followOutput(composedConsumer);
waitingConsumer.waitUntilEnd(10, TimeUnit.SECONDS);
return toStringConsumer.toUtf8String();
}
use of org.testcontainers.containers.output.OutputFrame in project testcontainers-java by testcontainers.
the class OutputStreamTest method testToStringConsumer.
@Test
public void testToStringConsumer() throws TimeoutException {
WaitingConsumer waitingConsumer = new WaitingConsumer();
ToStringConsumer toStringConsumer = new ToStringConsumer();
Consumer<OutputFrame> composedConsumer = toStringConsumer.andThen(waitingConsumer);
container.followOutput(composedConsumer);
waitingConsumer.waitUntilEnd(30, TimeUnit.SECONDS);
String utf8String = toStringConsumer.toUtf8String();
assertTrue("the expected first value was found", utf8String.contains("seq=1"));
assertTrue("the expected last value was found", utf8String.contains("seq=4"));
assertFalse("a non-expected value was found", utf8String.contains("seq=42"));
}
use of org.testcontainers.containers.output.OutputFrame in project testcontainers-java by testcontainers.
the class OutputStreamTest method testLogConsumer.
@Test
public void testLogConsumer() throws TimeoutException {
WaitingConsumer waitingConsumer = new WaitingConsumer();
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER);
Consumer<OutputFrame> composedConsumer = logConsumer.andThen(waitingConsumer);
container.followOutput(composedConsumer);
waitingConsumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("seq=2"));
}
use of org.testcontainers.containers.output.OutputFrame in project testcontainers-java by testcontainers.
the class LogUtils method followOutput.
/**
* {@inheritDoc}
*/
public void followOutput(DockerClient dockerClient, String containerId, Consumer<OutputFrame> consumer, OutputFrame.OutputType... types) {
final LogContainerCmd cmd = dockerClient.logContainerCmd(containerId).withFollowStream(true).withSince(0);
final FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
for (OutputFrame.OutputType type : types) {
callback.addConsumer(type, consumer);
if (type == STDOUT)
cmd.withStdOut(true);
if (type == STDERR)
cmd.withStdErr(true);
}
cmd.exec(callback);
}
use of org.testcontainers.containers.output.OutputFrame 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 + "'");
}
}
Aggregations