|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.core;
|
17 | 17 |
|
18 |
| -import static java.util.Collections.singletonList; |
| 18 | +import static java.util.Collections.*; |
19 | 19 | import static org.assertj.core.api.Assertions.*;
|
20 |
| -import static org.springframework.data.elasticsearch.annotations.Document.VersionType.EXTERNAL_GTE; |
| 20 | +import static org.springframework.data.elasticsearch.annotations.Document.VersionType.*; |
21 | 21 | import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
22 | 22 | import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
23 |
| -import static org.springframework.data.elasticsearch.core.document.Document.create; |
24 |
| -import static org.springframework.data.elasticsearch.core.query.StringQuery.MATCH_ALL; |
25 |
| -import static org.springframework.data.elasticsearch.utils.IdGenerator.nextIdAsString; |
26 |
| -import static org.springframework.data.elasticsearch.utils.IndexBuilder.buildIndex; |
| 23 | +import static org.springframework.data.elasticsearch.core.document.Document.*; |
| 24 | +import static org.springframework.data.elasticsearch.core.query.StringQuery.*; |
| 25 | +import static org.springframework.data.elasticsearch.utils.IdGenerator.*; |
| 26 | +import static org.springframework.data.elasticsearch.utils.IndexBuilder.*; |
27 | 27 |
|
28 | 28 | import java.lang.Double;
|
29 | 29 | import java.lang.Integer;
|
|
50 | 50 | import org.springframework.data.domain.Pageable;
|
51 | 51 | import org.springframework.data.domain.Sort;
|
52 | 52 | import org.springframework.data.elasticsearch.BulkFailureException;
|
| 53 | +import org.springframework.data.elasticsearch.VersionConflictException; |
53 | 54 | import org.springframework.data.elasticsearch.annotations.*;
|
54 | 55 | import org.springframework.data.elasticsearch.annotations.Field;
|
55 | 56 | import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
@@ -2008,7 +2009,7 @@ public void shouldIndexGteEntityWithVersionType() {
|
2008 | 2009 |
|
2009 | 2010 | // reindex with version one below
|
2010 | 2011 | assertThatThrownBy(() -> operations.index(indexQueryBuilder.withVersion(entity.getVersion() - 1).build(), index))
|
2011 |
| - .hasMessageContaining("version").hasMessageContaining("conflict"); |
| 2012 | + .isInstanceOf(VersionConflictException.class); |
2012 | 2013 | }
|
2013 | 2014 |
|
2014 | 2015 | @Test
|
@@ -3639,6 +3640,18 @@ void shouldFailWithConflictOnAttemptToSaveWithSameVersion() {
|
3639 | 3640 | .allMatch(failureStatus -> failureStatus.status().equals(409));
|
3640 | 3641 | }
|
3641 | 3642 |
|
| 3643 | + @Test // #2467 |
| 3644 | + @DisplayName("should throw VersionConflictException when saving invalid version") |
| 3645 | + void shouldThrowVersionConflictExceptionWhenSavingInvalidVersion() { |
| 3646 | + |
| 3647 | + var entity = new VersionedEntity("42", 1L); |
| 3648 | + operations.save(entity); |
| 3649 | + |
| 3650 | + assertThatThrownBy(() -> { |
| 3651 | + operations.save(entity); |
| 3652 | + }).isInstanceOf(VersionConflictException.class); |
| 3653 | + } |
| 3654 | + |
3642 | 3655 | // region entities
|
3643 | 3656 | @Document(indexName = "#{@indexNameProvider.indexName()}")
|
3644 | 3657 | @Setting(shards = 1, replicas = 0, refreshInterval = "-1")
|
@@ -4431,6 +4444,13 @@ static class VersionedEntity {
|
4431 | 4444 | @Nullable
|
4432 | 4445 | @Version private Long version;
|
4433 | 4446 |
|
| 4447 | + public VersionedEntity() {} |
| 4448 | + |
| 4449 | + public VersionedEntity(@Nullable String id, @Nullable java.lang.Long version) { |
| 4450 | + this.id = id; |
| 4451 | + this.version = version; |
| 4452 | + } |
| 4453 | + |
4434 | 4454 | @Nullable
|
4435 | 4455 | public String getId() {
|
4436 | 4456 | return id;
|
|
0 commit comments