DATAES-518 - Use scroll for unpaged find operations in ReactiveElasticsearchTemplate.
We now use scroll instead of a max page size for unpaged queries. Original pull request: #233.
This commit is contained in:
committed by
Mark Paluch
parent
fae1125e2f
commit
a1c139445f
@@ -32,6 +32,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -39,6 +40,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchVersion;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchVersionRule;
|
||||
import org.springframework.data.elasticsearch.TestUtils;
|
||||
@@ -354,6 +358,40 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-518
|
||||
public void findShouldApplyPagingCorrectly() {
|
||||
|
||||
List<SampleEntity> source = IntStream.range(0, 100).mapToObj(it -> randomEntity("entity - " + it))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
index(source.toArray(new SampleEntity[0]));
|
||||
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("message").contains("entity")) //
|
||||
.addSort(Sort.by("message"))//
|
||||
.setPageable(PageRequest.of(0, 20));
|
||||
|
||||
template.find(query, SampleEntity.class).as(StepVerifier::create) //
|
||||
.expectNextCount(20) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-518
|
||||
public void findWithoutPagingShouldReadAll() {
|
||||
|
||||
List<SampleEntity> source = IntStream.range(0, 100).mapToObj(it -> randomEntity("entity - " + it))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
index(source.toArray(new SampleEntity[0]));
|
||||
|
||||
CriteriaQuery query = new CriteriaQuery(new Criteria("message").contains("entity")) //
|
||||
.addSort(Sort.by("message"))//
|
||||
.setPageable(Pageable.unpaged());
|
||||
|
||||
template.find(query, SampleEntity.class).as(StepVerifier::create) //
|
||||
.expectNextCount(100) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void countShouldReturnCountAllWhenGivenNoQuery() {
|
||||
|
||||
|
||||
@@ -92,20 +92,20 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
assertThat(captor.getValue().getRefreshPolicy()).isEqualTo(RefreshPolicy.WAIT_UNTIL);
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
@Test // DATAES-504, DATAES-518
|
||||
public void findShouldFallBackToDefaultIndexOptionsIfNotSet() {
|
||||
|
||||
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
|
||||
when(client.search(captor.capture())).thenReturn(Flux.empty());
|
||||
|
||||
template.find(new CriteriaQuery(new Criteria("*")), SampleEntity.class) //
|
||||
template.find(new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10)), SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(captor.getValue().indicesOptions()).isEqualTo(DEFAULT_INDICES_OPTIONS);
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
@Test // DATAES-504, DATAES-518
|
||||
public void findShouldApplyIndexOptionsIfSet() {
|
||||
|
||||
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
|
||||
@@ -113,7 +113,7 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
|
||||
template.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
|
||||
|
||||
template.find(new CriteriaQuery(new Criteria("*")), SampleEntity.class) //
|
||||
template.find(new CriteriaQuery(new Criteria("*")).setPageable(PageRequest.of(0, 10)), SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -135,19 +135,18 @@ public class ReactiveElasticsearchTemplateUnitTests {
|
||||
assertThat(captor.getValue().source().size()).isEqualTo(50);
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
public void findShouldApplyDefaultMaxIfPaginationNotSet() {
|
||||
@Test // DATAES-504, DATAES-518
|
||||
public void findShouldUseScrollIfPaginationNotSet() {
|
||||
|
||||
ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
|
||||
when(client.search(captor.capture())).thenReturn(Flux.empty());
|
||||
when(client.scroll(captor.capture())).thenReturn(Flux.empty());
|
||||
|
||||
|
||||
template.find(new CriteriaQuery(new Criteria("*")).setPageable(Pageable.unpaged()), SampleEntity.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(captor.getValue().source().from()).isEqualTo(0);
|
||||
assertThat(captor.getValue().source().size()).isEqualTo(10000);
|
||||
verify(client).scroll(any());
|
||||
}
|
||||
|
||||
@Test // DATAES-504
|
||||
|
||||
Reference in New Issue
Block a user