Search in sources :

Example 1 with InternalCommandPortListeningCheck

use of org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck in project testcontainers-java by testcontainers.

the class HostPortWaitStrategy method waitUntilReady.

@Override
protected void waitUntilReady() {
    final Set<Integer> externalLivenessCheckPorts = getLivenessCheckPorts();
    if (externalLivenessCheckPorts.isEmpty()) {
        log.debug("Liveness check ports of {} is empty. Not waiting.", waitStrategyTarget.getContainerInfo().getName());
        return;
    }
    @SuppressWarnings("unchecked") List<Integer> exposedPorts = waitStrategyTarget.getExposedPorts();
    final Set<Integer> internalPorts = getInternalPorts(externalLivenessCheckPorts, exposedPorts);
    Callable<Boolean> internalCheck = new InternalCommandPortListeningCheck(waitStrategyTarget, internalPorts);
    Callable<Boolean> externalCheck = new ExternalPortListeningCheck(waitStrategyTarget, externalLivenessCheckPorts);
    try {
        Unreliables.retryUntilTrue((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> getRateLimiter().getWhenReady(() -> internalCheck.call() && externalCheck.call()));
    } catch (TimeoutException e) {
        throw new ContainerLaunchException("Timed out waiting for container port to open (" + waitStrategyTarget.getContainerIpAddress() + " ports: " + externalLivenessCheckPorts + " should be listening)");
    }
}
Also used : ExternalPortListeningCheck(org.testcontainers.containers.wait.internal.ExternalPortListeningCheck) ContainerLaunchException(org.testcontainers.containers.ContainerLaunchException) InternalCommandPortListeningCheck(org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck) TimeoutException(org.rnorth.ducttape.TimeoutException)

Aggregations

TimeoutException (org.rnorth.ducttape.TimeoutException)1 ContainerLaunchException (org.testcontainers.containers.ContainerLaunchException)1 ExternalPortListeningCheck (org.testcontainers.containers.wait.internal.ExternalPortListeningCheck)1 InternalCommandPortListeningCheck (org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck)1