org.testcontainers.containers.wait.strategy.HttpWaitStrategy Java Examples

The following examples show how to use org.testcontainers.containers.wait.strategy.HttpWaitStrategy. 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: PulsarContainer.java    From eventeum with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    this.waitStrategy = new HttpWaitStrategy()
            .forPort(BROKER_HTTP_PORT)
            .forStatusCode(200)
            .forPath(METRICS_ENDPOINT)
            .withStartupTimeout(Duration.of(60, SECONDS));

    this.withCommand("/bin/bash", "-c", "/pulsar/bin/pulsar standalone");

    this.withCreateContainerCmdModifier(createContainerCmd -> {
        createContainerCmd.withHostName("standalone");
    });

    super.start();
    log.info("Pulsar Service Started");
}
 
Example #2
Source File: BesuNode.java    From teku with Apache License 2.0 6 votes vote down vote up
public BesuNode(final Network network) {
  super(network, "hyperledger/besu:1.3.6", LOG);
  container
      .withExposedPorts(JSON_RPC_PORT)
      .withLogConsumer(frame -> LOG.debug(frame.getUtf8String().trim()))
      .waitingFor(new HttpWaitStrategy().forPort(JSON_RPC_PORT).forPath("/liveness"))
      .withCopyFileToContainer(
          MountableFile.forClasspathResource("besu/depositContractGenesis.json"), "/genesis.json")
      .withCommand(
          "--rpc-http-enabled",
          "--rpc-http-port",
          Integer.toString(JSON_RPC_PORT),
          "--rpc-http-cors-origins=*",
          "--host-whitelist=*",
          "--miner-enabled",
          "--miner-coinbase",
          "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
          "--genesis-file",
          "/genesis.json");
}
 
Example #3
Source File: SyndesisServerContainer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public SyndesisServerContainer build() {
    SyndesisServerContainer container;
    if (ObjectHelper.isEmpty(serverJarPath)) {
        container = new SyndesisServerContainer(serverJarPath, getJavaOptionString(), deleteOnExit);
    } else {
        container = new SyndesisServerContainer(imageTag, getJavaOptionString());
    }

    if (enableLogging) {
        container.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("SERVER_CONTAINER")));
    }

    container.withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd.withName("syndesis-server"));

    if (enableDebug) {
        container.withExposedPorts(SERVER_PORT, JOLOKIA_PORT, SyndesisTestEnvironment.getDebugPort());
        container.withCreateContainerCmdModifier(cmd -> cmd.withPortBindings(new PortBinding(Ports.Binding.bindPort(SyndesisTestEnvironment.getDebugPort()), new ExposedPort(SyndesisTestEnvironment.getDebugPort()))));
    } else {
        container.withExposedPorts(SERVER_PORT, JOLOKIA_PORT);
    }

    container.waitingFor(new HttpWaitStrategy().forPort(SERVER_PORT)
                                               .withStartupTimeout(Duration.ofMinutes(3)));

    return container;
}
 
Example #4
Source File: PulsarContainer.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    if (httpPort > 0 && servicePort < 0) {
        this.waitStrategy = new HttpWaitStrategy()
            .forPort(httpPort)
            .forStatusCode(200)
            .forPath(httpPath)
            .withStartupTimeout(Duration.of(300, SECONDS));
    } else if (httpPort > 0 || servicePort > 0) {
        this.waitStrategy = new HostPortWaitStrategy()
            .withStartupTimeout(Duration.of(300, SECONDS));
    }
    this.withCreateContainerCmdModifier(createContainerCmd -> {
        createContainerCmd.withHostName(hostname);
        createContainerCmd.withName(getContainerName());
        createContainerCmd.withEntrypoint(serviceEntryPoint);
    });

    beforeStart();
    super.start();
    log.info("Start pulsar service {} at container {}", serviceName, containerName);
}
 
Example #5
Source File: OrientDBContainer.java    From testcontainers-java with MIT License 6 votes vote down vote up
public OrientDBContainer(@NonNull String dockerImageName) {
    super(dockerImageName);

    serverPassword = DEFAULT_SERVER_PASSWORD;
    databaseName = DEFAULT_DATABASE_NAME;

    WaitStrategy waitForHttp = new HttpWaitStrategy()
        .forPort(DEFAULT_HTTP_PORT)
        .forStatusCodeMatching(response -> response == HTTP_OK);

    waitStrategy = new WaitAllStrategy()
        .withStrategy(Wait.forListeningPort())
        .withStrategy(waitForHttp)
        .withStartupTimeout(Duration.ofMinutes(2));

    addExposedPorts(DEFAULT_BINARY_PORT, DEFAULT_HTTP_PORT);
}
 
Example #6
Source File: Neo4jContainer.java    From testcontainers-java with MIT License 6 votes vote down vote up
/**
 * Creates a Testcontainer using a specific docker image.
 *
 * @param dockerImageName The docker image to use.
 */
