Search in sources :

Example 1 with WaitAllStrategy

use of org.testcontainers.containers.wait.strategy.WaitAllStrategy in project testcontainers-java by testcontainers.

the class LocalDockerCompose method addWaitStrategy.

/*
     * can have multiple wait strategies for a single container, e.g. if waiting on several ports
     * if no wait strategy is defined, the WaitAllStrategy will return immediately.
     * The WaitAllStrategy uses an long timeout, because timeouts should be handled by the inner strategies.
     */
private void addWaitStrategy(String serviceInstanceName, @NonNull WaitStrategy waitStrategy) {
    final WaitAllStrategy waitAllStrategy = waitStrategyMap.computeIfAbsent(serviceInstanceName, __ -> (WaitAllStrategy) new WaitAllStrategy().withStartupTimeout(Duration.ofMinutes(30)));
    waitAllStrategy.withStrategy(waitStrategy);
}
Also used : WaitAllStrategy(org.testcontainers.containers.wait.strategy.WaitAllStrategy)

Example 2 with WaitAllStrategy

use of org.testcontainers.containers.wait.strategy.WaitAllStrategy in project graylog2-server by Graylog2.

the class NodeContainerFactory method createRunningContainer.

private static GenericContainer<?> createRunningContainer(NodeContainerConfig config, ImageFromDockerfile image) {
    Path fileCopyBaseDir = config.mavenProjectDirProvider.getFileCopyBaseDir();
    List<Path> pluginJars = config.pluginJarsProvider.getJars();
    boolean includeFrontend = config.mavenProjectDirProvider.includeFrontend();
    GenericContainer<?> container = new GenericContainer<>(image).withFileSystemBind(property("server_jar"), GRAYLOG_HOME + "/graylog.jar", BindMode.READ_ONLY).withNetwork(config.network).withEnv("GRAYLOG_MONGODB_URI", config.mongoDbUri).withEnv("GRAYLOG_ELASTICSEARCH_HOSTS", config.elasticsearchUri).withEnv("GRAYLOG_ELASTICSEARCH_VERSION", config.elasticsearchVersion.encode()).withEnv("GRAYLOG_PASSWORD_SECRET", "M4lteserKreuzHerrStrack?").withEnv("GRAYLOG_NODE_ID_FILE", "data/config/node-id").withEnv("GRAYLOG_HTTP_BIND_ADDRESS", "0.0.0.0:" + API_PORT).withEnv("GRAYLOG_ROOT_PASSWORD_SHA2", ADMIN_PW_SHA2).withEnv("GRAYLOG_LB_RECOGNITION_PERIOD_SECONDS", "0").withEnv("GRAYLOG_VERSIONCHECKS", "false").waitingFor(new WaitAllStrategy().withStrategy(Wait.forLogMessage(".*Graylog server up and running.*", 1)).withStrategy(new HttpWaitStrategy().forPort(API_PORT).forPath("/api/system/indices/ranges").withMethod("GET").withBasicCredentials("admin", "admin").forResponsePredicate(body -> {
        try {
            return StreamSupport.stream(OBJECT_MAPPER.readTree(body).path("ranges").spliterator(), false).anyMatch(range -> range.path("index_name").asText().startsWith("graylog_"));
        } catch (IOException e) {
            throw new RuntimeException("Couldn't extract response", e);
        }
    }))).withExposedPorts(config.portsToExpose()).withStartupTimeout(Duration.of(120, SECONDS));
    if (!includeFrontend) {
        container.withEnv("DEVELOPMENT", "true");
    }
    pluginJars.forEach(hostPath -> {
        if (Files.exists(hostPath)) {
            final Path containerPath = Paths.get(GRAYLOG_HOME, "plugin", hostPath.getFileName().toString());
            container.addFileSystemBind(hostPath.toString(), containerPath.toString(), BindMode.READ_ONLY);
        }
    });
    container.start();
    if (config.enableDebugging) {
        LOG.info("Container debug port: " + container.getMappedPort(DEBUG_PORT));
    }
    config.mavenProjectDirProvider.getFilesToAddToBinDir().forEach(filename -> {
        final Path originalPath = fileCopyBaseDir.resolve(filename);
        final String containerPath = GRAYLOG_HOME + "/bin/" + originalPath.getFileName();
        container.copyFileToContainer(MountableFile.forHostPath(originalPath), containerPath);
        if (!containerFileExists(container, containerPath)) {
            LOG.error("Mandatory file {} does not exist in container at {}", filename, containerPath);
        }
    });
    return container;
}
Also used : Path(java.nio.file.Path) WaitAllStrategy(org.testcontainers.containers.wait.strategy.WaitAllStrategy) HttpWaitStrategy(org.testcontainers.containers.wait.strategy.HttpWaitStrategy) IOException(java.io.IOException) GenericContainer(org.testcontainers.containers.GenericContainer)

Aggregations

WaitAllStrategy (org.testcontainers.containers.wait.strategy.WaitAllStrategy)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 GenericContainer (org.testcontainers.containers.GenericContainer)1 HttpWaitStrategy (org.testcontainers.containers.wait.strategy.HttpWaitStrategy)1