DATAES-772 - Polishing.

This commit is contained in:
Peter-Josef Meisch 2020-04-17 21:40:54 +02:00
parent 76e91c3366
commit f6a37f4601
8 changed files with 114 additions and 144 deletions

View File

@ -30,8 +30,8 @@ import org.springframework.data.mapping.callback.EntityCallback;
public interface AfterConvertCallback<T> extends EntityCallback<T> { public interface AfterConvertCallback<T> extends EntityCallback<T> {
/** /**
* Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either * Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either the
* the same or a modified instance of the domain object. * same or a modified instance of the domain object.
* *
* @param entity the domain object (the result of the conversion). * @param entity the domain object (the result of the conversion).
* @param document must not be {@literal null}. * @param document must not be {@literal null}.

View File

@ -31,8 +31,8 @@ import org.springframework.data.mapping.callback.EntityCallback;
public interface ReactiveAfterConvertCallback<T> extends EntityCallback<T> { public interface ReactiveAfterConvertCallback<T> extends EntityCallback<T> {
/** /**
* Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either * Entity callback method invoked after a domain object is materialized from a {@link Document}. Can return either the
* the same or a modified instance of the domain object. * same or a modified instance of the domain object.
* *
* @param entity the domain object (the result of the conversion). * @param entity the domain object (the result of the conversion).
* @param document must not be {@literal null}. * @param document must not be {@literal null}.

View File

@ -206,9 +206,7 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
} }
private Document lukeDocument() { private Document lukeDocument() {
return Document.create() return Document.create().append("id", "init").append("firstname", "luke");
.append("id", "init")
.append("firstname", "luke");
} }
@Test // DATAES-772 @Test // DATAES-772
@ -235,8 +233,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
List<Person> results = template.multiGet(queryForTwo(), Person.class, index); List<Person> results = template.multiGet(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -267,8 +265,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
AggregatedPage<Person> results = template.queryForPage(queryForTwo(), Person.class, index); AggregatedPage<Person> results = template.queryForPage(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.getContent().get(0).id).isEqualTo("after-convert"); assertThat(results.getContent().get(0).id).isEqualTo("after-convert");
assertThat(results.getContent().get(1).id).isEqualTo("after-convert"); assertThat(results.getContent().get(1).id).isEqualTo("after-convert");
} }
@ -279,8 +277,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Page<Person>> results = template.queryForPage(singletonList(queryForTwo()), Person.class, index); List<Page<Person>> results = template.queryForPage(singletonList(queryForTwo()), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<Person> persons = results.get(0).getContent(); List<Person> persons = results.get(0).getContent();
assertThat(persons.get(0).id).isEqualTo("after-convert"); assertThat(persons.get(0).id).isEqualTo("after-convert");
assertThat(persons.get(1).id).isEqualTo("after-convert"); assertThat(persons.get(1).id).isEqualTo("after-convert");
@ -290,14 +288,12 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
void queryForPageWithMultipleQueriesAndEntityClassesShouldInvokeAfterConvertCallback() { void queryForPageWithMultipleQueriesAndEntityClassesShouldInvokeAfterConvertCallback() {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<AggregatedPage<?>> results = template.queryForPage(singletonList(queryForTwo()), List<AggregatedPage<?>> results = template.queryForPage(singletonList(queryForTwo()), singletonList(Person.class),
singletonList(Person.class), index); index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<Person> persons = results.get(0).getContent().stream() List<Person> persons = results.get(0).getContent().stream().map(Person.class::cast).collect(Collectors.toList());
.map(Person.class::cast)
.collect(Collectors.toList());
assertThat(persons.get(0).id).isEqualTo("after-convert"); assertThat(persons.get(0).id).isEqualTo("after-convert");
assertThat(persons.get(1).id).isEqualTo("after-convert"); assertThat(persons.get(1).id).isEqualTo("after-convert");
} }
@ -307,8 +303,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
CloseableIterator<Person> results = template.stream(queryForTwo(), Person.class, index); CloseableIterator<Person> results = template.stream(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.next().id).isEqualTo("after-convert"); assertThat(results.next().id).isEqualTo("after-convert");
assertThat(results.next().id).isEqualTo("after-convert"); assertThat(results.next().id).isEqualTo("after-convert");
} }
@ -322,8 +318,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
assertThat(results.next().id).isEqualTo("after-convert"); assertThat(results.next().id).isEqualTo("after-convert");
assertThat(results.next().id).isEqualTo("after-convert"); assertThat(results.next().id).isEqualTo("after-convert");
verify(afterConvertCallback, times(4)) verify(afterConvertCallback, times(4)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
} }
private void skipItemsFromScrollStart(CloseableIterator<Person> results) { private void skipItemsFromScrollStart(CloseableIterator<Person> results) {
@ -337,8 +333,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.queryForList(queryForTwo(), Person.class, index); List<Person> results = template.queryForList(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -349,8 +345,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<List<Person>> results = template.queryForList(singletonList(queryForTwo()), Person.class, index); List<List<Person>> results = template.queryForList(singletonList(queryForTwo()), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<Person> persons = results.get(0); List<Person> persons = results.get(0);
assertThat(persons.get(0).id).isEqualTo("after-convert"); assertThat(persons.get(0).id).isEqualTo("after-convert");
assertThat(persons.get(1).id).isEqualTo("after-convert"); assertThat(persons.get(1).id).isEqualTo("after-convert");
@ -362,11 +358,9 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<List<?>> results = template.queryForList(singletonList(queryForTwo()), singletonList(Person.class), index); List<List<?>> results = template.queryForList(singletonList(queryForTwo()), singletonList(Person.class), index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<Person> persons = results.get(0).stream() List<Person> persons = results.get(0).stream().map(Person.class::cast).collect(Collectors.toList());
.map(Person.class::cast)
.collect(Collectors.toList());
assertThat(persons.get(0).id).isEqualTo("after-convert"); assertThat(persons.get(0).id).isEqualTo("after-convert");
assertThat(persons.get(1).id).isEqualTo("after-convert"); assertThat(persons.get(1).id).isEqualTo("after-convert");
} }
@ -377,8 +371,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
AggregatedPage<Person> results = template.moreLikeThis(moreLikeThisQuery(), Person.class, index); AggregatedPage<Person> results = template.moreLikeThis(moreLikeThisQuery(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.getContent().get(0).id).isEqualTo("after-convert"); assertThat(results.getContent().get(0).id).isEqualTo("after-convert");
assertThat(results.getContent().get(1).id).isEqualTo("after-convert"); assertThat(results.getContent().get(1).id).isEqualTo("after-convert");
} }
@ -408,8 +402,7 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHit<Person> result = template.searchOne(queryForOne(), Person.class, index); SearchHit<Person> result = template.searchOne(queryForOne(), Person.class, index);
verify(afterConvertCallback) verify(afterConvertCallback).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index));
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index));
assertThat(result.getContent().id).isEqualTo("after-convert"); assertThat(result.getContent().id).isEqualTo("after-convert");
} }
@ -418,8 +411,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
List<SearchHits<Person>> results = template.multiSearch(singletonList(queryForTwo()), Person.class, index); List<SearchHits<Person>> results = template.multiSearch(singletonList(queryForTwo()), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<SearchHit<Person>> hits = results.get(0).getSearchHits(); List<SearchHit<Person>> hits = results.get(0).getSearchHits();
assertThat(hits.get(0).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(0).getContent().id).isEqualTo("after-convert");
assertThat(hits.get(1).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(1).getContent().id).isEqualTo("after-convert");
@ -428,11 +421,11 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
@Test // DATAES-772 @Test // DATAES-772
void multiSearchWithMultipleEntityClassesShouldInvokeAfterConvertCallback() { void multiSearchWithMultipleEntityClassesShouldInvokeAfterConvertCallback() {
List<SearchHits<?>> results = template.multiSearch(singletonList(queryForTwo()), List<SearchHits<?>> results = template.multiSearch(singletonList(queryForTwo()), singletonList(Person.class),
singletonList(Person.class), index); index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<? extends SearchHit<?>> hits = results.get(0).getSearchHits(); List<? extends SearchHit<?>> hits = results.get(0).getSearchHits();
assertThat(((Person) hits.get(0).getContent()).id).isEqualTo("after-convert"); assertThat(((Person) hits.get(0).getContent()).id).isEqualTo("after-convert");
assertThat(((Person) hits.get(1).getContent()).id).isEqualTo("after-convert"); assertThat(((Person) hits.get(1).getContent()).id).isEqualTo("after-convert");
@ -443,8 +436,7 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHits<Person> results = template.search(queryForTwo(), Person.class); SearchHits<Person> results = template.search(queryForTwo(), Person.class);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
List<SearchHit<Person>> hits = results.getSearchHits(); List<SearchHit<Person>> hits = results.getSearchHits();
assertThat(hits.get(0).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(0).getContent().id).isEqualTo("after-convert");
assertThat(hits.get(1).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(1).getContent().id).isEqualTo("after-convert");
@ -455,8 +447,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHits<Person> results = template.search(queryForTwo(), Person.class, index); SearchHits<Person> results = template.search(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<SearchHit<Person>> hits = results.getSearchHits(); List<SearchHit<Person>> hits = results.getSearchHits();
assertThat(hits.get(0).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(0).getContent().id).isEqualTo("after-convert");
assertThat(hits.get(1).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(1).getContent().id).isEqualTo("after-convert");
@ -467,8 +459,7 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHits<Person> results = template.search(moreLikeThisQuery(), Person.class); SearchHits<Person> results = template.search(moreLikeThisQuery(), Person.class);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
List<SearchHit<Person>> hits = results.getSearchHits(); List<SearchHit<Person>> hits = results.getSearchHits();
assertThat(hits.get(0).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(0).getContent().id).isEqualTo("after-convert");
assertThat(hits.get(1).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(1).getContent().id).isEqualTo("after-convert");
@ -479,8 +470,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHits<Person> results = template.search(moreLikeThisQuery(), Person.class, index); SearchHits<Person> results = template.search(moreLikeThisQuery(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
List<SearchHit<Person>> hits = results.getSearchHits(); List<SearchHit<Person>> hits = results.getSearchHits();
assertThat(hits.get(0).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(0).getContent().id).isEqualTo("after-convert");
assertThat(hits.get(1).getContent().id).isEqualTo("after-convert"); assertThat(hits.get(1).getContent().id).isEqualTo("after-convert");
@ -491,8 +482,7 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHitsIterator<Person> results = template.searchForStream(queryForTwo(), Person.class); SearchHitsIterator<Person> results = template.searchForStream(queryForTwo(), Person.class);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.next().getContent().id).isEqualTo("after-convert"); assertThat(results.next().getContent().id).isEqualTo("after-convert");
assertThat(results.next().getContent().id).isEqualTo("after-convert"); assertThat(results.next().getContent().id).isEqualTo("after-convert");
} }
@ -502,8 +492,8 @@ abstract class AbstractElasticsearchTemplateCallbackTests {
SearchHitsIterator<Person> results = template.searchForStream(queryForTwo(), Person.class, index); SearchHitsIterator<Person> results = template.searchForStream(queryForTwo(), Person.class, index);
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.next().getContent().id).isEqualTo("after-convert"); assertThat(results.next().getContent().id).isEqualTo("after-convert");
assertThat(results.next().getContent().id).isEqualTo("after-convert"); assertThat(results.next().getContent().id).isEqualTo("after-convert");
} }

View File

@ -84,8 +84,8 @@ class ElasticsearchRestTemplateCallbackTests extends AbstractElasticsearchTempla
}).when(getResponse).getSourceAsMap(); }).when(getResponse).getSourceAsMap();
doReturn(multiGetResponse).when(client).mget(any(MultiGetRequest.class), any(RequestOptions.class)); doReturn(multiGetResponse).when(client).mget(any(MultiGetRequest.class), any(RequestOptions.class));
doReturn(new MultiGetItemResponse[]{multiGetItemResponse, multiGetItemResponse}) doReturn(new MultiGetItemResponse[] { multiGetItemResponse, multiGetItemResponse }).when(multiGetResponse)
.when(multiGetResponse).getResponses(); .getResponses();
doReturn(getResponse).when(multiGetItemResponse).getResponse(); doReturn(getResponse).when(multiGetItemResponse).getResponse();
doReturn(searchResponse).when(client).search(any(SearchRequest.class), any(RequestOptions.class)); doReturn(searchResponse).when(client).search(any(SearchRequest.class), any(RequestOptions.class));

View File

@ -107,8 +107,8 @@ class ElasticsearchTransportTemplateCallbackTests extends AbstractElasticsearchT
when(client.prepareMultiGet()).thenReturn(multiGetRequestBuilder); when(client.prepareMultiGet()).thenReturn(multiGetRequestBuilder);
doReturn(multiGetResponseActionFuture).when(multiGetRequestBuilder).execute(); doReturn(multiGetResponseActionFuture).when(multiGetRequestBuilder).execute();
when(multiGetResponseActionFuture.actionGet()).thenReturn(multiGetResponse); when(multiGetResponseActionFuture.actionGet()).thenReturn(multiGetResponse);
doReturn(new MultiGetItemResponse[]{ multiGetItemResponse, multiGetItemResponse }) doReturn(new MultiGetItemResponse[] { multiGetItemResponse, multiGetItemResponse }).when(multiGetResponse)
.when(multiGetResponse).getResponses(); .getResponses();
doReturn(getResponse).when(multiGetItemResponse).getResponse(); doReturn(getResponse).when(multiGetItemResponse).getResponse();
when(client.prepareSearch(anyVararg())).thenReturn(searchRequestBuilder); when(client.prepareSearch(anyVararg())).thenReturn(searchRequestBuilder);

View File

@ -222,12 +222,11 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
List<Person> results = template.multiGet(pagedQueryForTwo(), Person.class, index) List<Person> results = template.multiGet(pagedQueryForTwo(), Person.class, index).timeout(Duration.ofSeconds(1))
.timeout(Duration.ofSeconds(1))
.toStream().collect(Collectors.toList()); .toStream().collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -294,27 +293,21 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.find(pagedQueryForTwo(), Person.class) List<Person> results = template.find(pagedQueryForTwo(), Person.class).timeout(Duration.ofSeconds(1)).toStream()
.timeout(Duration.ofSeconds(1)).toStream()
.collect(Collectors.toList()); .collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
private Query pagedQueryForTwo() { private Query pagedQueryForTwo() {
return new NativeSearchQueryBuilder() return new NativeSearchQueryBuilder().withIds(Arrays.asList("init1", "init2")).withPageable(PageRequest.of(0, 10))
.withIds(Arrays.asList("init1", "init2"))
.withPageable(PageRequest.of(0, 10))
.build(); .build();
} }
private Document lukeDocument() { private Document lukeDocument() {
return Document.create() return Document.create().append("id", "init").append("firstname", "luke");
.append("id", "init")
.append("firstname", "luke");
} }
@Test // DATAES-772 @Test // DATAES-772
@ -325,20 +318,16 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.find(scrollingQueryForTwo(), Person.class) List<Person> results = template.find(scrollingQueryForTwo(), Person.class).timeout(Duration.ofSeconds(1)).toStream()
.timeout(Duration.ofSeconds(1)) .collect(Collectors.toList());
.toStream().collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
private Query scrollingQueryForTwo() { private Query scrollingQueryForTwo() {
return new NativeSearchQueryBuilder() return new NativeSearchQueryBuilder().withIds(Arrays.asList("init1", "init2")).build();
.withIds(Arrays.asList("init1", "init2"))
.build();
} }
@Test // DATAES-772 @Test // DATAES-772
@ -349,12 +338,11 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.find(pagedQueryForTwo(), Person.class, index) List<Person> results = template.find(pagedQueryForTwo(), Person.class, index).timeout(Duration.ofSeconds(1))
.timeout(Duration.ofSeconds(1)).toStream() .toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -367,12 +355,10 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class) List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class).timeout(Duration.ofSeconds(1))
.timeout(Duration.ofSeconds(1)).toStream() .toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -386,11 +372,10 @@ public class ReactiveElasticsearchTemplateCallbackTests {
@SuppressWarnings("deprecation") // we know what we test @SuppressWarnings("deprecation") // we know what we test
List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class, index) List<Person> results = template.find(pagedQueryForTwo(), Person.class, Person.class, index)
.timeout(Duration.ofSeconds(1)).toStream() .timeout(Duration.ofSeconds(1)).toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).id).isEqualTo("after-convert"); assertThat(results.get(0).id).isEqualTo("after-convert");
assertThat(results.get(1).id).isEqualTo("after-convert"); assertThat(results.get(1).id).isEqualTo("after-convert");
} }
@ -402,12 +387,10 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class) List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class).timeout(Duration.ofSeconds(1))
.timeout(Duration.ofSeconds(1)).toStream() .toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.get(0).getContent().id).isEqualTo("after-convert"); assertThat(results.get(0).getContent().id).isEqualTo("after-convert");
assertThat(results.get(1).getContent().id).isEqualTo("after-convert"); assertThat(results.get(1).getContent().id).isEqualTo("after-convert");
} }
@ -420,11 +403,10 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, index) List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, index)
.timeout(Duration.ofSeconds(1)).toStream() .timeout(Duration.ofSeconds(1)).toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).getContent().id).isEqualTo("after-convert"); assertThat(results.get(0).getContent().id).isEqualTo("after-convert");
assertThat(results.get(1).getContent().id).isEqualTo("after-convert"); assertThat(results.get(1).getContent().id).isEqualTo("after-convert");
} }
@ -437,11 +419,9 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, Person.class) List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, Person.class)
.timeout(Duration.ofSeconds(1)).toStream() .timeout(Duration.ofSeconds(1)).toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), any());
assertThat(results.get(0).getContent().id).isEqualTo("after-convert"); assertThat(results.get(0).getContent().id).isEqualTo("after-convert");
assertThat(results.get(1).getContent().id).isEqualTo("after-convert"); assertThat(results.get(1).getContent().id).isEqualTo("after-convert");
} }
@ -454,11 +434,10 @@ public class ReactiveElasticsearchTemplateCallbackTests {
template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback)); template.setEntityCallbacks(ReactiveEntityCallbacks.create(afterConvertCallback));
List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, Person.class, index) List<SearchHit<Person>> results = template.search(pagedQueryForTwo(), Person.class, Person.class, index)
.timeout(Duration.ofSeconds(1)).toStream() .timeout(Duration.ofSeconds(1)).toStream().collect(Collectors.toList());
.collect(Collectors.toList());
verify(afterConvertCallback, times(2)) verify(afterConvertCallback, times(2)).onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()),
.onAfterConvert(eq(new Person("init", "luke")), eq(lukeDocument()), eq(index)); eq(index));
assertThat(results.get(0).getContent().id).isEqualTo("after-convert"); assertThat(results.get(0).getContent().id).isEqualTo("after-convert");
assertThat(results.get(1).getContent().id).isEqualTo("after-convert"); assertThat(results.get(1).getContent().id).isEqualTo("after-convert");
} }

View File

@ -34,8 +34,9 @@ class SearchHitSupportTest {
void unwrapsSearchHitsIteratorToCloseableIteratorOfEntities() { void unwrapsSearchHitsIteratorToCloseableIteratorOfEntities() {
TestStringSearchHitsIterator searchHitsIterator = new TestStringSearchHitsIterator(); TestStringSearchHitsIterator searchHitsIterator = new TestStringSearchHitsIterator();
@SuppressWarnings("unchecked") CloseableIterator<String> unwrappedIterator = @SuppressWarnings("unchecked")
(CloseableIterator<String>) SearchHitSupport.unwrapSearchHits(searchHitsIterator); CloseableIterator<String> unwrappedIterator = (CloseableIterator<String>) SearchHitSupport
.unwrapSearchHits(searchHitsIterator);
assertThat(unwrappedIterator.next()).isEqualTo("one"); assertThat(unwrappedIterator.next()).isEqualTo("one");
assertThat(unwrappedIterator.next()).isEqualTo("two"); assertThat(unwrappedIterator.next()).isEqualTo("two");