mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-29 16:22:10 +00:00
DATAES-976 - Polishing.
Use deleteAllById(…) from deleteAll(…). Simplify implementation in SimpleReactiveElasticsearchRepository. Original pull request: #554.
This commit is contained in:
parent
749270ba25
commit
9bf6b6a984
@ -166,7 +166,7 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate {
|
||||
public <T> List<T> multiGet(Query query, Class<T> clazz, IndexCoordinates index) {
|
||||
|
||||
Assert.notNull(index, "index must not be null");
|
||||
Assert.notEmpty(query.getIds(), "No Id define for Query");
|
||||
Assert.notEmpty(query.getIds(), "No Id defined for Query");
|
||||
|
||||
MultiGetRequest request = requestFactory.multiGetRequest(query, clazz, index);
|
||||
MultiGetResponse result = execute(client -> client.mget(request, RequestOptions.DEFAULT));
|
||||
|
@ -27,6 +27,7 @@ import org.elasticsearch.index.query.IdsQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@ -37,7 +38,6 @@ import org.springframework.data.elasticsearch.core.IndexOperations;
|
||||
import org.springframework.data.elasticsearch.core.SearchHit;
|
||||
import org.springframework.data.elasticsearch.core.SearchHitSupport;
|
||||
import org.springframework.data.elasticsearch.core.SearchHits;
|
||||
import org.springframework.data.elasticsearch.core.SearchPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
@ -50,6 +50,7 @@ import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Elasticsearch specific repository implementation. Likely to be used as target within
|
||||
@ -151,14 +152,12 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
Assert.notNull(ids, "ids can't be null.");
|
||||
|
||||
List<T> result = new ArrayList<>();
|
||||
List<String> stringIds = stringIdsRepresentation(ids);
|
||||
|
||||
if (stringIds.isEmpty()) {
|
||||
Query idQuery = getIdQuery(ids);
|
||||
if (CollectionUtils.isEmpty(idQuery.getIds())) {
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder().withIds(stringIds).build();
|
||||
List<T> multiGetEntities = execute(operations -> operations.multiGet(query, entityClass, getIndexCoordinates()));
|
||||
List<T> multiGetEntities = execute(operations -> operations.multiGet(idQuery, entityClass, getIndexCoordinates()));
|
||||
|
||||
if (multiGetEntities != null) {
|
||||
multiGetEntities.forEach(entity -> {
|
||||
@ -290,32 +289,6 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
doDelete(extractIdFromBean(entity), operations.getEntityRouting(entity), getIndexCoordinates());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
Assert.notNull(entities, "Cannot delete 'null' list.");
|
||||
|
||||
IndexCoordinates indexCoordinates = getIndexCoordinates();
|
||||
IdsQueryBuilder idsQueryBuilder = idsQuery();
|
||||
for (T entity : entities) {
|
||||
ID id = extractIdFromBean(entity);
|
||||
if (id != null) {
|
||||
idsQueryBuilder.addIds(stringIdRepresentation(id));
|
||||
}
|
||||
}
|
||||
|
||||
if (idsQueryBuilder.ids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build();
|
||||
|
||||
executeAndRefresh((OperationsCallback<Void>) operations -> {
|
||||
operations.delete(query, entityClass, indexCoordinates);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
@ -324,23 +297,36 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
IndexCoordinates indexCoordinates = getIndexCoordinates();
|
||||
IdsQueryBuilder idsQueryBuilder = idsQuery();
|
||||
for (ID id : ids) {
|
||||
if (id != null) {
|
||||
idsQueryBuilder.addIds(stringIdRepresentation(id));
|
||||
}
|
||||
idsQueryBuilder.addIds(stringIdRepresentation(id));
|
||||
}
|
||||
|
||||
if (idsQueryBuilder.ids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build();
|
||||
|
||||
executeAndRefresh((OperationsCallback<Void>) operations -> {
|
||||
operations.delete(query, entityClass, indexCoordinates);
|
||||
operations.delete(new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build(), entityClass,
|
||||
indexCoordinates);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
Assert.notNull(entities, "Cannot delete 'null' list.");
|
||||
|
||||
List<ID> ids = new ArrayList<>();
|
||||
for (T entity : entities) {
|
||||
ID id = extractIdFromBean(entity);
|
||||
if (id != null) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
deleteAllById(ids);
|
||||
}
|
||||
|
||||
private void doDelete(@Nullable ID id, @Nullable String routing, IndexCoordinates indexCoordinates) {
|
||||
|
||||
if (id != null) {
|
||||
@ -369,7 +355,7 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
return entityInformation.getId(entity);
|
||||
}
|
||||
|
||||
private List<String> stringIdsRepresentation(Iterable<ID> ids) {
|
||||
private List<String> stringIdsRepresentation(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "ids can't be null.");
|
||||
|
||||
@ -385,6 +371,12 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
return operations.getIndexCoordinatesFor(entityClass);
|
||||
}
|
||||
|
||||
private Query getIdQuery(Iterable<? extends ID> ids) {
|
||||
List<String> stringIds = stringIdsRepresentation(ids);
|
||||
|
||||
return new NativeSearchQueryBuilder().withIds(stringIds).build();
|
||||
}
|
||||
|
||||
// region operations callback
|
||||
@FunctionalInterface
|
||||
public interface OperationsCallback<R> {
|
||||
|
@ -15,14 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
import org.elasticsearch.index.query.IdsQueryBuilder;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||
@ -33,9 +34,7 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@ -167,7 +166,7 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
||||
|
||||
Assert.notNull(idStream, "IdStream must not be null!");
|
||||
return Flux.from(idStream) //
|
||||
.map(ID::toString) //
|
||||
.map(this::convertId) //
|
||||
.collectList() //
|
||||
.map(ids -> new NativeSearchQueryBuilder().withIds(ids).build()) //
|
||||
.flatMapMany(query -> {
|
||||
@ -206,6 +205,20 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
||||
.then(doRefresh());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "Ids must not be null!");
|
||||
|
||||
return Flux.fromIterable(ids) //
|
||||
.map(this::convertId) //
|
||||
.collectList() //
|
||||
.map(it -> new NativeSearchQueryBuilder().withQuery(new IdsQueryBuilder().addIds(it.toArray(new String[0])))
|
||||
.build())
|
||||
.flatMap(it -> operations.delete(it, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) //
|
||||
.then(doRefresh());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
|
||||
|
||||
@ -213,36 +226,16 @@ public class SimpleReactiveElasticsearchRepository<T, ID> implements ReactiveEla
|
||||
return deleteAll(Flux.fromIterable(entities));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "Ids must not be null!");
|
||||
|
||||
return Mono.just(Streamable.of(ids) //
|
||||
.map(this::convertId).toList() //
|
||||
).map(objects -> new StringQuery(QueryBuilders.idsQuery() //
|
||||
.addIds(objects.toArray(new String[0])) //
|
||||
.toString()) //
|
||||
).flatMap(
|
||||
query -> operations.delete(query, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) //
|
||||
.then(doRefresh());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAll(Publisher<? extends T> entityStream) {
|
||||
|
||||
Assert.notNull(entityStream, "EntityStream must not be null!");
|
||||
return Flux.from(entityStream) //
|
||||
.map(entity -> {
|
||||
|
||||
ID id = entityInformation.getId(entity);
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("Entity id must not be null!");
|
||||
}
|
||||
return convertId(id);
|
||||
}).collectList().map(objects -> new StringQuery(QueryBuilders.idsQuery() //
|
||||
.addIds(objects.toArray(new String[0])) //
|
||||
.toString())) //
|
||||
.map(entityInformation::getRequiredId) //
|
||||
.map(this::convertId) //
|
||||
.collectList() //
|
||||
.map(it -> new NativeSearchQueryBuilder().withQuery(new IdsQueryBuilder().addIds(it.toArray(new String[0])))
|
||||
.build())
|
||||
.flatMap(
|
||||
query -> operations.delete(query, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) //
|
||||
.then(doRefresh());
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.core.query.Query.*;
|
||||
@ -31,6 +30,7 @@ import reactor.test.StepVerifier;
|
||||
import java.lang.Boolean;
|
||||
import java.lang.Long;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -69,7 +69,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { SimpleReactiveElasticsearchRepositoryTests.Config.class })
|
||||
public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
class SimpleReactiveElasticsearchRepositoryTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ ReactiveElasticsearchRestTemplateConfiguration.class })
|
||||
@ -82,7 +82,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired ReactiveSampleEntityRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
operations.indexOps(IndexCoordinates.of(INDEX)).delete().block();
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void saveShouldSaveSingleEntity() {
|
||||
void saveShouldSaveSingleEntity() {
|
||||
|
||||
repository.save(SampleEntity.builder().build()) //
|
||||
.map(SampleEntity::getId) //
|
||||
@ -106,10 +106,10 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void saveShouldComputeMultipleEntities() {
|
||||
void saveShouldComputeMultipleEntities() {
|
||||
|
||||
repository
|
||||
.saveAll(asList(SampleEntity.builder().build(), SampleEntity.builder().build(),
|
||||
.saveAll(Arrays.asList(SampleEntity.builder().build(), SampleEntity.builder().build(),
|
||||
SampleEntity.builder().build())) //
|
||||
.map(SampleEntity::getId) //
|
||||
.flatMap(this::documentWithIdExistsInIndex) //
|
||||
@ -121,14 +121,14 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519, DATAES-767, DATAES-822
|
||||
public void findByIdShouldErrorIfIndexDoesNotExist() {
|
||||
void findByIdShouldErrorIfIndexDoesNotExist() {
|
||||
repository.findById("id-two") //
|
||||
.as(StepVerifier::create) //
|
||||
.expectError(ElasticsearchStatusException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findShouldRetrieveSingleEntityById() {
|
||||
void findShouldRetrieveSingleEntityById() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build(), //
|
||||
@ -141,7 +141,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findByIdShouldCompleteIfNothingFound() {
|
||||
void findByIdShouldCompleteIfNothingFound() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build(), //
|
||||
@ -153,7 +153,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-720
|
||||
public void findAllShouldReturnAllElements() {
|
||||
void findAllShouldReturnAllElements() {
|
||||
// make sure to be above the default page size of the Query interface
|
||||
int count = DEFAULT_PAGE_SIZE * 2;
|
||||
bulkIndex(IntStream.range(1, count + 1) //
|
||||
@ -168,19 +168,19 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findAllByIdByIdShouldCompleteIfIndexDoesNotExist() {
|
||||
repository.findAllById(asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete();
|
||||
void findAllByIdByIdShouldCompleteIfIndexDoesNotExist() {
|
||||
repository.findAllById(Arrays.asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findAllByIdShouldRetrieveMatchingDocuments() {
|
||||
void findAllByIdShouldRetrieveMatchingDocuments() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build(), //
|
||||
SampleEntity.builder().id("id-three").build()) //
|
||||
.block();
|
||||
|
||||
repository.findAllById(asList("id-one", "id-two")) //
|
||||
repository.findAllById(Arrays.asList("id-one", "id-two")) //
|
||||
.as(StepVerifier::create)//
|
||||
.expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) //
|
||||
.expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) //
|
||||
@ -188,14 +188,14 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void findAllByIdShouldCompleteWhenNothingFound() {
|
||||
void findAllByIdShouldCompleteWhenNothingFound() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build(), //
|
||||
SampleEntity.builder().id("id-three").build()) //
|
||||
.block();
|
||||
|
||||
repository.findAllById(asList("can't", "touch", "this")) //
|
||||
repository.findAllById(Arrays.asList("can't", "touch", "this")) //
|
||||
.as(StepVerifier::create)//
|
||||
.verifyComplete();
|
||||
}
|
||||
@ -267,14 +267,14 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519, DATAES-767, DATAES-822
|
||||
public void countShouldErrorWhenIndexDoesNotExist() {
|
||||
void countShouldErrorWhenIndexDoesNotExist() {
|
||||
repository.count() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectError(ElasticsearchStatusException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void countShouldCountDocuments() {
|
||||
void countShouldCountDocuments() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build()) //
|
||||
@ -284,7 +284,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void existsByIdShouldReturnTrueIfExists() {
|
||||
void existsByIdShouldReturnTrueIfExists() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -298,7 +298,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void existsByIdShouldReturnFalseIfNotExists() {
|
||||
void existsByIdShouldReturnFalseIfNotExists() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -312,7 +312,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void countShouldCountMatchingDocuments() {
|
||||
void countShouldCountMatchingDocuments() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -326,7 +326,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void existsShouldReturnTrueIfExists() {
|
||||
void existsShouldReturnTrueIfExists() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -340,7 +340,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void existsShouldReturnFalseIfNotExists() {
|
||||
void existsShouldReturnFalseIfNotExists() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -354,7 +354,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteByIdShouldCompleteIfNothingDeleted() {
|
||||
void deleteByIdShouldCompleteIfNothingDeleted() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build()) //
|
||||
@ -364,14 +364,14 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519, DATAES-767, DATAES-822, DATAES-678
|
||||
public void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||
void deleteByIdShouldCompleteWhenIndexDoesNotExist() {
|
||||
repository.deleteById("does-not-exist") //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteByIdShouldDeleteEntry() {
|
||||
void deleteByIdShouldDeleteEntry() {
|
||||
|
||||
SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build();
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) //
|
||||
@ -383,19 +383,19 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-976
|
||||
public void deleteAllByIdShouldDeleteEntry() {
|
||||
void deleteAllByIdShouldDeleteEntry() {
|
||||
|
||||
SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build();
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) //
|
||||
.block();
|
||||
|
||||
repository.deleteAllById(asList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete();
|
||||
repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete();
|
||||
|
||||
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteShouldDeleteEntry() {
|
||||
void deleteShouldDeleteEntry() {
|
||||
|
||||
SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build();
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) //
|
||||
@ -407,7 +407,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteAllShouldDeleteGivenEntries() {
|
||||
void deleteAllShouldDeleteGivenEntries() {
|
||||
|
||||
SampleEntity toBeDeleted = SampleEntity.builder().id("id-one").build();
|
||||
SampleEntity hangInThere = SampleEntity.builder().id("id-two").build();
|
||||
@ -416,7 +416,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
bulkIndex(toBeDeleted, hangInThere, toBeDeleted2) //
|
||||
.block();
|
||||
|
||||
repository.deleteAll(asList(toBeDeleted, toBeDeleted2)).as(StepVerifier::create).verifyComplete();
|
||||
repository.deleteAll(Arrays.asList(toBeDeleted, toBeDeleted2)).as(StepVerifier::create).verifyComplete();
|
||||
|
||||
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
|
||||
assertThat(documentWithIdExistsInIndex(toBeDeleted2.getId()).block()).isFalse();
|
||||
@ -424,7 +424,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void deleteAllShouldDeleteAllEntries() {
|
||||
void deleteAllShouldDeleteAllEntries() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").build(), //
|
||||
SampleEntity.builder().id("id-two").build(), //
|
||||
@ -440,7 +440,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderMethodShouldBeExecutedCorrectly() {
|
||||
void derivedFinderMethodShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -454,7 +454,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderMethodShouldBeExecutedCorrectlyWhenGivenPublisher() {
|
||||
void derivedFinderMethodShouldBeExecutedCorrectlyWhenGivenPublisher() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -468,7 +468,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() {
|
||||
void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), //
|
||||
SampleEntity.builder().id("id-two").message("test test").rate(1).build(), //
|
||||
@ -484,7 +484,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() {
|
||||
void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), //
|
||||
SampleEntity.builder().id("id-two").message("test test").rate(1).build(), //
|
||||
@ -500,7 +500,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() {
|
||||
void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), //
|
||||
SampleEntity.builder().id("id-two").message("test test").rate(1).build(), //
|
||||
@ -515,7 +515,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedFinderMethodReturningMonoShouldBeExecutedCorrectly() {
|
||||
void derivedFinderMethodReturningMonoShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -529,7 +529,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void annotatedFinderMethodShouldBeExecutedCorrectly() {
|
||||
void annotatedFinderMethodShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -543,7 +543,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-519
|
||||
public void derivedDeleteMethodShouldBeExecutedCorrectly() {
|
||||
void derivedDeleteMethodShouldBeExecutedCorrectly() {
|
||||
|
||||
bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), //
|
||||
SampleEntity.builder().id("id-two").message("test message").build(), //
|
||||
@ -561,7 +561,7 @@ public class SimpleReactiveElasticsearchRepositoryTests {
|
||||
}
|
||||
|
||||
Mono<Void> bulkIndex(SampleEntity... entities) {
|
||||
return operations.saveAll(asList(entities), IndexCoordinates.of(INDEX)).then();
|
||||
return operations.saveAll(Arrays.asList(entities), IndexCoordinates.of(INDEX)).then();
|
||||
}
|
||||
|
||||
interface ReactiveSampleEntityRepository extends ReactiveCrudRepository<SampleEntity, String> {
|
||||
|
@ -76,7 +76,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
*/
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { SimpleElasticsearchRepositoryIntegrationTests.Config.class })
|
||||
public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||
@ -91,7 +91,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
private IndexOperations indexOperations;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
void before() {
|
||||
indexOperations = operations.indexOps(SampleEntity.class);
|
||||
IndexInitializer.init(indexOperations);
|
||||
}
|
||||
@ -102,7 +102,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoBulkIndexDocument() {
|
||||
void shouldDoBulkIndexDocument() {
|
||||
|
||||
// given
|
||||
String documentId1 = nextIdAsString();
|
||||
@ -129,7 +129,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDocument() {
|
||||
void shouldSaveDocument() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -147,7 +147,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwExceptionWhenTryingToInsertWithVersionButWithoutId() {
|
||||
void throwExceptionWhenTryingToInsertWithVersionButWithoutId() {
|
||||
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
@ -159,7 +159,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindDocumentById() {
|
||||
void shouldFindDocumentById() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -178,7 +178,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCountOfDocuments() {
|
||||
void shouldReturnCountOfDocuments() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -196,7 +196,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindAllDocuments() {
|
||||
void shouldFindAllDocuments() {
|
||||
|
||||
// when
|
||||
Iterable<SampleEntity> results = repository.findAll();
|
||||
@ -206,7 +206,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteDocument() {
|
||||
void shouldDeleteDocument() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -225,7 +225,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenSearchQuery() {
|
||||
void shouldSearchDocumentsGivenSearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -246,7 +246,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchDocumentsGivenElasticsearchQuery() {
|
||||
void shouldSearchDocumentsGivenElasticsearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -265,7 +265,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-82
|
||||
public void shouldFindAllByIdQuery() {
|
||||
void shouldFindAllByIdQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -290,7 +290,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveIterableEntities() {
|
||||
void shouldSaveIterableEntities() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -316,7 +316,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnTrueGivenDocumentWithIdExists() {
|
||||
void shouldReturnTrueGivenDocumentWithIdExists() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -334,7 +334,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-363
|
||||
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
|
||||
void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -347,7 +347,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnResultsForGivenSearchQuery() {
|
||||
void shouldReturnResultsForGivenSearchQuery() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -366,7 +366,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteAll() {
|
||||
void shouldDeleteAll() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -386,7 +386,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteById() {
|
||||
void shouldDeleteById() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -407,7 +407,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test //DATAES-976
|
||||
public void shouldDeleteAllById() {
|
||||
void shouldDeleteAllById() {
|
||||
|
||||
// given
|
||||
String id1 = nextIdAsString();
|
||||
@ -441,7 +441,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteByMessageAndReturnList() {
|
||||
void shouldDeleteByMessageAndReturnList() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -477,7 +477,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteByListForMessage() {
|
||||
void shouldDeleteByListForMessage() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -510,7 +510,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteByType() {
|
||||
void shouldDeleteByType() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -542,7 +542,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteEntity() {
|
||||
void shouldDeleteEntity() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -562,7 +562,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIterableEntities() {
|
||||
void shouldReturnIterableEntities() {
|
||||
|
||||
// given
|
||||
String documentId1 = nextIdAsString();
|
||||
@ -587,7 +587,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeleteIterableEntities() {
|
||||
void shouldDeleteIterableEntities() {
|
||||
|
||||
// given
|
||||
String documentId1 = nextIdAsString();
|
||||
@ -614,7 +614,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexEntity() {
|
||||
void shouldIndexEntity() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -632,7 +632,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexWithoutRefreshEntity() {
|
||||
void shouldIndexWithoutRefreshEntity() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -655,7 +655,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSortByGivenField() {
|
||||
void shouldSortByGivenField() {
|
||||
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
@ -678,7 +678,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSimilarEntities() {
|
||||
void shouldReturnSimilarEntities() {
|
||||
|
||||
// given
|
||||
String sampleMessage = "So we build a web site or an application and want to add search to it, "
|
||||
@ -699,7 +699,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-142
|
||||
public void shouldIndexNotEmptyList() {
|
||||
void shouldIndexNotEmptyList() {
|
||||
// given
|
||||
List<SampleEntity> list = new ArrayList<>();
|
||||
String documentId = nextIdAsString();
|
||||
@ -720,7 +720,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-142
|
||||
public void shouldNotFailOnIndexingEmptyList() {
|
||||
void shouldNotFailOnIndexingEmptyList() {
|
||||
Iterable<SampleEntity> savedEntities = repository.saveAll(Collections.emptyList());
|
||||
|
||||
assertThat(savedEntities).hasSize(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user