Skip to content

Commit

Permalink
feat : adds health checks and testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Sep 6, 2024
1 parent fffbc95 commit 65e1987
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
8 changes: 6 additions & 2 deletions boot-opensearch-sample/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:

opensearch:
Expand All @@ -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"

Expand Down
5 changes: 0 additions & 5 deletions boot-opensearch-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.opensearch.client</groupId>
<artifactId>spring-data-opensearch-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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");
}
}
}

0 comments on commit 65e1987

Please sign in to comment.