Skip to content

Use Testcontainers for integration tests#2033

Open
lsh1215 wants to merge 4 commits into
opensearch-project:mainfrom
lsh1215:issue-1916-testcontainers
Open

Use Testcontainers for integration tests#2033
lsh1215 wants to merge 4 commits into
opensearch-project:mainfrom
lsh1215:issue-1916-testcontainers

Conversation

@lsh1215

@lsh1215 lsh1215 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Adds Testcontainers-backed OpenSearch startup for Java client integration tests so developers and the released integration workflow no longer need to start OpenSearch with Docker Compose before running integrationTest.

The Testcontainers path is enabled by default for the integrationTest task. Existing externally managed clusters remain supported by setting tests.rest.cluster or disabling the test container with -Dtests.opensearch.testcontainers.enabled=false.

The Docker/Testcontainers startup path is limited to the integrationTest task. The released integration CI path remains Ubuntu-only, and the macOS/Windows build and unit-test jobs do not get a Docker runtime requirement.

Closes #1916.

Changes

  • Add a JVM-singleton OpenSearchTestContainer helper for integration tests.
  • Start the container before OpenSearchRestTestCase initializes its REST client.
  • Use HTTPS/basic auth and handle the OpenSearch 2.12+ initial admin password requirement.
  • Handle ambiguous OpenSearch 2.x/custom image version tags conservatively and cover that compatibility logic with focused tests.
  • Disable disk threshold checks only for the disposable Testcontainers-managed node to avoid Docker host disk watermark state applying cluster.blocks.create_index=true during tests.
  • Replace released integration workflow Docker Compose setup with Gradle/Testcontainers startup.
  • Keep unreleased/source-build integration workflow on its existing external cluster path by disabling Testcontainers there.
  • Document the new default, version/image selection, and external-cluster opt-out.

Verification

  • git diff --check
  • ./gradlew integrationTest --tests "org.opensearch.client.opensearch.integTest.OpenSearchTestContainerTests"
  • ./gradlew spotlessJavaCheck
  • ./gradlew integrationTest --tests "org.opensearch.client.opensearch.integTest.restclient.PingAndInfoIT" -Dtests.opensearch.version=3.2.0
  • GitHub Actions for PR Use Testcontainers for integration tests #2033: all checks passed, including the released integration matrix.

@lsh1215 lsh1215 force-pushed the issue-1916-testcontainers branch 2 times, most recently from b151d92 to 389d48e Compare June 30, 2026 16:09
Signed-off-by: sanghun <vitash1215@gmail.com>
@lsh1215 lsh1215 force-pushed the issue-1916-testcontainers branch from 389d48e to 5923c09 Compare June 30, 2026 16:12
lsh1215 added 2 commits July 1, 2026 02:06
Signed-off-by: sanghun <vitash1215@gmail.com>
Signed-off-by: sanghun <vitash1215@gmail.com>
@lsh1215 lsh1215 marked this pull request as ready for review June 30, 2026 18:01
Comment thread java-client/build.gradle.kts Outdated
testImplementation("org.opensearch.test", "framework", opensearchVersion) {
exclude(group = "org.hamcrest")
}
"java21Implementation"("org.testcontainers:testcontainers:2.0.5")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed the official module in the first pass. Thanks for pointing it out.

Updated in 728e3fe.

The integration test container setup now uses org.opensearch.testcontainers.OpenSearchContainer, and the local GenericContainer setup code has been removed.

The remaining Testcontainers dependency is compileOnly only, since OpenSearchContainer extends GenericContainer and javac needs that superclass API.

The current CI failures appear unrelated to the test changes; the failed jobs stopped during Gradle buildSrc dependency resolution.

Signed-off-by: sanghun <vitash1215@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] use testcontainers for integration tests

2 participants