Skip to content

Instantly share code, notes, and snippets.

@MastaP
Created December 7, 2018 11:43
Show Gist options
  • Save MastaP/85a0c6ca8071d94dddf71d776e7d88ac to your computer and use it in GitHub Desktop.
Save MastaP/85a0c6ca8071d94dddf71d776e7d88ac to your computer and use it in GitHub Desktop.
A JUnit test which succeeds with TC 1.8.0 and hangs indefinitely on 1.9.0 and 1.10.2
import java.io.Closeable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.testcontainers.containers.GenericContainer;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.command.LogContainerResultCallback;
public class SleepingTest {
@Rule
public GenericContainer container = new GenericContainer("busybox") {
LogCallback logCallback;
@Override
protected void containerIsStarting(InspectContainerResponse containerInfo) {
super.containerIsStarting(containerInfo);
logCallback = getDockerClient().logContainerCmd(getContainerId())
.withStdOut(true)
.withStdErr(true)
.withTimestamps(true)
.withFollowStream(true)
.exec(new LogCallback());
}
@Override
protected void finished(Description description) {
if (logCallback != null) {
try {
logCallback.close();
}
catch (Exception ignored) {
}
}
super.finished(description);
}
class LogCallback extends LogContainerResultCallback {
final Logger logger = logger();
@Override
public void onStart(Closeable stream) {
super.onStart(stream);
logger.info("Log from {} (imageId: {})", getContainerName(), getDockerImageName());
}
@Override
public void onNext(Frame item) {
logger.info(new String(item.getPayload()).trim());
}
}
}.withCommand("sleep", "infinity");
@Test
public void test() throws Exception {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment