All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testcontainers.containers.wait.strategy.ShellStrategy Maven / Gradle / Ivy

There is a newer version: 1.20.3
Show newest version
package org.testcontainers.containers.wait.strategy;

import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.ContainerLaunchException;

import java.util.concurrent.TimeUnit;

public class ShellStrategy extends AbstractWaitStrategy {

    private String command;

    public ShellStrategy withCommand(String command) {
        this.command = command;
        return this;
    }

    @Override
    protected void waitUntilReady() {
        try {
            Unreliables.retryUntilTrue(
                (int) startupTimeout.getSeconds(),
                TimeUnit.SECONDS,
                () -> waitStrategyTarget.execInContainer("/bin/sh", "-c", this.command).getExitCode() == 0
            );
        } catch (TimeoutException e) {
            throw new ContainerLaunchException(
                "Timed out waiting for container to execute `" + this.command + "` successfully."
            );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy