committed by
Greg L. Turnquist
parent
b043239eb2
commit
13c0dea55c
@@ -17,11 +17,6 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-elasticsearch-example-utils</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
|
||||
@@ -19,7 +19,6 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
@@ -27,12 +26,11 @@ import javax.annotation.PreDestroy;
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.RestClients;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
|
||||
@@ -43,13 +41,13 @@ import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
class ApplicationConfiguration {
|
||||
|
||||
@Autowired ReactiveElasticsearchOperations operations;
|
||||
@Autowired RestHighLevelClient client;
|
||||
@Autowired ConferenceRepository repository;
|
||||
|
||||
@PreDestroy
|
||||
public void deleteIndex() {
|
||||
try {
|
||||
RestClients.create(ClientConfiguration.localhost()).rest().indices()
|
||||
.delete(new DeleteIndexRequest("conference-index"), RequestOptions.DEFAULT);
|
||||
client.indices().delete(new DeleteIndexRequest("conference-index"), RequestOptions.DEFAULT);
|
||||
} catch (IOException | ElasticsearchStatusException e) {
|
||||
// just ignore it
|
||||
}
|
||||
@@ -59,8 +57,7 @@ class ApplicationConfiguration {
|
||||
public void insertDataSample() {
|
||||
|
||||
try {
|
||||
RestClients.create(ClientConfiguration.localhost()).rest().indices()
|
||||
.create(new CreateIndexRequest("conference-index"), RequestOptions.DEFAULT);
|
||||
client.indices().create(new CreateIndexRequest("conference-index"), RequestOptions.DEFAULT);
|
||||
} catch (IOException | ElasticsearchStatusException e) {
|
||||
// just ignore it
|
||||
}
|
||||
@@ -79,7 +76,6 @@ class ApplicationConfiguration {
|
||||
.location(new GeoPoint(50.0646501D, 19.9449799)).build());
|
||||
|
||||
// Remove all documents
|
||||
repository.deleteAll().then(repository.saveAll(documents).then())
|
||||
.as(StepVerifier::create).verifyComplete();
|
||||
repository.deleteAll().then(repository.saveAll(documents).then()).as(StepVerifier::create).verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
spring.data.elasticsearch.client.reactive.endpoints=localhost:9200
|
||||
12
elasticsearch/reactive/src/main/resources/log4j2.xml
Normal file
12
elasticsearch/reactive/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="LogToConsole" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="LogToConsole"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -17,7 +17,6 @@ package example.springdata.elasticsearch.conference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.elasticsearch.util.EnabledOnElasticsearch;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.text.ParseException;
|
||||
@@ -31,6 +30,13 @@ import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperatio
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* Test case to show Spring Data Elasticsearch functionality.
|
||||
@@ -38,14 +44,26 @@ import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
* @author Christoph Strobl
|
||||
* @author Prakhar Gupta
|
||||
*/
|
||||
@EnabledOnElasticsearch
|
||||
@SpringBootTest(classes = ApplicationConfiguration.class)
|
||||
@Testcontainers
|
||||
class ReactiveElasticsearchOperationsTest {
|
||||
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
ReactiveElasticsearchOperations operations;
|
||||
@Container //
|
||||
private static ElasticsearchContainer container = new ElasticsearchContainer(
|
||||
DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.2")) //
|
||||
.withPassword("foobar") //
|
||||
.withReuse(true);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void setProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.elasticsearch.uris", () -> "http://" + container.getHttpHostAddress());
|
||||
registry.add("spring.elasticsearch.username", () -> "elastic");
|
||||
registry.add("spring.elasticsearch.password", () -> "foobar");
|
||||
}
|
||||
|
||||
@Autowired ReactiveElasticsearchOperations operations;
|
||||
|
||||
@Test
|
||||
void textSearch() {
|
||||
|
||||
@@ -17,7 +17,6 @@ package example.springdata.elasticsearch.conference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.elasticsearch.util.EnabledOnElasticsearch;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.text.ParseException;
|
||||
@@ -27,6 +26,13 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* Test case to show reactive Spring Data Elasticsearch repository functionality.
|
||||
@@ -34,14 +40,26 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
* @author Christoph Strobl
|
||||
* @author Prakhar Gupta
|
||||
*/
|
||||
@EnabledOnElasticsearch
|
||||
@SpringBootTest(classes = ApplicationConfiguration.class)
|
||||
@Testcontainers
|
||||
class ReactiveElasticsearchRepositoryTest {
|
||||
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
@Autowired
|
||||
ConferenceRepository repository;
|
||||
@Container //
|
||||
private static ElasticsearchContainer container = new ElasticsearchContainer(
|
||||
DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.17.2")) //
|
||||
.withPassword("foobar") //
|
||||
.withReuse(true);
|
||||
|
||||
@DynamicPropertySource
|
||||
static void setProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.elasticsearch.uris", () -> "http://" + container.getHttpHostAddress());
|
||||
registry.add("spring.elasticsearch.username", () -> "elastic");
|
||||
registry.add("spring.elasticsearch.password", () -> "foobar");
|
||||
}
|
||||
|
||||
@Autowired ConferenceRepository repository;
|
||||
|
||||
@Test
|
||||
void textSearch() {
|
||||
|
||||
Reference in New Issue
Block a user