0

I am using Testcontainers DockerComposeContainer and sending shell commands using the execInContainer method once my containers are up and running:

@ClassRule
public static DockerComposeContainer<?> environment = 
    new DockerComposeContainer<>(new File("docker-compose.yml"))
        .withExposedService(DB_1, DB_PORT)
        .waitingFor(SERVICE_1, Wait.defaultWaitStrategy())
        .withLocalCompose(true);

One of the commands is to simply move a file which will then be processed and I want to wait until the process inside the container processes it before checking the results in my test.

service.execInContainer("cp", "my-file.zip", "/home/user/dir");

The way I'm checking to see if the process has consumed the my-file.zip, once it has been moved, is to inspect the logs:

String log = "";
while (!log.contains("Moving my-file.zip file to /home/user/dir")) {
    ExecResult cat = soar.execInContainer("cat", "/my-service/logs/service.log");
    log = cat.getStdout();
}

This works, but I don't like the constant polling very much inside the while loop and was wondering if there is a better way to achieve this.

I've been looking internally into testcontainers and it makes use of the java dockerapi so I wondered if there is a better way to do this via that API or if I could do the waiting using a library like Awaitility.

Thanks for any suggestions

user1472672
  • 313
  • 1
  • 9

0 Answers0