use of org.testcontainers.containers.wait.strategy.HttpWaitStrategy 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;
}
use of org.testcontainers.containers.wait.strategy.HttpWaitStrategy in project flink by apache.
the class FlinkContainers method waitUntilJobManagerRESTReachable.
private void waitUntilJobManagerRESTReachable(GenericContainer<?> jobManager) {
LOG.debug("Waiting for JobManager's REST interface getting ready");
new HttpWaitStrategy().forPort(conf.get(RestOptions.PORT)).forPath(ClusterOverviewHeaders.URL).forStatusCode(200).withReadTimeout(DEFAULT_TIMEOUT).waitUntilReady(jobManager);
}
use of org.testcontainers.containers.wait.strategy.HttpWaitStrategy in project instrumentation-java by census-instrumentation.
the class JaegerExporterHandlerIntegrationTest method startContainer.
/**
* 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);
}
}
Aggregations