Java Code Examples for org.testcontainers.containers.wait.strategy.HttpWaitStrategy#forPort()

The following examples show how to use org.testcontainers.containers.wait.strategy.HttpWaitStrategy#forPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationContainer.java    From microshed-testing with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    super.configure();
    if (getExposedPorts().size() == 0) {
        addExposedPort(serverAdapter.getDefaultHttpPort());
    }
    // If the readiness path was not set explicitly, default it to:
    // A) The value defined by ServerAdapter.getReadinessPath(), if any
    // B) the app context root
    if (!waitStrategySet) {
        if (serverAdapter != null && serverAdapter.getReadinessPath().isPresent()) {
            withReadinessPath(serverAdapter.getReadinessPath().get());
        } else {
            withReadinessPath(appContextRoot);
        }
    }
    if (readinessPathSet &&
        primaryPort != null &&
        waitStrategy instanceof HttpWaitStrategy) {
        HttpWaitStrategy wait = (HttpWaitStrategy) waitStrategy;
        wait.forPort(primaryPort);
    }
}
 
Example 2
Source File: ApplicationContainer.java    From microshed-testing with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the path to be used to determine container readiness. The readiness check will
 * timeout after a sensible amount of time has elapsed.
 * If unspecified, the readiness path with defailt to the application context root
 *
 * @param readinessUrl The HTTP endpoint to be polled for readiness. Once the endpoint
 *            returns HTTP 200 (OK), the container is considered to be ready.
 * @param timeoutSeconds The amount of time (in seconds) to wait for the container to be ready.
 * @param port The port that should be used for the readiness check.
 * @return the current instance
 */
public ApplicationContainer withReadinessPath(String readinessUrl,
                                              int timeoutSeconds,
                                              Integer port) {
    readinessPathSet = true;
    Objects.requireNonNull(readinessUrl);
    readinessUrl = buildPath(readinessUrl);
    HttpWaitStrategy strat = Wait.forHttp(readinessUrl);
    if (port != null) {
        strat.forPort(port);
    }
    strat.withStartupTimeout(Duration.ofSeconds(timeoutSeconds));
    waitingFor(strat);
    return this;
}