testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::modules::OpenSearchImage Class Reference

A reusable, copyable description of a single-node OpenSearch server for tests, running with the security plugin DISABLED: plain HTTP on one published port, no credentials — OpenSearchContainer::http_url() is all a REST client needs. More...

#include <testcontainers/modules/OpenSearch.hpp>

Public Member Functions

 OpenSearchImage ()
 A config ready to start(): pinned image, port 9200 exposed, security plugin disabled, single-node discovery, 512 MB heap, readiness = HTTP 200 from /_cluster/health through the published port, and a 120s startup budget (a JVM engine booting a gigabyte of plugins).
OpenSearchImagewith_image (const std::string &reference)
 Override the pinned image with a full reference "name[:tag]" (tag defaults to "latest"), e.g.
OpenSearchImagewith_env (std::string key, std::string value)
 Set an environment variable.
OpenSearchImagewith_label (std::string key, std::string value)
OpenSearchImagewith_network (std::string network)
 Join a user-defined network; peers resolve this container by name/alias at http://<alias>:9200 (kPort, not the mapped host port).
OpenSearchImagewith_network (const Network &network)
OpenSearchImagewith_network_alias (std::string alias)
OpenSearchImagewith_reuse (bool reuse=true)
 Enable container reuse (effective only when reuse is also enabled globally — see GenericImage::with_reuse).
OpenSearchImagewith_wait (WaitFor wait)
 REPLACE the default readiness probe with a custom strategy (the first call drops the module's /_cluster/health probe; repeatable — further waits run in order under the same timeout).
OpenSearchImagewith_startup_timeout (std::chrono::milliseconds timeout)
 Budget for the readiness phase (default: 120s — a JVM engine booting ~1 GB of plugins needs it on slow CI; observed warm boots are 10-20s).
OpenSearchImagewith_startup_attempts (int n)
 Retry the whole create→start→wait sequence up to n times.
OpenSearchImagewith_customizer (std::function< void(GenericImage &)> customize)
 Register a callback that customizes the underlying GenericImage — the channel for options this module does not surface (mounts, memory limits, extra ports such as the performance analyzer's 9600, pull policy, ...).
GenericImage to_generic () const
 Render the full configuration — env, port, health probe, customizers — into a plain GenericImage: the drop-down escape hatch when you need a raw core Container instead of an OpenSearchContainer.
OpenSearchContainer start () const
 Create, start, and wait until /_cluster/health answers 200 through the published port.

Static Public Attributes

static constexpr std::string_view kDefaultImage = "opensearchproject/opensearch:3.7.0"
 The pinned default image (the newest stable of the active 3.x line; the hub publishes no minor-line tags, so the pin is patch-level).
static constexpr std::uint16_t kPort = 9200
 The REST port INSIDE the container.

Detailed Description

A reusable, copyable description of a single-node OpenSearch server for tests, running with the security plugin DISABLED: plain HTTP on one published port, no credentials — OpenSearchContainer::http_url() is all a REST client needs.

Throwaway test data only; no client library is required or linked.

The with_* builders mutate in place and return *this, so a named config can be configured incrementally and started many times. Core options the module does not surface are reached through with_customizer; to_generic() drops down to a plain GenericImage entirely.

Constructor & Destructor Documentation

◆ OpenSearchImage()

testcontainers::modules::OpenSearchImage::OpenSearchImage ( )

A config ready to start(): pinned image, port 9200 exposed, security plugin disabled, single-node discovery, 512 MB heap, readiness = HTTP 200 from /_cluster/health through the published port, and a 120s startup budget (a JVM engine booting a gigabyte of plugins).

Member Function Documentation

◆ with_image()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_image ( const std::string & reference)

Override the pinned image with a full reference "name[:tag]" (tag defaults to "latest"), e.g.

another 3.x patch or a registry mirror. Images older than 2.12 are untested.

◆ with_env()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_env ( std::string key,
std::string value )

Set an environment variable.

Applied after the module's own settings, so on a duplicate key YOURS wins (the managed keys are engine tuning, not credential mirrors — no getter can desync). Keys shaped like section.setting become OpenSearch settings — with_env("cluster.name", "it") configures the server. Overriding the heap (OPENSEARCH_JAVA_OPTS) or discovery.type is fair game; re-enabling security (DISABLE_SECURITY_PLUGIN / DISABLE_INSTALL_DEMO_CONFIG) switches 9200 to https with demo certs, which the module's plain-HTTP readiness probe can never pass — replace it via with_wait then (an in-container curl -sk --fail -u admin:<password> https://localhost:9200/ through wait_for::successful_shell_command is the working recipe).

◆ with_label()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_label ( std::string key,
std::string value )

◆ with_network() [1/2]

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_network ( std::string network)

Join a user-defined network; peers resolve this container by name/alias at http://<alias>:9200 (kPort, not the mapped host port).

◆ with_network() [2/2]

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_network ( const Network & network)

◆ with_network_alias()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_network_alias ( std::string alias)

◆ with_reuse()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_reuse ( bool reuse = true)

Enable container reuse (effective only when reuse is also enabled globally — see GenericImage::with_reuse).

An adopted server keeps its indices: same config, next run, data intact.

◆ with_wait()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_wait ( WaitFor wait)

REPLACE the default readiness probe with a custom strategy (the first call drops the module's /_cluster/health probe; repeatable — further waits run in order under the same timeout).

Required when a security-enabled setup turns 9200 into https (see with_env).

◆ with_startup_timeout()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_startup_timeout ( std::chrono::milliseconds timeout)

Budget for the readiness phase (default: 120s — a JVM engine booting ~1 GB of plugins needs it on slow CI; observed warm boots are 10-20s).

Image pull time does not count against it.

◆ with_startup_attempts()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_startup_attempts ( int n)

Retry the whole create→start→wait sequence up to n times.

◆ with_customizer()

OpenSearchImage & testcontainers::modules::OpenSearchImage::with_customizer ( std::function< void(GenericImage &)> customize)

Register a callback that customizes the underlying GenericImage — the channel for options this module does not surface (mounts, memory limits, extra ports such as the performance analyzer's 9600, pull policy, ...).

Customizers run when the config is rendered (start() / to_generic()), in registration order, AFTER the module's own rendering — what they set wins. A wait added here runs IN ADDITION to the default probe (unlike with_wait, which replaces it).

◆ to_generic()

GenericImage testcontainers::modules::OpenSearchImage::to_generic ( ) const

Render the full configuration — env, port, health probe, customizers — into a plain GenericImage: the drop-down escape hatch when you need a raw core Container instead of an OpenSearchContainer.

◆ start()

OpenSearchContainer testcontainers::modules::OpenSearchImage::start ( ) const

Create, start, and wait until /_cluster/health answers 200 through the published port.

Throws DockerError / StartupTimeoutError from the run, like GenericImage::start().

Member Data Documentation

◆ kDefaultImage

std::string_view testcontainers::modules::OpenSearchImage::kDefaultImage = "opensearchproject/opensearch:3.7.0"
staticconstexpr

The pinned default image (the newest stable of the active 3.x line; the hub publishes no minor-line tags, so the pin is patch-level).

Override with with_image; any opensearchproject/opensearch tag from 2.12 up keeps the env contract this module relies on.

◆ kPort

std::uint16_t testcontainers::modules::OpenSearchImage::kPort = 9200
staticconstexpr

The REST port INSIDE the container.

Peers on a shared docker network connect to http://<alias-or-name>:kPort; the test process itself uses OpenSearchContainer::http_url() (the mapped host port).