public Neo4jContainer(String dockerImageName) {
    super(dockerImageName);

    WaitStrategy waitForBolt = new LogMessageWaitStrategy()
        .withRegEx(String.format(".*Bolt enabled on 0\\.0\\.0\\.0:%d\\.\n", DEFAULT_BOLT_PORT));
    WaitStrategy waitForHttp = new HttpWaitStrategy()
        .forPort(DEFAULT_HTTP_PORT)
        .forStatusCodeMatching(response -> response == HTTP_OK);

    this.waitStrategy = new WaitAllStrategy()
        .withStrategy(waitForBolt)
        .withStrategy(waitForHttp)
        .withStartupTimeout(Duration.ofMinutes(2));

    addExposedPorts(DEFAULT_BOLT_PORT, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT);
}
 
Example #7
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 #8
Source File: PulsarContainer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public PulsarContainer(final String pulsarVersion) {
    super(pulsarVersion);
    withExposedPorts(BROKER_HTTP_PORT, PULSAR_PORT);
    withCommand("/pulsar/bin/pulsar standalone");
    waitingFor(new HttpWaitStrategy()
            .forPort(BROKER_HTTP_PORT)
            .forStatusCode(200)
            .forPath("/admin/v2/namespaces/public/default")
            .withStartupTimeout(Duration.of(300, SECONDS)));
}
 
Example #9
Source File: HttpWaitStrategyTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * Create a HttpWaitStrategy instance with a waitUntilReady implementation
 *
 * @param ready Indicates that the WaitStrategy has completed waiting successfully.
 * @return the HttpWaitStrategy instance
 */
private HttpWaitStrategy createHttpWaitStrategy(final AtomicBoolean ready) {
    return new HttpWaitStrategy() {
        @Override
        protected void waitUntilReady() {
            // blocks until ready or timeout occurs
            super.waitUntilReady();
            ready.set(true);
        }
    };
}
 
Example #10
Source File: CockroachContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
public CockroachContainer(final String dockerImageName) {
    super(dockerImageName);

    withExposedPorts(REST_API_PORT, DB_PORT);
    waitingFor(
        new HttpWaitStrategy()
            .forPath("/health")
            .forPort(REST_API_PORT)
            .forStatusCode(200)
            .withStartupTimeout(Duration.ofMinutes(1))
    );
    withCommand("start --insecure");
}
 
Example #11
Source File: ElasticsearchContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * Create an Elasticsearch Container by passing the full docker image name
 * @param dockerImageName Full docker image name, like: docker.elastic.co/elasticsearch/elasticsearch:6.4.1
 */
public ElasticsearchContainer(String dockerImageName) {
    super(dockerImageName);
    logger().info("Starting an elasticsearch container using [{}]", dockerImageName);
    withNetworkAliases("elasticsearch-" + Base58.randomString(6));
    withEnv("discovery.type", "single-node");
    addExposedPorts(ELASTICSEARCH_DEFAULT_PORT, ELASTICSEARCH_DEFAULT_TCP_PORT);
    setWaitStrategy(new HttpWaitStrategy()
        .forPort(ELASTICSEARCH_DEFAULT_PORT)
        .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
        .withStartupTimeout(Duration.ofMinutes(2)));
}
 
Example #12
Source File: CouchbaseContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * Before we can start configuring the host, we need to wait until the cluster manager is listening.
 */
private void waitUntilNodeIsOnline() {
    new HttpWaitStrategy()
        .forPort(MGMT_PORT)
        .forPath("/pools")
        .forStatusCode(200)
        .waitUntilReady(this);
}
 
Example #13
Source File: CouchbaseContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
protected void configure() {
    super.configure();

    WaitAllStrategy waitStrategy = new WaitAllStrategy();

    // Makes sure that all nodes in the cluster are healthy.
    waitStrategy = waitStrategy.withStrategy(
        new HttpWaitStrategy()
            .forPath("/pools/default")
            .forPort(MGMT_PORT)
            .withBasicCredentials(username, password)
            .forStatusCode(200)
            .forResponsePredicate(response -> {
                try {
                    return Optional.of(MAPPER.readTree(response))
                        .map(n -> n.at("/nodes/0/status"))
                        .map(JsonNode::asText)
                        .map("healthy"::equals)
                        .orElse(false);
                } catch (IOException e) {
                    logger().error("Unable to parse response {}", response);
                    return false;
                }
            })
    );

    if (enabledServices.contains(CouchbaseService.QUERY)) {
        waitStrategy = waitStrategy.withStrategy(
            new HttpWaitStrategy()
                .forPath("/admin/ping")
                .forPort(QUERY_PORT)
                .withBasicCredentials(username, password)
                .forStatusCode(200)
        );
    }

    waitingFor(waitStrategy);
}
 
