diff --git a/boot-opensearch-sample/docker/docker-compose.yml b/boot-opensearch-sample/docker/docker-compose.yml index b1348824b..116b3e61f 100644 --- a/boot-opensearch-sample/docker/docker-compose.yml +++ b/boot-opensearch-sample/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: opensearch: @@ -8,9 +7,14 @@ services: ports: - "9200:9200" - "9600:9600" + healthcheck: + test: [ "CMD-SHELL", "curl -k -u admin:D3v3l0p-ment --silent --fail https://localhost:9200/ || exit 1" ] + interval: 10s + timeout: 10s + retries: 3 environment: - discovery.type=single-node - - OPENSEARCH_INITIAL_ADMIN_PASSWORD=admin + - OPENSEARCH_INITIAL_ADMIN_PASSWORD=D3v3l0p-ment - "DISABLE_SECURITY_PLUGIN=true" - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" diff --git a/boot-opensearch-sample/pom.xml b/boot-opensearch-sample/pom.xml index 786fe5ccc..d3d12c7d6 100644 --- a/boot-opensearch-sample/pom.xml +++ b/boot-opensearch-sample/pom.xml @@ -56,11 +56,6 @@ org.springframework.boot spring-boot-starter-web - - org.glassfish.jaxb - jaxb-runtime - provided - org.opensearch.client spring-data-opensearch-starter diff --git a/boot-opensearch-sample/src/main/resources/application-local.properties b/boot-opensearch-sample/src/main/resources/application-local.properties index 62c4e116a..847ab7449 100644 --- a/boot-opensearch-sample/src/main/resources/application-local.properties +++ b/boot-opensearch-sample/src/main/resources/application-local.properties @@ -1,5 +1,4 @@ -spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/appdb -spring.datasource.username=appuser -spring.datasource.password=secret - +################ opensearch ##################### +opensearch.uris=http://localhost:9200 +opensearch.username=admin +opensearch.password=D3v3l0p-ment diff --git a/boot-opensearch-sample/src/main/resources/application.properties b/boot-opensearch-sample/src/main/resources/application.properties index a2d763338..cd0e100ca 100644 --- a/boot-opensearch-sample/src/main/resources/application.properties +++ b/boot-opensearch-sample/src/main/resources/application.properties @@ -9,8 +9,4 @@ spring.mvc.problemdetails.enabled=true management.endpoints.web.exposure.include=configprops,env,health,info,logfile,loggers,metrics,prometheus management.endpoint.health.show-details=always -################ opensearch ##################### -opensearch.uris=http://localhost:9200 -opensearch.username=admin -opensearch.password=admin spring.threads.virtual.enabled=true \ No newline at end of file diff --git a/boot-opensearch-sample/src/test/java/com/example/opensearch/ApplicationIntegrationTest.java b/boot-opensearch-sample/src/test/java/com/example/opensearch/ApplicationIntegrationTest.java index 633b03437..bae45d571 100644 --- a/boot-opensearch-sample/src/test/java/com/example/opensearch/ApplicationIntegrationTest.java +++ b/boot-opensearch-sample/src/test/java/com/example/opensearch/ApplicationIntegrationTest.java @@ -1,10 +1,29 @@ package com.example.opensearch; +import static org.assertj.core.api.Assertions.assertThat; + import com.example.opensearch.common.AbstractIntegrationTest; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.io.InputStream; import org.junit.jupiter.api.Test; +import org.opensearch.client.Request; +import org.opensearch.client.Response; +import org.opensearch.client.RestClient; +import org.springframework.beans.factory.annotation.Autowired; class ApplicationIntegrationTest extends AbstractIntegrationTest { + @Autowired private RestClient restClient; + @Test - void contextLoads() {} + void restClientOpenSearchNodeVersion() throws IOException { + final Request request = new Request("GET", "/"); + final Response response = restClient.performRequest(request); + try (InputStream input = response.getEntity().getContent()) { + JsonNode result = new ObjectMapper().readTree(input); + assertThat(result.path("version").path("number").asText()).isEqualTo("2.16.0"); + } + } }