DATAES-799 - Polishing.
This commit is contained in:
@@ -25,8 +25,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Roman Puchkovskiy
|
||||
*/
|
||||
@@ -48,8 +46,8 @@ class ElasticsearchExceptionTranslatorTests {
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldConvertVersionConflictEngineExceptionWithSeqNoConflictToOptimisticLockingFailureException() {
|
||||
VersionConflictEngineException ex = new VersionConflictEngineException(
|
||||
new ShardId("index", "uuid", 1), "exception-id",
|
||||
VersionConflictEngineException ex = new VersionConflictEngineException(new ShardId("index", "uuid", 1),
|
||||
"exception-id",
|
||||
"Elasticsearch exception [type=version_conflict_engine_exception, reason=[WPUUsXEB6uuA6j8_A7AB]: version conflict, required seqNo [34], primary term [16]. current document has seqNo [35] and primary term [16]]");
|
||||
|
||||
DataAccessException translated = translator.translateExceptionIfPossible(ex);
|
||||
@@ -58,4 +56,4 @@ class ElasticsearchExceptionTranslatorTests {
|
||||
assertThat(translated.getMessage()).startsWith("Cannot index a document due to seq_no+primary_term conflict");
|
||||
assertThat(translated.getCause()).isSameAs(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,16 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.Query;
|
||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.junit.junit4.ElasticsearchVersion;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -858,10 +867,8 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = template.save(original).block();
|
||||
|
||||
template.get(saved.getId(), OptimisticEntity.class)
|
||||
.as(StepVerifier::create)
|
||||
.assertNext(this::assertThatSeqNoPrimaryTermIsFilled)
|
||||
.verifyComplete();
|
||||
template.get(saved.getId(), OptimisticEntity.class).as(StepVerifier::create)
|
||||
.assertNext(this::assertThatSeqNoPrimaryTermIsFilled).verifyComplete();
|
||||
}
|
||||
|
||||
private void assertThatSeqNoPrimaryTermIsFilled(OptimisticEntity retrieved) {
|
||||
@@ -878,10 +885,10 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
original.setMessage("It's fine");
|
||||
OptimisticEntity saved = template.save(original).block();
|
||||
|
||||
template.multiGet(multiGetQueryForOne(saved.getId()), OptimisticEntity.class, template.getIndexCoordinatesFor(OptimisticEntity.class))
|
||||
.as(StepVerifier::create)
|
||||
.assertNext(this::assertThatSeqNoPrimaryTermIsFilled)
|
||||
.verifyComplete();
|
||||
template
|
||||
.multiGet(multiGetQueryForOne(saved.getId()), OptimisticEntity.class,
|
||||
template.getIndexCoordinatesFor(OptimisticEntity.class))
|
||||
.as(StepVerifier::create).assertNext(this::assertThatSeqNoPrimaryTermIsFilled).verifyComplete();
|
||||
}
|
||||
|
||||
private Query multiGetQueryForOne(String id) {
|
||||
@@ -895,17 +902,15 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
OptimisticEntity saved = template.save(original).block();
|
||||
restTemplate.refresh(OptimisticEntity.class);
|
||||
|
||||
template.search(searchQueryForOne(saved.getId()), OptimisticEntity.class, template.getIndexCoordinatesFor(OptimisticEntity.class))
|
||||
.map(SearchHit::getContent)
|
||||
.as(StepVerifier::create)
|
||||
.assertNext(this::assertThatSeqNoPrimaryTermIsFilled)
|
||||
template
|
||||
.search(searchQueryForOne(saved.getId()), OptimisticEntity.class,
|
||||
template.getIndexCoordinatesFor(OptimisticEntity.class))
|
||||
.map(SearchHit::getContent).as(StepVerifier::create).assertNext(this::assertThatSeqNoPrimaryTermIsFilled)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
private Query searchQueryForOne(String id) {
|
||||
return new NativeSearchQueryBuilder()
|
||||
.withFilter(new IdsQueryBuilder().addIds(id))
|
||||
.build();
|
||||
return new NativeSearchQueryBuilder().withFilter(new IdsQueryBuilder().addIds(id)).build();
|
||||
}
|
||||
|
||||
@Test // DATAES-799
|
||||
@@ -921,12 +926,9 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
template.save(forEdit1).block();
|
||||
|
||||
forEdit2.setMessage("It'll be great");
|
||||
template.save(forEdit2)
|
||||
.as(StepVerifier::create)
|
||||
.expectError(OptimisticLockingFailureException.class)
|
||||
.verify();
|
||||
template.save(forEdit2).as(StepVerifier::create).expectError(OptimisticLockingFailureException.class).verify();
|
||||
}
|
||||
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldThrowOptimisticLockingFailureExceptionWhenConcurrentUpdateOccursOnVersionedEntityWithSeqNoPrimaryTermProperty() {
|
||||
OptimisticAndVersionedEntity original = new OptimisticAndVersionedEntity();
|
||||
@@ -940,10 +942,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
template.save(forEdit1).block();
|
||||
|
||||
forEdit2.setMessage("It'll be great");
|
||||
template.save(forEdit2)
|
||||
.as(StepVerifier::create)
|
||||
.expectError(OptimisticLockingFailureException.class)
|
||||
.verify();
|
||||
template.save(forEdit2).as(StepVerifier::create).expectError(OptimisticLockingFailureException.class).verify();
|
||||
}
|
||||
|
||||
@Test // DATAES-799
|
||||
@@ -955,10 +954,7 @@ public class ReactiveElasticsearchTemplateTests {
|
||||
OptimisticAndVersionedEntity forEdit = template.get(saved.getId(), OptimisticAndVersionedEntity.class).block();
|
||||
|
||||
forEdit.setMessage("It'll be ok");
|
||||
template.save(forEdit)
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
template.save(forEdit).as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -233,8 +233,8 @@ class RequestFactoryTests {
|
||||
when(client.prepareSearch(any())).thenReturn(new SearchRequestBuilder(client, SearchAction.INSTANCE));
|
||||
Query query = new NativeSearchQueryBuilder().build();
|
||||
|
||||
SearchRequestBuilder builder = requestFactory.searchRequestBuilder(client, query,
|
||||
EntityWithSeqNoPrimaryTerm.class, IndexCoordinates.of("seqNoPrimaryTerm"));
|
||||
SearchRequestBuilder builder = requestFactory.searchRequestBuilder(client, query, EntityWithSeqNoPrimaryTerm.class,
|
||||
IndexCoordinates.of("seqNoPrimaryTerm"));
|
||||
|
||||
assertThat(builder.request().source().seqNoAndPrimaryTerm()).isTrue();
|
||||
}
|
||||
|
||||
@@ -703,7 +703,7 @@ public class MappingElasticsearchConverterUnitTests {
|
||||
EntityWithSeqNoPrimaryTerm entity = new EntityWithSeqNoPrimaryTerm();
|
||||
entity.seqNoPrimaryTerm = new SeqNoPrimaryTerm(1L, 2L);
|
||||
Document document = Document.create();
|
||||
|
||||
|
||||
mappingElasticsearchConverter.write(entity, document);
|
||||
|
||||
assertThat(document).doesNotContainKey("seqNoPrimaryTerm");
|
||||
@@ -926,7 +926,8 @@ public class MappingElasticsearchConverterUnitTests {
|
||||
}
|
||||
|
||||
@Data
|
||||
@org.springframework.data.elasticsearch.annotations.Document(indexName = "test-index-entity-with-seq-no-primary-term-mapper")
|
||||
@org.springframework.data.elasticsearch.annotations.Document(
|
||||
indexName = "test-index-entity-with-seq-no-primary-term-mapper")
|
||||
static class EntityWithSeqNoPrimaryTerm {
|
||||
|
||||
@Nullable private SeqNoPrimaryTerm seqNoPrimaryTerm;
|
||||
|
||||
@@ -579,7 +579,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
@Test // DATAES-799
|
||||
void shouldNotIncludeSeqNoPrimaryTermPropertyInMappingEvenWhenAnnotatedWithField() {
|
||||
String propertyMapping = getMappingBuilder().buildPropertyMapping(EntityWithSeqNoPrimaryTerm.class);
|
||||
|
||||
|
||||
assertThat(propertyMapping).doesNotContain("seqNoPrimaryTerm");
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,8 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldReportThatThereIsNoSeqNoPrimaryTermPropertyWhenThereIsNoSuchProperty() {
|
||||
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = ClassTypeInformation.from(EntityWithoutSeqNoPrimaryTerm.class);
|
||||
TypeInformation<EntityWithoutSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
|
||||
.from(EntityWithoutSeqNoPrimaryTerm.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithoutSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
@@ -108,7 +109,8 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldReportThatThereIsSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
|
||||
.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
@@ -119,7 +121,8 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldReturnSeqNoPrimaryTermPropertyWhenThereIsSuchProperty() {
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
|
||||
.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));
|
||||
@@ -134,7 +137,8 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test // DATAES-799
|
||||
void shouldNotAllowMoreThanOneSeqNoPrimaryTermProperties() {
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
TypeInformation<EntityWithSeqNoPrimaryTerm> typeInformation = ClassTypeInformation
|
||||
.from(EntityWithSeqNoPrimaryTerm.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithSeqNoPrimaryTerm> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
entity.addPersistentProperty(createProperty(entity, "seqNoPrimaryTerm"));
|
||||
@@ -202,8 +206,7 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
@Nullable @Field(name = "renamed-field") private String renamedField;
|
||||
}
|
||||
|
||||
private static class EntityWithoutSeqNoPrimaryTerm {
|
||||
}
|
||||
private static class EntityWithoutSeqNoPrimaryTerm {}
|
||||
|
||||
private static class EntityWithSeqNoPrimaryTerm {
|
||||
private SeqNoPrimaryTerm seqNoPrimaryTerm;
|
||||
|
||||
@@ -49,4 +49,4 @@ class SeqNoPrimaryTermTests {
|
||||
assertThatThrownBy(() -> new SeqNoPrimaryTerm(1, SequenceNumbers.UNASSIGNED_PRIMARY_TERM))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user