Example #14
Source File: ToxiproxyContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
public ToxiproxyContainer(String imageName) {
    super(imageName);
    addExposedPorts(TOXIPROXY_CONTROL_PORT);
    setWaitStrategy(new HttpWaitStrategy().forPath("/version").forPort(TOXIPROXY_CONTROL_PORT));

    // allow up to 32 ports to be proxied (arbitrary value). Here we make the ports exposed; whether or not
    //  Toxiproxy will listen is controlled at runtime using getProxy(...)
    for (int i = FIRST_PROXIED_PORT; i <= LAST_PROXIED_PORT; i++) {
        addExposedPort(i);
    }
}
 
Example #15
Source File: ClickHouseContainer.java    From testcontainers-java with MIT License 5 votes vote down vote up
public ClickHouseContainer(String dockerImageName) {
    super(dockerImageName);

    withExposedPorts(HTTP_PORT, NATIVE_PORT);
    waitingFor(
        new HttpWaitStrategy()
            .forStatusCode(200)
            .forResponsePredicate(responseBody -> "Ok.".equals(responseBody))
            .withStartupTimeout(Duration.ofMinutes(1))
    );
}
 
Example #16
Source File: PulsarContainer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public PulsarContainer(final String pulsarVersion) {
    super(pulsarVersion);
    withExposedPorts(BROKER_HTTP_PORT, PULSAR_PORT);
    withCommand("/pulsar/bin/pulsar standalone");
    waitingFor(new HttpWaitStrategy()
            .forPort(BROKER_HTTP_PORT)
            .forStatusCode(200)
            .forPath("/admin/v2/namespaces/public/default")
            .withStartupTimeout(Duration.of(300, SECONDS)));
}
 
Example #17
Source File: StandaloneContainer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
protected void beforeStart() {
    // update the wait strategy until public/default namespace is created
    this.waitStrategy = new HttpWaitStrategy()
            .forPort(BROKER_HTTP_PORT)
            .forStatusCode(200)
            .forPath("/admin/v2/namespaces/public/default")
            .withStartupTimeout(Duration.of(300, SECONDS));
}
 
Example #18
Source File: JaegerExporterHandlerIntegrationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Starts a docker container optionally. For example, skips if Docker is unavailable. */
@SuppressWarnings("rawtypes")
@BeforeClass
public static void startContainer() {
  try {
    container =
        new GenericContainer(JAEGER_IMAGE)
            .withExposedPorts(JAEGER_HTTP_PORT, JAEGER_HTTP_PORT_THRIFT)
            .waitingFor(new HttpWaitStrategy());
    container.start();
  } catch (RuntimeException e) {
    throw new AssumptionViolatedException("could not start docker container", e);
  }
}
 
Example #19
Source File: ElasticsearchWithPluginContainer.java    From elasticsearch-analysis-morfologik with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    logger().info("Starting an elasticsearch container using [{}]", dockerImage);
    withNetworkAliases("elasticsearch-" + Base58.randomString(6));
    withEnv("discovery.type", "single-node");
    addExposedPorts(ELASTICSEARCH_DEFAULT_PORT, ELASTICSEARCH_DEFAULT_TCP_PORT);
    setWaitStrategy(new HttpWaitStrategy()
            .forPort(ELASTICSEARCH_DEFAULT_PORT)
            .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
            .withStartupTimeout(Duration.ofMinutes(2)));
    setImage(prepareImage(dockerImage));
}
 
Example #20
Source File: TekuNode.java    From teku with Apache License 2.0 5 votes vote down vote up
private TekuNode(final SimpleHttpClient httpClient, final Network network, final Config config) {
  super(network, TEKU_DOCKER_IMAGE, LOG);
  this.httpClient = httpClient;
  this.config = config;

  container
      .withWorkingDirectory(WORKING_DIRECTORY)
      .withExposedPorts(REST_API_PORT)
      .waitingFor(
          new HttpWaitStrategy()
              .forPort(REST_API_PORT)
              .forPath("/network/peer_id")
              .withStartupTimeout(Duration.ofMinutes(2)))
      .withCommand("--config-file", CONFIG_FILE_PATH);
}
 
Example #21
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;
}
 
Example #22
Source File: S3TestHelper.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
public static GenericContainer<?> createTestContainer(final int testPort) {
    return new GenericContainer<>("localstack/localstack:latest")
            .withEnv("DEBUG", "1")
            .waitingFor(new HttpWaitStrategy().forStatusCode(200).forPort(testPort));
}
 
Example #23
Source File: EmbeddedPrometheusBootstrapConfiguration.java    From kayenta with Apache License 2.0 4 votes vote down vote up
@Bean(name = "prometheusWaitStrategy")
public WaitStrategy prometheusWaitStrategy() {
  return new HttpWaitStrategy().forPath("/status").forPort(PORT).forStatusCode(200);
}
 
Example #24
Source File: HttpWaitStrategyTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
/**
 * @param ready the AtomicBoolean on which to indicate success
 * @return the WaitStrategy under test
 */
@NotNull
protected HttpWaitStrategy buildWaitStrategy(final AtomicBoolean ready) {
    return createHttpWaitStrategy(ready)
        .forResponsePredicate(s -> s.equals(GOOD_RESPONSE_BODY));
}