Skip to content

Commit

Permalink
feat: using opensearchTestContainers
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Sep 26, 2023
1 parent 4d29ffb commit 674dcef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 12 additions & 0 deletions boot-opensearch-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,23 @@
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opensearch.client</groupId>
<artifactId>spring-data-opensearch-test-autoconfigure</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opensearch</groupId>
<artifactId>opensearch-testcontainers</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.example.opensearch.common;

import org.opensearch.testcontainers.OpensearchContainer;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.utility.DockerImageName;

public class ContainersConfig {

static final GenericContainer<?> openSearchContainer =
new GenericContainer<>("opensearchproject/opensearch:2.10.0")
.withEnv("discovery.type", "single-node")
.withEnv("DISABLE_SECURITY_PLUGIN", "true")
.withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m")
.withExposedPorts(9200, 9600);
@Container
public static OpensearchContainer openSearchContainer =
new OpensearchContainer(DockerImageName.parse("opensearchproject/opensearch:2.10.0"));

static {
openSearchContainer.start();
Expand All @@ -20,11 +19,6 @@ public class ContainersConfig {
@DynamicPropertySource
static void setApplicationProperties(DynamicPropertyRegistry dynamicPropertyRegistry) {
dynamicPropertyRegistry.add(
"opensearch.uris",
() ->
"http://%s:%d"
.formatted(
openSearchContainer.getHost(),
openSearchContainer.getMappedPort(9200)));
"opensearch.uris", () -> openSearchContainer.getHttpHostAddress());
}
}

0 comments on commit 674dcef

Please sign in to comment.