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);
}
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;
}
Aggregations