From 674dcef8ba78da5a26afb0ea277890299e327cb2 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Tue, 26 Sep 2023 15:02:57 +0000 Subject: [PATCH] feat: using opensearchTestContainers --- boot-opensearch-sample/pom.xml | 12 +++++++++++ .../opensearch/common/ContainersConfig.java | 20 +++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/boot-opensearch-sample/pom.xml b/boot-opensearch-sample/pom.xml index 39b339fb1..ec28a83ae 100644 --- a/boot-opensearch-sample/pom.xml +++ b/boot-opensearch-sample/pom.xml @@ -89,11 +89,23 @@ spring-boot-testcontainers test + + org.opensearch.client + spring-data-opensearch-test-autoconfigure + 1.2.0 + test + org.testcontainers junit-jupiter test + + org.opensearch + opensearch-testcontainers + 2.0.0 + test + diff --git a/boot-opensearch-sample/src/test/java/com/example/opensearch/common/ContainersConfig.java b/boot-opensearch-sample/src/test/java/com/example/opensearch/common/ContainersConfig.java index 1996e2c2e..73e482548 100644 --- a/boot-opensearch-sample/src/test/java/com/example/opensearch/common/ContainersConfig.java +++ b/boot-opensearch-sample/src/test/java/com/example/opensearch/common/ContainersConfig.java @@ -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(); @@ -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()); } }