DATAES-567 - Polishing.

This commit is contained in:
Peter-Josef Meisch
2020-04-20 18:56:11 +02:00
parent c2eec8c74a
commit 91f442bd2f
8 changed files with 64 additions and 60 deletions

View File

@@ -18,11 +18,6 @@ package org.springframework.data.elasticsearch.client.reactive;
import static org.assertj.core.api.Assertions.*;
import lombok.SneakyThrows;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import reactor.test.StepVerifier;
import java.io.IOException;
@@ -47,12 +42,16 @@ import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -218,9 +217,9 @@ public class ReactiveElasticsearchClientTests {
String id2 = addSourceDocument().ofType(TYPE_I).to(INDEX_I);
MultiGetRequest request = new MultiGetRequest() //
.add(INDEX_I,id1) //
.add(INDEX_I,"this-one-does-not-exist") //
.add(INDEX_I,id2); //
.add(INDEX_I, id1) //
.add(INDEX_I, "this-one-does-not-exist") //
.add(INDEX_I, id2); //
client.multiGet(request) //
.map(GetResult::getId) //
@@ -236,8 +235,7 @@ public class ReactiveElasticsearchClientTests {
String id2 = addSourceDocument().ofType(TYPE_I).to(INDEX_I);
client.multiGet(new MultiGetRequest() //
.add(INDEX_II, id1)
.add(INDEX_II, id2)) //
.add(INDEX_II, id1).add(INDEX_II, id2)) //
.as(StepVerifier::create) //
.verifyComplete();
}
@@ -661,7 +659,7 @@ public class ReactiveElasticsearchClientTests {
}).verifyComplete();
}
@Test //DATAES-567
@Test // DATAES-567
public void aggregateReturnsAggregationResults() throws IOException {
syncClient.indices().create(new CreateIndexRequest(INDEX_I), RequestOptions.DEFAULT);
Map<String, Object> jsonMap = Collections.singletonMap("properties",
@@ -676,10 +674,8 @@ public class ReactiveElasticsearchClientTests {
SearchRequest request = new SearchRequest(INDEX_I) //
.source(searchSourceBuilder);
client.aggregate(request)
.as(StepVerifier::create)
.expectNextMatches(aggregation -> aggregation.getType().equals(StringTerms.NAME))
.verifyComplete();
client.aggregate(request).as(StepVerifier::create)
.expectNextMatches(aggregation -> aggregation.getType().equals(StringTerms.NAME)).verifyComplete();
}
private AddToIndexOfType addSourceDocument() {

View File

@@ -19,9 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockWebClientProvider.Receive.*;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.metrics.ParsedMax;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -43,6 +40,8 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.metrics.ParsedMax;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -637,7 +636,8 @@ public class ReactiveElasticsearchClientUnitTests {
assertThat(aggregation.getName()).isEqualTo("max_post_date");
assertThat(aggregation instanceof ParsedMax);
ParsedMax parsedMax = (ParsedMax) aggregation;
assertThat(Instant.ofEpochMilli((long)parsedMax.getValue())).isEqualTo(Instant.parse("2010-01-15T01:46:38Z"));
assertThat(Instant.ofEpochMilli((long) parsedMax.getValue()))
.isEqualTo(Instant.parse("2010-01-15T01:46:38Z"));
}).verifyComplete();
}
@@ -648,7 +648,6 @@ public class ReactiveElasticsearchClientUnitTests {
.receive(Receive::json) //
.body(fromPath("aggregate-ok-no-results"));
client.aggregate(new SearchRequest("twitter")) //
.as(StepVerifier::create) //
.consumeNextWith(aggregation -> {

View File

@@ -24,8 +24,6 @@ import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -41,6 +39,8 @@ import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.junit.jupiter.api.AfterEach;
@@ -498,10 +498,8 @@ public class ReactiveElasticsearchTemplateTests {
index(sampleEntity1, sampleEntity2, sampleEntity3);
NativeSearchQuery query = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.addAggregation(AggregationBuilders.terms("messages").field("message"))
.build();
NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.addAggregation(AggregationBuilders.terms("messages").field("message")).build();
template.aggregate(query, SampleEntity.class) //
.as(StepVerifier::create) //
@@ -518,8 +516,9 @@ public class ReactiveElasticsearchTemplateTests {
@Test // DATAES-567
public void aggregateShouldReturnEmptyWhenIndexDoesNotExist() {
template.aggregate(new CriteriaQuery(Criteria.where("message").is("some message")), SampleEntity.class,
IndexCoordinates.of("no-such-index")) //
template
.aggregate(new CriteriaQuery(Criteria.where("message").is("some message")), SampleEntity.class,
IndexCoordinates.of("no-such-index")) //
.as(StepVerifier::create) //
.verifyComplete();
}