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
Signed-off-by: sanghun <vitash1215@gmail.com>
testImplementation("org.opensearch.test", "framework", opensearchVersion) {
exclude(group = "org.hamcrest")
}
// opensearch-testcontainers exposes OpenSearchContainer as a GenericContainer subclass, but publishes

@reta reta Jul 2, 2026

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.

Please just use:

Suggested change
// opensearch-testcontainers exposes OpenSearchContainer as a GenericContainer subclass, but publishes
testImplementation("org.opensearch:opensearch-testcontainers:4.1.0")
testImplementation"("org.testcontainers:testcontainers:2.0.4")
testImplementation"("org.testcontainers:testcontainers-junit-jupiter:2.0.4")


import org.junit.Test;

public class OpenSearchTestContainerTests {

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.

I don't think we need these tests - opensearch-testcontainers has bunch of them


import org.opensearch.testcontainers.OpenSearchContainer;

final class OpenSearchTestContainer {

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.

Please move under java-client/src/test/java21. Also, we should be using JUnit Jupiter extentions mechanism with proper pre / post lifycycle (see please examples here https://www.baeldung.com/junit-5-registerextension-annotation)


import com.carrotsearch.randomizedtesting.ThreadFilter;

public final class TestcontainersThreadFilter implements ThreadFilter {

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.

Please remove, we should not see any leaking threads after https://github.com/opensearch-project/opensearch-java/pull/2033/changes#r3514648791 (the extension part)

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