Description
Im using the following function to be able to block surefire tests until the docker container is started.
This works almost always but some of the time im getting the exception shown below. Im unsure under what situations next would fail for a LogStream or if there is an issue with how dockerClient.logs gets the log stream.
My questions are:
How are others using the docker client to wait for logs?
What would cause the exceptions im seeing?
public void waitForLog(String messageToMatch) throws Exception {
logger.info("Waiting for toc.log to signal start of service with log message: " + messageToMatch);
LogStream logs = dockerClient.logs(container.id(), follow(), stdout());
String log;
do {
LogMessage logMessage = logs.next();
ByteBuffer buffer = logMessage.content();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
log = new String(bytes);
} while (!log.contains(messageToMatch));
}
How to reproduce
Im still not sure how to reproduce since it only happens rarely on my local machine but always on our Jenkins servers.
What do you expect
No exeption thrown, we will read the logs.
What happened instead
Exception is thrown.
Software:
Docker version:
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:01:32 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.0-ce
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:01:32 2017
OS/Arch: linux/amd64
Experimental: false
Spotify's docker-client version: 7.0.2
Full backtrace
Caused by: java.util.NoSuchElementException: null
at com.google.common.collect.AbstractIterator.next(AbstractIterator.java:154)
at com.support.test.core.docker.DockerProxy.waitForLog(DockerProxy.java:175)
at com.support.test.core.runner.TestListener.testRunStarted(TestListener.java:54)
at org.junit.runner.notification.SynchronizedRunListener.testRunStarted(SynchronizedRunListener.java:35)
at org.junit.runner.notification.RunNotifier$1.notifyListener(RunNotifier.java:91)
at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
at org.junit.runner.notification.RunNotifier.fireTestRunStarted(RunNotifier.java:88)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:120)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)