org.testcontainers.containers.wait.strategy.ShellStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testcontainers Show documentation
Show all versions of testcontainers Show documentation
Isolated container management for Java code testing
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."
);
}
}
}