From 5abebb570e15a2474398f3364c5d017df8ecaced Mon Sep 17 00:00:00 2001 From: Andrey G Date: Sun, 1 Sep 2024 12:51:52 +0300 Subject: [PATCH] FMWK-428 Refactor tests (#771) --- .../reference/query-methods-modification.adoc | 4 +- src/main/asciidoc/reference/template.adoc | 2 +- .../data/aerospike/query/FilterOperation.java | 10 +- .../query/AerospikeQueryCreatorUtils.java | 2 +- .../core/AerospikeTemplateIndexTests.java | 294 ---------------- ...iveAerospikeTemplateCountRelatedTests.java | 13 +- ...ReactiveAerospikeTemplateFindAllTests.java | 55 +++ ...veAerospikeTemplateFindByEntitiesTest.java | 2 +- ...pikeTemplateFindByQueryProjectionTest.java | 19 - ...tiveAerospikeTemplateFindByQueryTests.java | 131 ------- ...tiveAerospikeTemplateFindInRangeTests.java | 95 +++++ .../ReactiveAerospikeTemplateIndexTests.java | 223 ------------ .../AbstractFindByEntitiesTest.java | 2 +- .../{ => sync}/AerospikeExpirationTests.java | 2 +- .../{ => sync}/AerospikeTemplateAddTests.java | 2 +- .../AerospikeTemplateAppendTests.java | 2 +- .../AerospikeTemplateCompositeKeyTests.java | 2 +- .../AerospikeTemplateCountTests.java | 17 +- .../AerospikeTemplateDeleteTests.java | 2 +- .../AerospikeTemplateExecuteTests.java | 2 +- .../AerospikeTemplateExistsTests.java | 2 +- .../sync/AerospikeTemplateFindAllTests.java | 75 ++++ .../AerospikeTemplateFindByEntitiesTests.java | 2 +- ...ospikeTemplateFindByIdProjectionTests.java | 2 +- .../AerospikeTemplateFindByIdTests.java | 2 +- ...ikeTemplateFindByQueryProjectionTests.java | 22 +- .../AerospikeTemplateFindByQueryTests.java | 121 +------ .../AerospikeTemplateFindInRangeTests.java | 80 +++++ .../AerospikeTemplateInsertTests.java | 2 +- .../AerospikeTemplatePersistTests.java | 3 +- .../AerospikeTemplatePrependTests.java | 2 +- ...erospikeTemplateQueryAggregationTests.java | 2 +- .../AerospikeTemplateSaveTests.java | 2 +- .../AerospikeTemplateUpdateTests.java | 2 +- .../{ => sync}/AutoIndexedDocumentAssert.java | 2 +- ...faultAerospikeExceptionTranslatorTest.java | 3 +- .../{ => sync}/WritePolicyBuilderTest.java | 3 +- .../data/aerospike/logging/LoggingTests.java | 5 +- .../query/IndexedQualifierTests.java | 299 ---------------- .../data/aerospike/query/UsersTests.java | 48 --- .../aerospike/query/cache/IndexTests.java | 187 ---------- .../ReactiveIndexedQualifierTests.java | 312 ----------------- .../reactive/ReactiveQualifierTests.java | 329 +++--------------- .../query/reactive/ReactiveSelectorTests.java | 210 ----------- .../query/reactive/ReactiveUsersTests.java | 36 -- .../{ => sync}/BaseQueryEngineTests.java | 3 +- .../FilterOperationRegexpBuilderTest.java | 2 +- .../query/{ => sync}/QualifierTests.java | 204 +++-------- .../IndexedPersonRepositoryQueryTests.java | 245 ------------- .../blocking/indexed/countBy/EqualsTests.java | 25 -- .../blocking/indexed/findBy/BetweenTests.java | 103 ------ .../indexed/findBy/ContainingTests.java | 70 ---- .../findBy/CrudRepositoryQueryTests.java | 41 --- .../indexed/findBy/CustomQueriesTests.java | 141 -------- .../blocking/indexed/findBy/EqualsTests.java | 178 ---------- .../indexed/findBy/GreaterThanTests.java | 79 ----- .../indexed/findBy/NotContainingTests.java | 40 --- .../noindex/findBy/CustomQueriesTests.java | 17 +- .../blocking/noindex/findBy/EqualsTests.java | 8 +- ...tiveIndexedPersonRepositoryQueryTests.java | 126 ------- .../reactive/indexed/findBy/BetweenTests.java | 26 -- .../indexed/findBy/ContainingTests.java | 85 ----- .../findBy/CrudRepositoryQueryTests.java | 10 - .../indexed/findBy/CustomQueriesTests.java | 141 -------- .../reactive/indexed/findBy/EqualsTests.java | 55 --- .../indexed/findBy/GreaterThanTests.java | 55 --- .../indexed/findBy/LessThanTests.java | 30 -- .../indexed/findBy/StartsWithTests.java | 54 --- src/test/resources/bootstrap.properties | 3 +- 69 files changed, 469 insertions(+), 3906 deletions(-) delete mode 100644 src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateIndexTests.java create mode 100644 src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java create mode 100644 src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindInRangeTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateIndexTests.java rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AbstractFindByEntitiesTest.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeExpirationTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateAddTests.java (98%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateAppendTests.java (98%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateCompositeKeyTests.java (96%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateCountTests.java (95%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateDeleteTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateExecuteTests.java (97%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateExistsTests.java (97%) create mode 100644 src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateFindByEntitiesTests.java (92%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateFindByIdProjectionTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateFindByIdTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateFindByQueryProjectionTests.java (81%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateFindByQueryTests.java (76%) create mode 100644 src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindInRangeTests.java rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateInsertTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplatePersistTests.java (96%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplatePrependTests.java (98%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateQueryAggregationTests.java (98%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateSaveTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AerospikeTemplateUpdateTests.java (99%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/AutoIndexedDocumentAssert.java (98%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/DefaultAerospikeExceptionTranslatorTest.java (97%) rename src/test/java/org/springframework/data/aerospike/core/{ => sync}/WritePolicyBuilderTest.java (96%) delete mode 100644 src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/query/UsersTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/query/cache/IndexTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java rename src/test/java/org/springframework/data/aerospike/query/{ => sync}/BaseQueryEngineTests.java (93%) rename src/test/java/org/springframework/data/aerospike/query/{ => sync}/FilterOperationRegexpBuilderTest.java (98%) rename src/test/java/org/springframework/data/aerospike/query/{ => sync}/QualifierTests.java (77%) delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/IndexedPersonRepositoryQueryTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/countBy/EqualsTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/BetweenTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/ContainingTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CrudRepositoryQueryTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CustomQueriesTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/EqualsTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/GreaterThanTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/NotContainingTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/ReactiveIndexedPersonRepositoryQueryTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/BetweenTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/ContainingTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CrudRepositoryQueryTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CustomQueriesTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/EqualsTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/GreaterThanTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/LessThanTests.java delete mode 100644 src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/StartsWithTests.java diff --git a/src/main/asciidoc/reference/query-methods-modification.adoc b/src/main/asciidoc/reference/query-methods-modification.adoc index e174411ec..225a2dfde 100644 --- a/src/main/asciidoc/reference/query-methods-modification.adoc +++ b/src/main/asciidoc/reference/query-methods-modification.adoc @@ -43,7 +43,7 @@ Below is an example of different variations: Qualifier firstNameEqJohn = Qualifier.builder() .setField("firstName") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get("John")) + .setValue("John") .build(); result = repository.findUsingQuery(new Query(firstNameEqJohn)); assertThat(result).containsOnly(john); @@ -57,7 +57,7 @@ Below is an example of different variations: Qualifier sinceUpdateTimeLt50Seconds = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) - .setValue1AsObj(50000L) + .setValue(50000L) .build(); result = repository.findUsingQuery(new Query(sinceUpdateTimeLt50Seconds)); assertThat(result).contains(john); diff --git a/src/main/asciidoc/reference/template.adoc b/src/main/asciidoc/reference/template.adoc index 8785e5fb8..f283547c5 100644 --- a/src/main/asciidoc/reference/template.adoc +++ b/src/main/asciidoc/reference/template.adoc @@ -75,7 +75,7 @@ long count = template.count (new QualifierBuilder() .setFilterOperation(FilterOperation.EQ) .setField("firstName") - .setValue1(Value.get("John")) + .setValue("John") .build() ), Person.class diff --git a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java index 72aadb716..26d1d1d0d 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -127,7 +127,7 @@ public Exp filterExp(Map qualifierMap) { Qualifier.builder() .setPath(getBinName(qualifierMap)) .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(item)) + .setValue(item) .build() .getFilterExp() ).toArray(Exp[]::new); @@ -154,7 +154,7 @@ public Exp filterExp(Map qualifierMap) { Qualifier.builder() .setPath(getBinName(qualifierMap)) .setFilterOperation(FilterOperation.NOTEQ) - .setValue(Value.get(item)) + .setValue(item) .build() .getFilterExp() ).toArray(Exp[]::new); @@ -576,7 +576,7 @@ public Exp filterExp(Map qualifierMap) { Qualifier.builder() .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) .setPath(path) - .setValue(Value.get(item)) + .setValue(item) .build() .getFilterExp() ).toArray(Exp[]::new); @@ -609,7 +609,7 @@ public Exp filterExp(Map qualifierMap) { Qualifier.builder() .setFilterOperation(FilterOperation.MAP_VAL_NOTEQ_BY_KEY) .setPath(path) - .setValue(Value.get(item)) + .setValue(item) .build() .getFilterExp() ).toArray(Exp[]::new); @@ -1559,7 +1559,7 @@ private static Exp processMetadataFieldInOrNot(Map qualifi Qualifier.metadataBuilder() .setMetadataField(getMetadataField(qualifierMap)) .setFilterOperation(filterOperation) - .setValue(Value.get(item)) + .setValue(item) .build() .getFilterExp() ).toArray(Exp[]::new); diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreatorUtils.java b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreatorUtils.java index 2b533716a..b2d295f5a 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreatorUtils.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreatorUtils.java @@ -153,7 +153,7 @@ protected static String getFieldName(String segmentName, AerospikePersistentProp protected static void setQbValuesForMapByKey(QueryQualifierBuilder qb, Object key, Object value) { qb.setKey(Value.get(value)); // contains value - qb.setValue(Value.get(key)); // contains key + qb.setValue(key); // contains key } protected static Object convertIfNecessary(Object obj, MappingAerospikeConverter converter) { diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateIndexTests.java b/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateIndexTests.java deleted file mode 100644 index 127e5c9ef..000000000 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateIndexTests.java +++ /dev/null @@ -1,294 +0,0 @@ -package org.springframework.data.aerospike.core; - -import com.aerospike.client.cdt.CTX; -import com.aerospike.client.query.IndexCollectionType; -import com.aerospike.client.query.IndexType; -import lombok.Value; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.BaseBlockingIntegrationTests; -import org.springframework.data.aerospike.exceptions.IndexAlreadyExistsException; -import org.springframework.data.aerospike.mapping.Document; -import org.springframework.data.aerospike.query.model.Index; -import org.springframework.data.aerospike.util.AsyncUtils; -import org.springframework.test.context.TestPropertySource; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.springframework.data.aerospike.util.AwaitilityUtils.awaitTenSecondsUntil; - -@TestPropertySource(properties = {"spring-data-aerospike.data.create-indexes-on-startup=true"}) -// this test class requires secondary indexes created on startup -public class AerospikeTemplateIndexTests extends BaseBlockingIntegrationTests { - - private static final String INDEX_TEST_1 = "index-test-77777"; - private static final String INDEX_TEST_1_WITH_SET = "index-test-77777" + OVERRIDE_SET_NAME; - private static final String INDEX_TEST_2 = "index-test-88888"; - private static final String INDEX_TEST_2_WITH_SET = "index-test-88888" + OVERRIDE_SET_NAME; - - @Override - @BeforeEach - public void setUp() { - additionalAerospikeTestOperations.dropIndex(IndexedDocument.class, INDEX_TEST_1); - additionalAerospikeTestOperations.dropIndex(IndexedDocument.class, INDEX_TEST_2); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, INDEX_TEST_1_WITH_SET); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, INDEX_TEST_2_WITH_SET); - } - - @Test - public void createIndex_createsIndexIfExecutedConcurrently() { - AtomicInteger errors = new AtomicInteger(); - AsyncUtils.executeConcurrently(5, () -> { - try { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - } catch (IndexAlreadyExistsException e) { // relevant for Aerospike Server ver. < 6.1.0.1 - errors.incrementAndGet(); - } - }); - - awaitTenSecondsUntil(() -> assertThat(template.indexExists(INDEX_TEST_1)).isTrue()); - assertThat(errors.get()).isLessThanOrEqualTo(5); // depending on the timing - } - - @Test - public void createIndex_allCreateIndexConcurrentAttemptsShouldNotFailIfIndexAlreadyExists() { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - assertThat(template.indexExists(INDEX_TEST_1)).isTrue(); - - awaitTenSecondsUntil(() -> - assertThat(template.indexExists(INDEX_TEST_1)).isTrue()); - - AtomicInteger errors = new AtomicInteger(); - AsyncUtils.executeConcurrently(5, () -> { - try { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - } catch (IndexAlreadyExistsException e) { // relevant for Aerospike Server ver. < 6.1.0.1 - errors.incrementAndGet(); - } - }); - - assertThat(errors.get()).isLessThanOrEqualTo(5); // depending on the timing - } - - @Test - public void createIndex_createsIndex() { - String setName = template.getSetName(IndexedDocument.class); - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - assertThat(template.indexExists(INDEX_TEST_1)).isTrue(); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(setName)) - .contains(Index.builder().name(INDEX_TEST_1).namespace(namespace).set(setName).bin("stringField") - .indexType(IndexType.STRING).build()) - ); - } - - @Test - public void createIndexWithSetName_createsIndex() { - template.createIndex(OVERRIDE_SET_NAME, INDEX_TEST_1_WITH_SET, "stringField", IndexType.STRING); - assertThat(template.indexExists(INDEX_TEST_1_WITH_SET)).isTrue(); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(OVERRIDE_SET_NAME)) - .contains(Index.builder().name(INDEX_TEST_1_WITH_SET).namespace(namespace).set(OVERRIDE_SET_NAME) - .bin("stringField") - .indexType(IndexType.STRING).build()) - ); - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_shouldNotThrowExceptionIfIndexAlreadyExists() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - - awaitTenSecondsUntil(() -> assertThat(template.indexExists(INDEX_TEST_1)).isTrue()); - - assertThatCode(() -> template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", - IndexType.STRING)).doesNotThrowAnyException(); - } - } - - @Test - public void createIndex_createsListIndex() { - String setName = template.getSetName(IndexedDocument.class); - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "listField", IndexType.STRING, - IndexCollectionType.LIST); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(setName)) - .contains(Index.builder().name(INDEX_TEST_1).namespace(namespace).set(setName).bin("listField") - .indexType(IndexType.STRING).indexCollectionType(IndexCollectionType.LIST).build()) - ); - } - - @Test - public void createIndexWithSetName_createsListIndex() { - template.createIndex(OVERRIDE_SET_NAME, INDEX_TEST_1_WITH_SET, "listField", IndexType.STRING, - IndexCollectionType.LIST); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(OVERRIDE_SET_NAME)) - .contains(Index.builder().name(INDEX_TEST_1_WITH_SET).namespace(namespace).set(OVERRIDE_SET_NAME) - .bin("listField") - .indexType(IndexType.STRING).indexCollectionType(IndexCollectionType.LIST).build()) - ); - } - - @Test - public void createIndex_createsMapIndex() { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "mapField", IndexType.STRING, - IndexCollectionType.MAPKEYS); - template.createIndex(IndexedDocument.class, INDEX_TEST_2, "mapField", IndexType.STRING, - IndexCollectionType.MAPVALUES); - - awaitTenSecondsUntil(() -> { - assertThat(template.indexExists(INDEX_TEST_1)).isTrue(); - assertThat(template.indexExists(INDEX_TEST_2)).isTrue(); - }); - } - - @Test - public void createIndexWithSetName_createsMapIndex() { - template.createIndex(OVERRIDE_SET_NAME, INDEX_TEST_1_WITH_SET, "mapField", IndexType.STRING, - IndexCollectionType.MAPKEYS); - template.createIndex(OVERRIDE_SET_NAME, INDEX_TEST_2_WITH_SET, "mapField", IndexType.STRING, - IndexCollectionType.MAPVALUES); - - awaitTenSecondsUntil(() -> { - assertThat(template.indexExists(INDEX_TEST_1_WITH_SET)).isTrue(); - assertThat(template.indexExists(INDEX_TEST_2_WITH_SET)).isTrue(); - }); - } - - @Test - public void createIndex_createsIndexForDifferentTypes() { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "mapField", IndexType.STRING); - template.createIndex(IndexedDocument.class, INDEX_TEST_2, "mapField", IndexType.NUMERIC); - - awaitTenSecondsUntil(() -> { - assertThat(template.indexExists(INDEX_TEST_1)).isTrue(); - assertThat(template.indexExists(INDEX_TEST_2)).isTrue(); - }); - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void deleteIndex_doesNotThrowExceptionIfIndexDoesNotExist() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - assertThatCode(() -> template.deleteIndex(IndexedDocument.class, "not-existing-index")) - .doesNotThrowAnyException(); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void deleteIndexWithSetName_doesNotThrowExceptionIfIndexDoesNotExist() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - assertThatCode(() -> template.deleteIndex(OVERRIDE_SET_NAME, "not-existing-index")) - .doesNotThrowAnyException(); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_createsIndexOnNestedList() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - String setName = template.getSetName(IndexedDocument.class); - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "nestedList", IndexType.STRING, - IndexCollectionType.LIST, CTX.listIndex(1)); - - awaitTenSecondsUntil(() -> { - CTX ctx = Objects.requireNonNull(additionalAerospikeTestOperations.getIndexes(setName).stream() - .filter(o -> o.getName().equals(INDEX_TEST_1)) - .findFirst().orElse(null)).getCtx()[0]; - - assertThat(ctx.id).isEqualTo(CTX.listIndex(1).id); - assertThat(ctx.value.toLong()).isEqualTo(CTX.listIndex(1).value.toLong()); - } - ); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_createsIndexOnNestedListContextRank() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - String setName = template.getSetName(IndexedDocument.class); - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "nestedList", IndexType.STRING, - IndexCollectionType.LIST, CTX.listRank(-1)); - - awaitTenSecondsUntil(() -> { - CTX ctx = Objects.requireNonNull(additionalAerospikeTestOperations.getIndexes(setName).stream() - .filter(o -> o.getName().equals(INDEX_TEST_1)) - .findFirst().orElse(null)).getCtx()[0]; - - assertThat(ctx.id).isEqualTo(CTX.listRank(-1).id); - assertThat(ctx.value.toLong()).isEqualTo(CTX.listRank(-1).value.toLong()); - } - ); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_createsIndexOnMapOfMapsContext() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - String setName = template.getSetName(IndexedDocument.class); - - CTX[] ctx = new CTX[]{ - CTX.mapKey(com.aerospike.client.Value.get("key1")), - CTX.mapKey(com.aerospike.client.Value.get("innerKey2")) - }; - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "mapOfLists", IndexType.STRING, - IndexCollectionType.MAPKEYS, ctx); - - awaitTenSecondsUntil(() -> { - CTX[] ctxResponse = - Objects.requireNonNull(additionalAerospikeTestOperations.getIndexes(setName).stream() - .filter(o -> o.getName().equals(INDEX_TEST_1)) - .findFirst().orElse(null)).getCtx(); - - assertThat(ctx.length).isEqualTo(ctxResponse.length); - assertThat(ctx[0].id).isIn(ctxResponse[0].id, ctxResponse[1].id); - assertThat(ctx[1].id).isIn(ctxResponse[0].id, ctxResponse[1].id); - assertThat(ctx[0].value.toLong()).isIn(ctxResponse[0].value.toLong(), - ctxResponse[1].value.toLong()); - assertThat(ctx[1].value.toLong()).isIn(ctxResponse[0].value.toLong(), - ctxResponse[1].value.toLong()); - } - ); - } - } - - @Test - public void deleteIndex_deletesExistingIndex() { - template.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING); - - awaitTenSecondsUntil(() -> assertThat(template.indexExists(INDEX_TEST_1)).isTrue()); - - template.deleteIndex(IndexedDocument.class, INDEX_TEST_1); - - awaitTenSecondsUntil(() -> assertThat(template.indexExists(INDEX_TEST_1)).isFalse()); - } - - @Test - void indexedAnnotation_createsIndexes() { - AutoIndexedDocumentAssert.assertIndexesCreated(additionalAerospikeTestOperations, namespace); - } - - @Value - @Document - public static class IndexedDocument { - - String stringField; - int intField; - List> nestedList; - Map> mapOfMaps; - } -} diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateCountRelatedTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateCountRelatedTests.java index a45c8dd2f..404230296 100644 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateCountRelatedTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateCountRelatedTests.java @@ -1,6 +1,5 @@ package org.springframework.data.aerospike.core.reactive; -import com.aerospike.client.Value; import org.awaitility.Awaitility; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,7 +48,7 @@ void count_shouldFindAllItemsByGivenCriteria() { QualifierBuilder qbVasya1 = Qualifier.builder() .setPath("firstName") - .setValue(Value.get("vasili")) + .setValue("vasili") .setFilterOperation(FilterOperation.EQ); Query queryVasya1 = new Query(qbVasya1.build()); @@ -61,7 +60,7 @@ void count_shouldFindAllItemsByGivenCriteria() { QualifierBuilder qbVasya2 = Qualifier.builder() .setPath("age") - .setValue(Value.get(51)) + .setValue(51) .setFilterOperation(FilterOperation.EQ); Query queryVasyaAnd = new Query(Qualifier.and(qbVasya1.build(), qbVasya2.build())); @@ -73,7 +72,7 @@ void count_shouldFindAllItemsByGivenCriteria() { QualifierBuilder qbPetya = Qualifier.builder() .setPath("firstName") - .setValue(Value.get("petya")) + .setValue("petya") .setFilterOperation(FilterOperation.EQ); Long petyaCount = reactiveTemplate.count(new Query(qbPetya.build()), Person.class) .subscribeOn(Schedulers.parallel()) @@ -95,7 +94,7 @@ void count_shouldFindAllItemsByGivenCriteriaAndRespectsIgnoreCase() { QualifierBuilder qbVasya1 = Qualifier.builder() .setPath("firstName") - .setValue(Value.get("vas")) + .setValue("vas") .setIgnoreCase(true) .setFilterOperation(FilterOperation.STARTS_WITH); @@ -104,7 +103,7 @@ void count_shouldFindAllItemsByGivenCriteriaAndRespectsIgnoreCase() { QualifierBuilder qbVasya2 = Qualifier.builder() .setPath("firstName") - .setValue(Value.get("VaS")) + .setValue("VaS") .setIgnoreCase(false) .setFilterOperation(FilterOperation.STARTS_WITH); @@ -118,7 +117,7 @@ void count_shouldFindAllItemsByGivenCriteriaAndRespectsIgnoreCase() { void count_shouldReturnZeroIfNoDocumentsByProvidedCriteriaIsFound() { QualifierBuilder qb1 = Qualifier.builder() .setPath("firstName") - .setValue(Value.get("nastyushka")) + .setValue("nastyushka") .setFilterOperation(FilterOperation.EQ); Long count = reactiveTemplate.count(new Query(qb1.build()), Person.class) diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java new file mode 100644 index 000000000..646df7901 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindAllTests.java @@ -0,0 +1,55 @@ +package org.springframework.data.aerospike.core.reactive; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.data.aerospike.sample.Person; +import reactor.core.scheduler.Schedulers; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.assertThat; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ReactiveAerospikeTemplateFindAllTests extends ReactiveAerospikeTemplateFindByQueryTests { + + @Test + public void findAll_findAllExistingDocuments() { + List persons = IntStream.rangeClosed(1, 10) + .mapToObj(age -> Person.builder().id(nextId()).firstName("Dave").lastName("Matthews").age(age).build()) + .collect(Collectors.toList()); + reactiveTemplate.insertAll(persons).blockLast(); + + List result = reactiveTemplate.findAll(Person.class) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + assertThat(result).hasSameElementsAs(persons); + + deleteAll(persons); // cleanup + } + + @Test + public void findAllWithSetName_findAllExistingDocuments() { + List persons = IntStream.rangeClosed(1, 10) + .mapToObj(age -> Person.builder().id(nextId()).firstName("Dave").lastName("Matthews").age(age).build()) + .collect(Collectors.toList()); + reactiveTemplate.insertAll(persons, OVERRIDE_SET_NAME).blockLast(); + + List result = reactiveTemplate.findAll(Person.class, OVERRIDE_SET_NAME) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + assertThat(result).hasSameElementsAs(persons); + + deleteAll(persons, OVERRIDE_SET_NAME); // cleanup + } + + @Test + public void findAll_findNothing() { + List actual = reactiveTemplate.findAll(Person.class) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + + assertThat(actual).isEmpty(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByEntitiesTest.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByEntitiesTest.java index e46715760..39ee73637 100644 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByEntitiesTest.java +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByEntitiesTest.java @@ -1,9 +1,9 @@ package org.springframework.data.aerospike.core.reactive; import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.core.AbstractFindByEntitiesTest; import org.springframework.data.aerospike.core.model.GroupedEntities; import org.springframework.data.aerospike.core.model.GroupedKeys; +import org.springframework.data.aerospike.core.sync.AbstractFindByEntitiesTest; import reactor.core.scheduler.Schedulers; public class ReactiveAerospikeTemplateFindByEntitiesTest diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryProjectionTest.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryProjectionTest.java index 9f445c594..045b0b313 100644 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryProjectionTest.java +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryProjectionTest.java @@ -1,6 +1,5 @@ package org.springframework.data.aerospike.core.reactive; -import com.aerospike.client.query.IndexType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -29,18 +28,6 @@ public class ReactiveAerospikeTemplateFindByQueryProjectionTest extends BaseReac public void beforeAllSetUp() { reactiveTemplate.deleteAll(Person.class).block(); reactiveTemplate.deleteAll(OVERRIDE_SET_NAME).block(); - additionalAerospikeTestOperations.createIndex( - Person.class, "person_age_index", "age", IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex( - Person.class, "person_last_name_index", "lastName", IndexType.STRING); - additionalAerospikeTestOperations.createIndex( - Person.class, "person_first_name_index", "firstName", IndexType.STRING); - additionalAerospikeTestOperations.createIndex( - OVERRIDE_SET_NAME, "person_age_index" + OVERRIDE_SET_NAME, "age", IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex( - OVERRIDE_SET_NAME, "person_last_name_index" + OVERRIDE_SET_NAME, "lastName", IndexType.STRING); - additionalAerospikeTestOperations.createIndex( - OVERRIDE_SET_NAME, "person_first_name_index" + OVERRIDE_SET_NAME, "firstName", IndexType.STRING); } @Override @@ -53,12 +40,6 @@ public void setUp() { @AfterAll public void afterAll() { - additionalAerospikeTestOperations.dropIndex(Person.class, "person_age_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_last_name_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_first_name_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_age_index" + OVERRIDE_SET_NAME); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_last_name_index" + OVERRIDE_SET_NAME); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_first_name_index" + OVERRIDE_SET_NAME); reactiveTemplate.deleteAll(Person.class).block(); reactiveTemplate.deleteAll(OVERRIDE_SET_NAME).block(); } diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryTests.java index ad127ffde..0070c83bd 100644 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindByQueryTests.java @@ -1,7 +1,5 @@ package org.springframework.data.aerospike.core.reactive; -import com.aerospike.client.query.IndexType; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,12 +35,6 @@ public class ReactiveAerospikeTemplateFindByQueryTests extends BaseReactiveInteg public void beforeAllSetUp() { additionalAerospikeTestOperations.deleteAllAndVerify(Person.class); additionalAerospikeTestOperations.deleteAllAndVerify(Person.class, OVERRIDE_SET_NAME); - additionalAerospikeTestOperations.createIndex(Person.class, "person_age_index", - "age", IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex(Person.class, "person_last_name_index", - "lastName", IndexType.STRING); - additionalAerospikeTestOperations.createIndex(Person.class, "person_first_name_index", - "firstName", IndexType.STRING); } @Override @@ -53,129 +45,6 @@ public void setUp() { super.setUp(); } - @AfterAll - public void afterAll() { - additionalAerospikeTestOperations.dropIndex(Person.class, "person_age_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_last_name_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_first_name_index"); - additionalAerospikeTestOperations.deleteAllAndVerify(Person.class); - additionalAerospikeTestOperations.deleteAllAndVerify(Person.class, OVERRIDE_SET_NAME); - } - - @Test - public void findAll_findAllExistingDocuments() { - List persons = IntStream.rangeClosed(1, 10) - .mapToObj(age -> Person.builder().id(nextId()).firstName("Dave").lastName("Matthews").age(age).build()) - .collect(Collectors.toList()); - reactiveTemplate.insertAll(persons).blockLast(); - - List result = reactiveTemplate.findAll(Person.class) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - assertThat(result).hasSameElementsAs(persons); - - deleteAll(persons); // cleanup - } - - @Test - public void findAllWithSetName_findAllExistingDocuments() { - List persons = IntStream.rangeClosed(1, 10) - .mapToObj(age -> Person.builder().id(nextId()).firstName("Dave").lastName("Matthews").age(age).build()) - .collect(Collectors.toList()); - reactiveTemplate.insertAll(persons, OVERRIDE_SET_NAME).blockLast(); - - List result = reactiveTemplate.findAll(Person.class, OVERRIDE_SET_NAME) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - assertThat(result).hasSameElementsAs(persons); - - deleteAll(persons, OVERRIDE_SET_NAME); // cleanup - } - - @Test - public void findAll_findNothing() { - List actual = reactiveTemplate.findAll(Person.class) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - - assertThat(actual).isEmpty(); - } - - @Test - public void findInRange_shouldFindLimitedNumberOfDocuments() { - List allUsers = IntStream.range(20, 27) - .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); - reactiveTemplate.insertAll(allUsers).blockLast(); - - List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - assertThat(actual) - .hasSize(5) - .containsAnyElementsOf(allUsers); - - deleteAll(allUsers); // cleanup - } - - @Test - public void findInRange_shouldFindLimitedNumberOfDocumentsAndSkip() { - List allUsers = IntStream.range(20, 27) - .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); - reactiveTemplate.insertAll(allUsers).blockLast(); - - List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - - assertThat(actual) - .hasSize(5) - .containsAnyElementsOf(allUsers); - - deleteAll(allUsers); // cleanup - } - - @Test - public void findInRangeWithSetName_shouldFindLimitedNumberOfDocumentsAndSkip() { - List allUsers = IntStream.range(20, 27) - .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); - reactiveTemplate.insertAll(allUsers, OVERRIDE_SET_NAME).blockLast(); - - List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - - assertThat(actual) - .hasSize(5) - .containsAnyElementsOf(allUsers); - - deleteAll(allUsers, OVERRIDE_SET_NAME); // cleanup - } - - @Test - public void findInRange_shouldFindLimitedNumberOfDocumentsWithOrderBy() { - List persons = new ArrayList<>(); - persons.add(new Person(nextId(), "Dave", "Matthews")); - persons.add(new Person(nextId(), "Josh", "Matthews")); - persons.add(new Person(nextId(), "Chris", "Yes")); - persons.add(new Person(nextId(), "Kate", "New")); - persons.add(new Person(nextId(), "Nicole", "Joshua")); - reactiveTemplate.insertAll(persons).blockLast(); - - int skip = 0; - int limit = 3; - Sort sort = Sort.by(asc("firstName")); - - List result = reactiveTemplate.findInRange(skip, limit, sort, Person.class) - .subscribeOn(Schedulers.parallel()) - .collectList().block(); - - assertThat(Objects.requireNonNull(result).stream().map(Person::getFirstName).collect(Collectors.toList())) - .hasSize(3) - .containsExactly("Chris", "Dave", "Josh"); - - deleteAll(persons); // cleanup - } - @Test public void findAll_OrderByFirstName() { List persons = new ArrayList<>(); diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindInRangeTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindInRangeTests.java new file mode 100644 index 000000000..f26f714dc --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateFindInRangeTests.java @@ -0,0 +1,95 @@ +package org.springframework.data.aerospike.core.reactive; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.data.aerospike.sample.Person; +import org.springframework.data.domain.Sort; +import reactor.core.scheduler.Schedulers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.domain.Sort.Order.asc; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ReactiveAerospikeTemplateFindInRangeTests extends ReactiveAerospikeTemplateFindByQueryTests { + + @Test + public void findInRange_shouldFindLimitedNumberOfDocuments() { + List allUsers = IntStream.range(20, 27) + .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); + reactiveTemplate.insertAll(allUsers).blockLast(); + + List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + assertThat(actual) + .hasSize(5) + .containsAnyElementsOf(allUsers); + + deleteAll(allUsers); // cleanup + } + + @Test + public void findInRange_shouldFindLimitedNumberOfDocumentsAndSkip() { + List allUsers = IntStream.range(20, 27) + .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); + reactiveTemplate.insertAll(allUsers).blockLast(); + + List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + + assertThat(actual) + .hasSize(5) + .containsAnyElementsOf(allUsers); + + deleteAll(allUsers); // cleanup + } + + @Test + public void findInRangeWithSetName_shouldFindLimitedNumberOfDocumentsAndSkip() { + List allUsers = IntStream.range(20, 27) + .mapToObj(id -> new Person(nextId(), "Firstname", "Lastname")).collect(Collectors.toList()); + reactiveTemplate.insertAll(allUsers, OVERRIDE_SET_NAME).blockLast(); + + List actual = reactiveTemplate.findInRange(0, 5, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + + assertThat(actual) + .hasSize(5) + .containsAnyElementsOf(allUsers); + + deleteAll(allUsers, OVERRIDE_SET_NAME); // cleanup + } + + @Test + public void findInRange_shouldFindLimitedNumberOfDocumentsWithOrderBy() { + List persons = new ArrayList<>(); + persons.add(new Person(nextId(), "Dave", "Matthews")); + persons.add(new Person(nextId(), "Josh", "Matthews")); + persons.add(new Person(nextId(), "Chris", "Yes")); + persons.add(new Person(nextId(), "Kate", "New")); + persons.add(new Person(nextId(), "Nicole", "Joshua")); + reactiveTemplate.insertAll(persons).blockLast(); + + int skip = 0; + int limit = 3; + Sort sort = Sort.by(asc("firstName")); + + List result = reactiveTemplate.findInRange(skip, limit, sort, Person.class) + .subscribeOn(Schedulers.parallel()) + .collectList().block(); + + assertThat(Objects.requireNonNull(result).stream().map(Person::getFirstName).collect(Collectors.toList())) + .hasSize(3) + .containsExactly("Chris", "Dave", "Josh"); + + deleteAll(persons); // cleanup + } +} diff --git a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateIndexTests.java b/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateIndexTests.java deleted file mode 100644 index 85725e289..000000000 --- a/src/test/java/org/springframework/data/aerospike/core/reactive/ReactiveAerospikeTemplateIndexTests.java +++ /dev/null @@ -1,223 +0,0 @@ -package org.springframework.data.aerospike.core.reactive; - -import com.aerospike.client.cdt.CTX; -import com.aerospike.client.query.IndexCollectionType; -import com.aerospike.client.query.IndexType; -import lombok.Value; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.core.AerospikeTemplateIndexTests; -import org.springframework.data.aerospike.exceptions.IndexAlreadyExistsException; -import org.springframework.data.aerospike.exceptions.IndexNotFoundException; -import org.springframework.data.aerospike.mapping.Document; -import org.springframework.data.aerospike.query.model.Index; -import reactor.core.publisher.Mono; - -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.IntStream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.springframework.data.aerospike.util.AwaitilityUtils.awaitTenSecondsUntil; - -public class ReactiveAerospikeTemplateIndexTests extends BaseReactiveIntegrationTests { - - private static final String INDEX_TEST_1 = "index-test-77777"; - private static final String INDEX_TEST_2 = "index-test-88888"; - - @Override - @BeforeEach - public void setUp() { - additionalAerospikeTestOperations.dropIndex(IndexedDocument.class, INDEX_TEST_1); - additionalAerospikeTestOperations.dropIndex(IndexedDocument.class, INDEX_TEST_2); - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_shouldNotThrowExceptionIfIndexAlreadyExists() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING).block(); - - assertThatCode(() -> reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", - IndexType.STRING) - .block()) - .doesNotThrowAnyException(); - } - } - - // for Aerospike Server ver. < 6.1.0.1 - @Test - public void createIndex_throwsExceptionIfIndexAlreadyExists() { - if (!serverVersionSupport.isDropCreateBehaviorUpdated()) { - reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING).block(); - - assertThatThrownBy(() -> reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", - IndexType.STRING) - .block()).isInstanceOf(IndexAlreadyExistsException.class); - } - } - - @Test - public void createIndex_createsIndexIfExecutedConcurrently() { - AtomicInteger errorsCount = new AtomicInteger(); - - IntStream.range(0, 5) - .mapToObj(i -> reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", - IndexType.STRING) - .onErrorResume(throwable -> { - errorsCount.incrementAndGet(); - return Mono.empty(); - })) - .forEach(Mono::block); - - assertThat(errorsCount.get()).isLessThanOrEqualTo(4); // depending on the timing - assertThat(reactiveTemplate.indexExists(INDEX_TEST_1).toFuture().getNow(false)).isTrue(); - } - - @Test - public void createIndex_createsIndex() { - String setName = reactiveTemplate.getSetName(AerospikeTemplateIndexTests.IndexedDocument.class); - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, "stringField", - IndexType.STRING) - .block(); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(setName)) - .contains(Index.builder().name(INDEX_TEST_1).namespace(namespace).set(setName).bin("stringField") - .indexType(IndexType.STRING).build()) - ); - } - - @Test - public void createIndex_createsListIndex() { - String setName = reactiveTemplate.getSetName(AerospikeTemplateIndexTests.IndexedDocument.class); - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, "listField", - IndexType.STRING, IndexCollectionType.LIST) - .block(); - - awaitTenSecondsUntil(() -> - assertThat(additionalAerospikeTestOperations.getIndexes(setName)) - .contains(Index.builder().name(INDEX_TEST_1).namespace(namespace).set(setName).bin("listField") - .indexType(IndexType.STRING).indexCollectionType(IndexCollectionType.LIST).build()) - ); - } - - @Test - public void createIndex_createsMapIndex() { - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, "mapField", - IndexType.STRING, IndexCollectionType.MAPKEYS) - .block(); - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_2, "mapField", - IndexType.STRING, IndexCollectionType.MAPVALUES) - .block(); - - awaitTenSecondsUntil(() -> { - assertThat(reactiveTemplate.indexExists(INDEX_TEST_1).toFuture().getNow(false)).isTrue(); - assertThat(reactiveTemplate.indexExists(INDEX_TEST_2).toFuture().getNow(false)).isTrue(); - }); - } - - @Test - public void createIndex_createsIndexForDifferentTypes() { - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, "mapField", - IndexType.STRING) - .block(); - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_2, "mapField", - IndexType.NUMERIC) - .block(); - - awaitTenSecondsUntil(() -> { - assertThat(reactiveTemplate.indexExists(INDEX_TEST_1).toFuture().getNow(false)).isTrue(); - assertThat(reactiveTemplate.indexExists(INDEX_TEST_2).toFuture().getNow(false)).isTrue(); - }); - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_createsIndexOnNestedList() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - String setName = reactiveTemplate.getSetName(AerospikeTemplateIndexTests.IndexedDocument.class); - reactiveTemplate.createIndex( - AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, "nestedList", - IndexType.STRING, IndexCollectionType.LIST, CTX.listIndex(1)).block(); - - awaitTenSecondsUntil(() -> { - CTX ctx = Objects.requireNonNull(additionalAerospikeTestOperations.getIndexes(setName).stream() - .filter(o -> o.getName().equals(INDEX_TEST_1)) - .findFirst().orElse(null)).getCtx()[0]; - - assertThat(ctx.id).isEqualTo(CTX.listIndex(1).id); - assertThat(ctx.value.toLong()).isEqualTo(CTX.listIndex(1).value.toLong()); - } - ); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void createIndex_createsIndexOnMapOfMapsContext() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - String setName = reactiveTemplate.getSetName(AerospikeTemplateIndexTests.IndexedDocument.class); - - CTX[] ctx = new CTX[]{ - CTX.mapKey(com.aerospike.client.Value.get("key1")), - CTX.mapKey(com.aerospike.client.Value.get("innerKey2")) - }; - reactiveTemplate.createIndex(AerospikeTemplateIndexTests.IndexedDocument.class, INDEX_TEST_1, - "mapOfLists", IndexType.STRING, IndexCollectionType.MAPKEYS, ctx).block(); - - awaitTenSecondsUntil(() -> { - CTX[] ctxResponse = - Objects.requireNonNull(additionalAerospikeTestOperations.getIndexes(setName).stream() - .filter(o -> o.getName().equals(INDEX_TEST_1)) - .findFirst().orElse(null)).getCtx(); - - assertThat(ctx.length).isEqualTo(ctxResponse.length); - assertThat(ctx[0].id).isIn(ctxResponse[0].id, ctxResponse[1].id); - assertThat(ctx[1].id).isIn(ctxResponse[0].id, ctxResponse[1].id); - assertThat(ctx[0].value.toLong()).isIn(ctxResponse[0].value.toLong(), - ctxResponse[1].value.toLong()); - assertThat(ctx[1].value.toLong()).isIn(ctxResponse[0].value.toLong(), - ctxResponse[1].value.toLong()); - } - ); - } - } - - // for Aerospike Server ver. >= 6.1.0.1 - @Test - public void deleteIndex_doesNotThrowExceptionIfIndexDoesNotExist() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - assertThatCode(() -> reactiveTemplate.deleteIndex(IndexedDocument.class, "not-existing-index") - .block()) - .doesNotThrowAnyException(); - } - } - - // for Aerospike Server ver. < 6.1.0.1 - @Test - public void deleteIndex_throwsExceptionIfIndexDoesNotExist() { - if (!serverVersionSupport.isDropCreateBehaviorUpdated()) { - assertThatThrownBy(() -> reactiveTemplate.deleteIndex(IndexedDocument.class, "not-existing-index").block()) - .isInstanceOf(IndexNotFoundException.class); - } - } - - @Test - public void deleteIndex_deletesExistingIndex() { - reactiveTemplate.createIndex(IndexedDocument.class, INDEX_TEST_1, "stringField", IndexType.STRING).block(); - reactiveTemplate.deleteIndex(IndexedDocument.class, INDEX_TEST_1).block(); - assertThat(reactiveTemplate.indexExists(INDEX_TEST_1).toFuture().getNow(false)).isFalse(); - } - - @Value - @Document - public static class IndexedDocument { - - String stringField; - int intField; - } -} diff --git a/src/test/java/org/springframework/data/aerospike/core/AbstractFindByEntitiesTest.java b/src/test/java/org/springframework/data/aerospike/core/sync/AbstractFindByEntitiesTest.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AbstractFindByEntitiesTest.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AbstractFindByEntitiesTest.java index d040290c1..bc4477a58 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AbstractFindByEntitiesTest.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AbstractFindByEntitiesTest.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.core.convert.ConverterNotFoundException; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeExpirationTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeExpirationTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeExpirationTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeExpirationTests.java index 5cbfd5a3b..201b60b0d 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeExpirationTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeExpirationTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.AerospikeException; import com.aerospike.client.Key; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAddTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAddTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAddTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAddTests.java index 771cb433b..11bfd3825 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAddTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAddTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAppendTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAppendTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAppendTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAppendTests.java index 3ecf134d6..b0a1bf4a3 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateAppendTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateAppendTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCompositeKeyTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCompositeKeyTests.java similarity index 96% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCompositeKeyTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCompositeKeyTests.java index 92fc06250..9c3a0e905 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCompositeKeyTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCompositeKeyTests.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCountTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCountTests.java similarity index 95% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCountTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCountTests.java index 6f72ecd49..cabb23939 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateCountTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateCountTests.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; -import com.aerospike.client.Value; import org.awaitility.Awaitility; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -63,7 +62,7 @@ public void countFindsAllItemsByGivenCriteria() { new Query(Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath("firstName") - .setValue(Value.get("vasili")) + .setValue("vasili") .build() ), Person.class @@ -74,13 +73,13 @@ public void countFindsAllItemsByGivenCriteria() { Qualifier qbIs1 = Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath("firstName") - .setValue(Value.get("vasili")) + .setValue("vasili") .build(); Qualifier qbIs2 = Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath("age") - .setValue(Value.get(51)) + .setValue(51) .build(); long vasya51Count = template.count( @@ -93,7 +92,7 @@ public void countFindsAllItemsByGivenCriteria() { new Query(Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath("firstName") - .setValue(Value.get("petya")) + .setValue("petya") .build() ), Person.class @@ -117,7 +116,7 @@ public void countFindsAllItemsByGivenCriteriaAndRespectsIgnoreCase() { Query query1 = new Query(Qualifier.builder() .setPath("firstName") - .setValue(Value.get("vas")) + .setValue("vas") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(true) .build() @@ -126,7 +125,7 @@ public void countFindsAllItemsByGivenCriteriaAndRespectsIgnoreCase() { Query query2 = new Query(Qualifier.builder() .setPath("firstName") - .setValue(Value.get("VaS")) + .setValue("VaS") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(false) .build() @@ -145,7 +144,7 @@ public void countReturnsZeroIfNoDocumentsByProvidedCriteriaIsFound() { Query query1 = new Query (Qualifier.builder() .setPath("firstName") - .setValue(Value.get("nastyushka")) + .setValue("nastyushka") .setFilterOperation(FilterOperation.STARTS_WITH) .build() ); diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateDeleteTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateDeleteTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateDeleteTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateDeleteTests.java index fd481a6b0..9ff2c8d29 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateDeleteTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateDeleteTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.AerospikeException; import com.aerospike.client.policy.GenerationPolicy; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExecuteTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExecuteTests.java similarity index 97% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExecuteTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExecuteTests.java index b5de868ee..e81565938 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExecuteTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExecuteTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.Bin; import com.aerospike.client.IAerospikeClient; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExistsTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExistsTests.java similarity index 97% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExistsTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExistsTests.java index 5e773d3fc..a8455f999 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateExistsTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateExistsTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; diff --git a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java new file mode 100644 index 000000000..345c79b03 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindAllTests.java @@ -0,0 +1,75 @@ +/* + * Copyright 2019 the original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.aerospike.core.sync; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.data.aerospike.sample.Person; +import org.springframework.data.domain.Sort; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.domain.Sort.Order.asc; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class AerospikeTemplateFindAllTests extends AerospikeTemplateFindByQueryTests { + + @Test + public void findAll_OrderByFirstName() { + Sort sort = Sort.by(asc("firstName")); + List result = template.findAll(sort, 0, 0, Person.class) + .collect(Collectors.toList()); + + assertThat(result) + .hasSize(10) + .containsExactly(aabbot, alister, ashley, beatrice, dave, jean, knowlen, mitch, xylophone, zaipper); + } + + @Test + public void findAll_OrderByFirstNameWithSetName() { + Sort sort = Sort.by(asc("firstName")); + List result = template.findAll(sort, 0, 0, Person.class, OVERRIDE_SET_NAME) + .collect(Collectors.toList()); + + assertThat(result) + .hasSize(10) + .containsExactly(aabbot, alister, ashley, beatrice, dave, jean, knowlen, mitch, xylophone, zaipper); + } + + @Test + public void findAll_findAllExistingDocuments() { + Stream result = template.findAll(Person.class); + assertThat(result).containsAll(allPersons); + } + + @Test + public void findAll_findNothing() { + additionalAerospikeTestOperations.deleteAllAndVerify(Person.class); + + Stream result = template.findAll(Person.class); + assertThat(result).isEmpty(); + + // batch write operations are supported starting with Server version 6.0+ + if (serverVersionSupport.isBatchWriteSupported()) { + template.insertAll(allPersons); + } else { + allPersons.forEach(person -> template.insert(person)); + } + } +} diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByEntitiesTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByEntitiesTests.java similarity index 92% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByEntitiesTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByEntitiesTests.java index 639088bc2..42b365b10 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByEntitiesTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByEntitiesTests.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; import org.springframework.data.aerospike.core.model.GroupedEntities; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdProjectionTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdProjectionTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdProjectionTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdProjectionTests.java index d1e3cb275..5957e0724 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdProjectionTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdProjectionTests.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdTests.java index 6c4b2d59d..23fec65af 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByIdTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByIdTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.Bin; import com.aerospike.client.Key; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryProjectionTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryProjectionTests.java similarity index 81% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryProjectionTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryProjectionTests.java index 120c80d16..02e77fa5a 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryProjectionTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryProjectionTests.java @@ -1,6 +1,5 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; -import com.aerospike.client.query.IndexType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -61,19 +60,6 @@ public void beforeAllSetUp() { template.insert(person, OVERRIDE_SET_NAME); }); } - - additionalAerospikeTestOperations.createIndex(Person.class, "person_age_index", "age", - IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex(Person.class, "person_first_name_index", "firstName" - , IndexType.STRING); - additionalAerospikeTestOperations.createIndex(Person.class, "person_last_name_index", "lastName", - IndexType.STRING); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_age_index", "age", - IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_first_name_index", "firstName" - , IndexType.STRING); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_last_name_index", "lastName", - IndexType.STRING); } @Override @@ -97,12 +83,6 @@ public void setUp() { public void afterAll() { deleteOneByOne(allPersons); deleteOneByOne(allPersons, OVERRIDE_SET_NAME); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_age_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_first_name_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_last_name_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_age_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_first_name_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_last_name_index"); } @Test diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java similarity index 76% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java index c3f51c189..1060703c5 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; -import com.aerospike.client.Value; import com.aerospike.client.query.Filter; import com.aerospike.client.query.IndexType; import com.aerospike.client.query.RecordSet; @@ -35,20 +34,16 @@ import org.springframework.data.aerospike.sample.SampleClasses; import org.springframework.data.aerospike.util.CollectionUtils; import org.springframework.data.aerospike.util.QueryUtils; -import org.springframework.data.domain.Sort; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY; import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY_VALUE_PAIR; -import static org.springframework.data.domain.Sort.Order.asc; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class AerospikeTemplateFindByQueryTests extends BaseBlockingIntegrationTests { @@ -96,19 +91,8 @@ public void beforeAllSetUp() { template.insert(person, OVERRIDE_SET_NAME); }); } - - additionalAerospikeTestOperations.createIndex(Person.class, "person_age_index", "age", - IndexType.NUMERIC); additionalAerospikeTestOperations.createIndex(Person.class, "person_first_name_index", "firstName", IndexType.STRING); - additionalAerospikeTestOperations.createIndex(Person.class, "person_last_name_index", "lastName", - IndexType.STRING); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_age_index", "age", - IndexType.NUMERIC); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_first_name_index", "firstName" - , IndexType.STRING); - additionalAerospikeTestOperations.createIndex(OVERRIDE_SET_NAME, "person_set_last_name_index", "lastName", - IndexType.STRING); } @Override @@ -127,12 +111,7 @@ public void afterAll() { deleteOneByOne(allPersons); deleteOneByOne(allPersons, OVERRIDE_SET_NAME); } - additionalAerospikeTestOperations.dropIndex(Person.class, "person_age_index"); additionalAerospikeTestOperations.dropIndex(Person.class, "person_first_name_index"); - additionalAerospikeTestOperations.dropIndex(Person.class, "person_last_name_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_age_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_first_name_index"); - additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_set_last_name_index"); } @Test @@ -225,96 +204,6 @@ public void findWithStatement() { .containsOnly(entry("firstName", dave.getFirstName()), entry("lastName", dave.getLastName()))); } - @Test - public void findInRange_shouldFindLimitedNumberOfDocuments() { - int skip = 0; - int limit = 5; - Stream stream = template.findInRange(skip, limit, Sort.unsorted(), Person.class); - assertThat(stream).hasSize(5); - } - - @Test - public void findInRangeWithSetName_shouldFindLimitedNumberOfDocuments() { - int skip = 0; - int limit = 5; - Stream stream = template.findInRange(skip, limit, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME); - assertThat(stream).hasSize(5); - } - - @Test - public void findInRange_shouldFailOnUnsortedQueryWithOffsetValue() { - int skip = 3; - int limit = 5; - assertThatThrownBy(() -> template.findInRange(skip, limit, Sort.unsorted(), Person.class)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Unsorted query must not have offset value. For retrieving paged results use sorted query."); - } - - @Test - public void findInRangeWithSetName_shouldFailOnUnsortedQueryWithOffsetValue() { - int skip = 3; - int limit = 5; - assertThatThrownBy(() -> template.findInRange(skip, limit, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Unsorted query must not have offset value. For retrieving paged results use sorted query."); - } - - @Test - public void findInRange_shouldFindLimitedNumberOfDocumentsWithOrderBy() { - int skip = 0; - int limit = 5; - Sort sort = Sort.by(asc("firstName")); - List stream = template.findInRange(skip, limit, sort, Person.class) - .collect(Collectors.toList()); - - assertThat(stream) - .hasSize(5) - .containsExactly(aabbot, alister, ashley, beatrice, dave); - } - - @Test - public void findAll_OrderByFirstName() { - Sort sort = Sort.by(asc("firstName")); - List result = template.findAll(sort, 0, 0, Person.class) - .collect(Collectors.toList()); - - assertThat(result) - .hasSize(10) - .containsExactly(aabbot, alister, ashley, beatrice, dave, jean, knowlen, mitch, xylophone, zaipper); - } - - @Test - public void findAll_OrderByFirstNameWithSetName() { - Sort sort = Sort.by(asc("firstName")); - List result = template.findAll(sort, 0, 0, Person.class, OVERRIDE_SET_NAME) - .collect(Collectors.toList()); - - assertThat(result) - .hasSize(10) - .containsExactly(aabbot, alister, ashley, beatrice, dave, jean, knowlen, mitch, xylophone, zaipper); - } - - @Test - public void findAll_findAllExistingDocuments() { - Stream result = template.findAll(Person.class); - assertThat(result).containsAll(allPersons); - } - - @Test - public void findAll_findNothing() { - additionalAerospikeTestOperations.deleteAllAndVerify(Person.class); - - Stream result = template.findAll(Person.class); - assertThat(result).isEmpty(); - - // batch write operations are supported starting with Server version 6.0+ - if (serverVersionSupport.isBatchWriteSupported()) { - template.insertAll(allPersons); - } else { - allPersons.forEach(person -> template.insert(person)); - } - } - @Test public void findByListContainingInteger() { Query query = QueryUtils.createQueryForMethodWithArgs(serverVersionSupport, "findByIntsContaining", 100); @@ -463,14 +352,12 @@ public void findAllUsingQuery_shouldRunWithDifferentArgumentsCombinations() { SampleClasses.CustomCollectionClass doc2 = new SampleClasses.CustomCollectionClass(nextId(), fieldValue2); template.save(doc1); template.save(doc2); - additionalAerospikeTestOperations.createIndex(SampleClasses.CustomCollectionClass.class, - "CustomCollectionClass_field", fieldName, IndexType.STRING); // find by query Qualifier qualifier = Qualifier.builder() .setPath(fieldName) .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(fieldValue1)) + .setValue(fieldValue1) .build(); Stream result1 = template.find(new Query(qualifier), SampleClasses.CustomCollectionClass.class); @@ -480,12 +367,12 @@ public void findAllUsingQuery_shouldRunWithDifferentArgumentsCombinations() { Qualifier dataEqFieldValue1 = Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath(fieldName) - .setValue(Value.get(fieldValue1)) + .setValue(fieldValue1) .build(); Qualifier dataEqFieldValue2 = Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setPath(fieldName) - .setValue(Value.get(fieldValue2)) + .setValue(fieldValue2) .build(); Qualifier qualifierOr = Qualifier.or(dataEqFieldValue1, dataEqFieldValue2); Stream result3 = diff --git a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindInRangeTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindInRangeTests.java new file mode 100644 index 000000000..8bbfd964b --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindInRangeTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2019 the original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.aerospike.core.sync; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.data.aerospike.sample.Person; +import org.springframework.data.domain.Sort; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.springframework.data.domain.Sort.Order.asc; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class AerospikeTemplateFindInRangeTests extends AerospikeTemplateFindByQueryTests { + + @Test + public void findInRange_shouldFindLimitedNumberOfDocuments() { + int skip = 0; + int limit = 5; + Stream stream = template.findInRange(skip, limit, Sort.unsorted(), Person.class); + assertThat(stream).hasSize(5); + } + + @Test + public void findInRangeWithSetName_shouldFindLimitedNumberOfDocuments() { + int skip = 0; + int limit = 5; + Stream stream = template.findInRange(skip, limit, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME); + assertThat(stream).hasSize(5); + } + + @Test + public void findInRange_shouldFailOnUnsortedQueryWithOffsetValue() { + int skip = 3; + int limit = 5; + assertThatThrownBy(() -> template.findInRange(skip, limit, Sort.unsorted(), Person.class)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Unsorted query must not have offset value. For retrieving paged results use sorted query."); + } + + @Test + public void findInRangeWithSetName_shouldFailOnUnsortedQueryWithOffsetValue() { + int skip = 3; + int limit = 5; + assertThatThrownBy(() -> template.findInRange(skip, limit, Sort.unsorted(), Person.class, OVERRIDE_SET_NAME)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Unsorted query must not have offset value. For retrieving paged results use sorted query."); + } + + @Test + public void findInRange_shouldFindLimitedNumberOfDocumentsWithOrderBy() { + int skip = 0; + int limit = 5; + Sort sort = Sort.by(asc("firstName")); + List stream = template.findInRange(skip, limit, sort, Person.class) + .collect(Collectors.toList()); + + assertThat(stream) + .hasSize(5) + .containsExactly(aabbot, alister, ashley, beatrice, dave); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateInsertTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateInsertTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateInsertTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateInsertTests.java index 59245cd94..07003764a 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateInsertTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateInsertTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.Key; import com.aerospike.client.Record; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePersistTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePersistTests.java similarity index 96% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePersistTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePersistTests.java index 4f87cecc4..618a425da 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePersistTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePersistTests.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.policy.RecordExistsAction; import com.aerospike.client.policy.WritePolicy; import org.junit.jupiter.api.Test; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; +import org.springframework.data.aerospike.core.WritePolicyBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePrependTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePrependTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePrependTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePrependTests.java index dc3890e3e..721f03571 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplatePrependTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplatePrependTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateQueryAggregationTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateQueryAggregationTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateQueryAggregationTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateQueryAggregationTests.java index eb06d3dc6..6ad80814a 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateQueryAggregationTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateQueryAggregationTests.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.Language; import com.aerospike.client.Value; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateSaveTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateSaveTests.java index bce7a8526..2ad1ab8c3 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateSaveTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.Key; import com.aerospike.client.Record; diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateUpdateTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateUpdateTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateUpdateTests.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateUpdateTests.java index d26d81950..1482fa7c9 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateUpdateTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateUpdateTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.AerospikeException; import com.aerospike.client.Key; diff --git a/src/test/java/org/springframework/data/aerospike/core/AutoIndexedDocumentAssert.java b/src/test/java/org/springframework/data/aerospike/core/sync/AutoIndexedDocumentAssert.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/core/AutoIndexedDocumentAssert.java rename to src/test/java/org/springframework/data/aerospike/core/sync/AutoIndexedDocumentAssert.java index b925f2c3b..4d835e163 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AutoIndexedDocumentAssert.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AutoIndexedDocumentAssert.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.cdt.CTX; import com.aerospike.client.query.IndexCollectionType; diff --git a/src/test/java/org/springframework/data/aerospike/core/DefaultAerospikeExceptionTranslatorTest.java b/src/test/java/org/springframework/data/aerospike/core/sync/DefaultAerospikeExceptionTranslatorTest.java similarity index 97% rename from src/test/java/org/springframework/data/aerospike/core/DefaultAerospikeExceptionTranslatorTest.java rename to src/test/java/org/springframework/data/aerospike/core/sync/DefaultAerospikeExceptionTranslatorTest.java index cf6c7f77c..69e4a501f 100644 --- a/src/test/java/org/springframework/data/aerospike/core/DefaultAerospikeExceptionTranslatorTest.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/DefaultAerospikeExceptionTranslatorTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.AerospikeException; import com.aerospike.client.ResultCode; @@ -24,6 +24,7 @@ import org.springframework.dao.QueryTimeoutException; import org.springframework.dao.RecoverableDataAccessException; import org.springframework.dao.TransientDataAccessResourceException; +import org.springframework.data.aerospike.core.DefaultAerospikeExceptionTranslator; import org.springframework.data.aerospike.exceptions.IndexAlreadyExistsException; import org.springframework.data.aerospike.exceptions.IndexNotFoundException; diff --git a/src/test/java/org/springframework/data/aerospike/core/WritePolicyBuilderTest.java b/src/test/java/org/springframework/data/aerospike/core/sync/WritePolicyBuilderTest.java similarity index 96% rename from src/test/java/org/springframework/data/aerospike/core/WritePolicyBuilderTest.java rename to src/test/java/org/springframework/data/aerospike/core/sync/WritePolicyBuilderTest.java index c296f6e80..60d6622b9 100644 --- a/src/test/java/org/springframework/data/aerospike/core/WritePolicyBuilderTest.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/WritePolicyBuilderTest.java @@ -1,9 +1,10 @@ -package org.springframework.data.aerospike.core; +package org.springframework.data.aerospike.core.sync; import com.aerospike.client.policy.GenerationPolicy; import com.aerospike.client.policy.RecordExistsAction; import com.aerospike.client.policy.WritePolicy; import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.core.WritePolicyBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java b/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java index 8b965f3a1..5b97d333c 100644 --- a/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java +++ b/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java @@ -3,7 +3,6 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; -import com.aerospike.client.Value; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,7 +45,7 @@ void binIsIndexed() { Qualifier qualifier = Qualifier.builder() .setPath("testField") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("testValue1")) + .setValue("testValue1") .build(); StatementBuilder statementBuilder = new StatementBuilder(indexesCacheMock); @@ -79,7 +78,7 @@ void queryIsCreated_CustomQuery() { Query query = new Query(Qualifier.builder() .setPath("firstName") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("TestName")) + .setValue("TestName") .build()); statementBuilder.build("TEST", "Person", query, null); diff --git a/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java deleted file mode 100644 index e2c66ae9f..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright 2012-2020 Aerospike, Inc. - * - * Portions may be licensed to Aerospike, Inc. under one or more contributor - * license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.springframework.data.aerospike.query; - -import com.aerospike.client.Value; -import com.aerospike.client.query.IndexType; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import org.springframework.data.aerospike.util.CollectionUtils; - -import java.util.Map; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.AGES; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.BLUE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GEO_BIN_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GREEN; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.INDEXED_GEO_SET; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.INDEXED_SET_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.ORANGE; -import static org.springframework.data.aerospike.util.CollectionUtils.countingInt; - -/* - * These tests generate qualifiers on indexed bins. - */ -class IndexedQualifierTests extends BaseQueryEngineTests { - - @AfterEach - public void assertNoScans() { - additionalAerospikeTestOperations.assertNoScansForSet(INDEXED_SET_NAME); - } - - @Test - void selectOnIndexedLTQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age < 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.LT) - .setValue(Value.get(26)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - assertThat(iterator) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isLessThan(26)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(25)); - }); - } - - @Test - void selectOnIndexedLTEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.LTEQ) - .setValue(Value.get(26)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - Map ageCount = CollectionUtils.toStream(iterator) - .map(rec -> rec.record.getInt("age")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(ageCount.keySet()) - .isNotEmpty() - .allSatisfy(age -> assertThat(age).isLessThanOrEqualTo(26)); - assertThat(ageCount.get(25)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(25)); - assertThat(ageCount.get(26)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(26)); - }); - } - - @Test - void selectOnIndexedNumericEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(26)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - assertThat(iterator) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(26)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(26)); - }); - } - - @Test - void selectWithBlueColorQuery() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(BLUE)) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, new Query(qual1)); - - assertThat(it) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isBetween(25, 29)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(BLUE)); - }); - } - - @Test - void selectOnIndexedGTEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.GTEQ) - .setValue(Value.get(28)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - Map ageCount = CollectionUtils.toStream(iterator) - .map(rec -> rec.record.getInt("age")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(ageCount.keySet()) - .isNotEmpty() - .allSatisfy(age -> assertThat(age).isGreaterThanOrEqualTo(28)); - assertThat(ageCount.get(28)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28)); - assertThat(ageCount.get(29)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(29)); - }); - } - - @Test - void selectOnIndexedGTQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.GT) - .setValue(Value.get(28)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - assertThat(iterator) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(29)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(29)); - }); - } - - @Test - void selectOnIndexedStringEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - Qualifier qualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(ORANGE)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(qualifier)); - - assertThat(iterator) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(ORANGE)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(ORANGE)); - }); - } - - @Test - void selectWithGeoWithin() { - if (serverVersionSupport.isDropCreateBehaviorUpdated()) { - withIndex(namespace, INDEXED_GEO_SET, "geo_index", GEO_BIN_NAME, IndexType.GEO2DSPHERE, () -> { - double lon = -122.0; - double lat = 37.5; - double radius = 50000.0; - String rgnstr = String.format("{ \"type\": \"AeroCircle\", " - + "\"coordinates\": [[%.8f, %.8f], %f] }", - lon, lat, radius); - - Qualifier qualifier = Qualifier.builder() - .setPath(GEO_BIN_NAME) - .setFilterOperation(FilterOperation.GEO_WITHIN) - .setValue(Value.getAsGeoJSON(rgnstr)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_GEO_SET, null, - new Query(qualifier)); - - assertThat(iterator).toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.generation).isPositive()); - additionalAerospikeTestOperations.assertNoScansForSet(INDEXED_GEO_SET); - }); - } - } - - @Test - void selectWithoutQuery() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, null); - - Map ageCount = CollectionUtils.toStream(it) - .map(rec -> rec.record.getInt("age")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(ageCount.keySet()) - .isNotEmpty() - .allSatisfy(age -> assertThat(age).isIn((Object[]) AGES)); - assertThat(ageCount.get(28)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28)); - assertThat(ageCount.get(29)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(29)); - }); - } - - @Test - void selectWithQualifiersOnly() { - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(GREEN)) - .build(); - Qualifier qual2 = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(29)) - .build(); - - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(Qualifier.and(qual1, qual2))); - - assertThat(it).toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(GREEN)) - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isBetween(28, 29)); - }); - } - - @Test - void selectWithAndQualifier() { - Qualifier colorIsGreen = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(GREEN)) - .build(); - Qualifier ageBetween28And29 = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(29)) - .build(); - - tryCreateIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC); - tryCreateIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING); - try { - Qualifier qualifier = Qualifier.and(colorIsGreen, ageBetween28And29); - - KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - assertThat(it).toIterable().isNotEmpty() - .allSatisfy(rec -> { - assertThat(rec.record.getInt("age")).isBetween(28, 29); - assertThat(rec.record.getString("color")).isEqualTo(GREEN); - }); - } finally { - tryDropIndex(INDEXED_SET_NAME, "age_index"); - tryDropIndex(INDEXED_SET_NAME, "color_index"); - } - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/UsersTests.java b/src/test/java/org/springframework/data/aerospike/query/UsersTests.java deleted file mode 100644 index b1396bc3f..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/UsersTests.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.springframework.data.aerospike.query; - -import com.aerospike.client.Value; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.RECORD_COUNT; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.USERS_SET; - -class UsersTests extends BaseQueryEngineTests { - - @Test - void allUsers() { - KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null, null); - - assertThat(it).toIterable().hasSize(RECORD_COUNT); - } - - @Test - void usersInterrupted() { - try (KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null, null)) { - int counter = 0; - while (it.hasNext()) { - it.next(); - counter++; - if (counter >= 1000) - break; - } - } - } - - @Test - void usersInNorthRegion() { - Qualifier qualifier = Qualifier.builder() - .setPath("region") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("n")) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null, new Query(qualifier)); - - assertThat(it).toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("region")).isEqualTo("n")); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/cache/IndexTests.java b/src/test/java/org/springframework/data/aerospike/query/cache/IndexTests.java deleted file mode 100644 index c0143e33f..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/cache/IndexTests.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.springframework.data.aerospike.query.cache; - -import com.aerospike.client.query.IndexCollectionType; -import com.aerospike.client.query.IndexType; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.BaseBlockingIntegrationTests; -import org.springframework.data.aerospike.query.model.Index; -import org.springframework.data.aerospike.query.model.IndexKey; - -import java.util.List; -import java.util.Optional; - -import static com.aerospike.client.query.IndexCollectionType.LIST; -import static com.aerospike.client.query.IndexCollectionType.MAPKEYS; -import static com.aerospike.client.query.IndexCollectionType.MAPVALUES; -import static com.aerospike.client.query.IndexType.GEO2DSPHERE; -import static com.aerospike.client.query.IndexType.NUMERIC; -import static com.aerospike.client.query.IndexType.STRING; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.model.Index.builder; - -public class IndexTests extends BaseBlockingIntegrationTests { - - private static final String SET = "index-test"; - private static final String BIN_1 = "bin-1"; - private static final String BIN_2 = "bin-2"; - private static final String BIN_3 = "bin-3"; - private static final String INDEX_NAME = "index-1"; - private static final String INDEX_NAME_2 = "index-2"; - private static final String INDEX_NAME_3 = "index-3"; - - @Override - @BeforeEach - public void setUp() { - List dropIndexes = List.of( - builder().set(SET).name(INDEX_NAME).build(), - builder().set(null).name(INDEX_NAME_2).build(), - builder().set(SET).name(INDEX_NAME_2).build(), - builder().set(SET).name(INDEX_NAME_3).build() - ); - additionalAerospikeTestOperations.dropIndexes(dropIndexes); - } - - @Test - public void refreshIndexes_findsNewlyCreatedIndex() { - Optional index = indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null)); - assertThat(index).isEmpty(); - - additionalAerospikeTestOperations.createIndex(namespace, SET, INDEX_NAME, BIN_1, IndexType.NUMERIC); - - index = indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null)); - assertThat(index).isPresent() - .hasValueSatisfying(value -> { - assertThat(value.getName()).isEqualTo(INDEX_NAME); - assertThat(value.getNamespace()).isEqualTo(namespace); - assertThat(value.getSet()).isEqualTo(SET); - assertThat(value.getBin()).isEqualTo(BIN_1); - assertThat(value.getIndexType()).isEqualTo(IndexType.NUMERIC); - }); - } - - @Test - public void refreshIndexes_removesDeletedIndex() { - additionalAerospikeTestOperations.createIndex(namespace, SET, INDEX_NAME, BIN_1, IndexType.NUMERIC); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null))).isPresent(); - - additionalAerospikeTestOperations.dropIndex(SET, INDEX_NAME); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null))).isEmpty(); - } - - @Test - public void refreshIndexes_indexWithoutSetCanBeParsed() { - additionalAerospikeTestOperations.createIndex(namespace, null, INDEX_NAME_2, BIN_2, IndexType.STRING); - - Optional index = indexesCache.getIndex(new IndexKey(namespace, null, BIN_2, IndexType.STRING, null)); - assertThat(index).isPresent() - .hasValueSatisfying(value -> { - assertThat(value.getName()).isEqualTo(INDEX_NAME_2); - assertThat(value.getNamespace()).isEqualTo(namespace); - assertThat(value.getSet()).isNull(); - assertThat(value.getBin()).isEqualTo(BIN_2); - assertThat(value.getIndexType()).isEqualTo(IndexType.STRING); - }); - } - - @Test - public void refreshIndexes_indexWithGeoTypeCanBeParsed() { - additionalAerospikeTestOperations.createIndex(namespace, SET, INDEX_NAME_3, BIN_3, GEO2DSPHERE); - - Optional index = indexesCache.getIndex(new IndexKey(namespace, SET, BIN_3, GEO2DSPHERE, null)); - assertThat(index).isPresent() - .hasValueSatisfying(value -> { - assertThat(value.getName()).isEqualTo(INDEX_NAME_3); - assertThat(value.getNamespace()).isEqualTo(namespace); - assertThat(value.getSet()).isEqualTo(SET); - assertThat(value.getBin()).isEqualTo(BIN_3); - assertThat(value.getIndexType()).isEqualTo(GEO2DSPHERE); - }); - } - - @Test - public void refreshIndexes_multipleIndexesForTheSameBinCanBeParsed() { - - List newIndexes = List.of( - builder().set(SET).name(INDEX_NAME).bin(BIN_1).indexType(NUMERIC).indexCollectionType(MAPKEYS).build(), - builder().set(SET).name(INDEX_NAME_2).bin(BIN_1).indexType(NUMERIC).indexCollectionType(MAPVALUES).build(), - builder().set(SET).name(INDEX_NAME_3).bin(BIN_2).indexType(NUMERIC).indexCollectionType(LIST).build() - ); - additionalAerospikeTestOperations.createIndexes(newIndexes); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, - IndexCollectionType.MAPKEYS))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, - IndexCollectionType.MAPVALUES))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_2, IndexType.NUMERIC, - IndexCollectionType.LIST))).isPresent(); - } - - @Test - public void refreshIndexes_multipleIndexesCanBeParsed() { - List newIndexes = List.of( - builder().set(SET).name(INDEX_NAME).bin(BIN_1).indexType(NUMERIC).build(), - builder().set(null).name(INDEX_NAME_2).bin(BIN_2).indexType(STRING).build(), - builder().set(SET).name(INDEX_NAME_3).bin(BIN_3).indexType(GEO2DSPHERE).build() - ); - additionalAerospikeTestOperations.createIndexes(newIndexes); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, null, BIN_2, IndexType.STRING, null))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_3, GEO2DSPHERE, null))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey("unknown", null, "unknown", IndexType.NUMERIC, null))).isEmpty(); - } - - @Test - public void refreshIndexes_indexesForTheSameBinCanBeParsed() { - List newIndexes = List.of( - builder().set(SET).name(INDEX_NAME).bin(BIN_1).indexType(NUMERIC).build(), - builder().set(SET).name(INDEX_NAME_2).bin(BIN_1).indexType(STRING).build() - ); - additionalAerospikeTestOperations.createIndexes(newIndexes); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null))).hasValueSatisfying(value -> { - assertThat(value.getName()).isEqualTo(INDEX_NAME); - assertThat(value.getNamespace()).isEqualTo(namespace); - assertThat(value.getSet()).isEqualTo(SET); - assertThat(value.getBin()).isEqualTo(BIN_1); - assertThat(value.getIndexType()).isEqualTo(IndexType.NUMERIC); - }); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.STRING, null))).hasValueSatisfying(value -> { - assertThat(value.getName()).isEqualTo(INDEX_NAME_2); - assertThat(value.getNamespace()).isEqualTo(namespace); - assertThat(value.getSet()).isEqualTo(SET); - assertThat(value.getBin()).isEqualTo(BIN_1); - assertThat(value.getIndexType()).isEqualTo(IndexType.STRING); - }); - - } - - @Test - public void isIndexedBin_returnsTrueForIndexedField() { - List newIndexes = List.of( - builder().set(SET).name(INDEX_NAME).bin(BIN_1).indexType(NUMERIC).build(), - builder().set(SET).name(INDEX_NAME_2).bin(BIN_2).indexType(NUMERIC).build() - ); - additionalAerospikeTestOperations.createIndexes(newIndexes); - - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null))).isPresent(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_2, IndexType.NUMERIC, null))).isPresent(); - } - - @Test - public void isIndexedBin_returnsFalseForNonIndexedField() { - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_2, IndexType.NUMERIC, null))).isEmpty(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_2, IndexType.STRING, null))).isEmpty(); - assertThat(indexesCache.getIndex(new IndexKey(namespace, SET, BIN_2, GEO2DSPHERE, null))).isEmpty(); - } - - @Test - public void getIndex_returnsEmptyForNonExistingIndex() { - Optional index = indexesCache.getIndex(new IndexKey(namespace, SET, BIN_1, IndexType.NUMERIC, null)); - - assertThat(index).isEmpty(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java deleted file mode 100644 index 57bc1325b..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright 2012-2019 Aerospike, Inc. - * - * Portions may be licensed to Aerospike, Inc. under one or more contributor - * license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.springframework.data.aerospike.query.reactive; - -import com.aerospike.client.Value; -import com.aerospike.client.query.IndexType; -import com.aerospike.client.query.KeyRecord; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.FilterOperation.EQ; -import static org.springframework.data.aerospike.query.FilterOperation.GEO_WITHIN; -import static org.springframework.data.aerospike.query.FilterOperation.GT; -import static org.springframework.data.aerospike.query.FilterOperation.GTEQ; -import static org.springframework.data.aerospike.query.FilterOperation.LT; -import static org.springframework.data.aerospike.query.FilterOperation.LTEQ; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.BLUE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GEO_BIN_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GREEN; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.INDEXED_GEO_SET; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.INDEXED_SET_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.ORANGE; - -/* - * These tests generate qualifiers on indexed bins. - */ -public class ReactiveIndexedQualifierTests extends BaseReactiveQueryEngineTests { - - @AfterEach - public void assertNoScans() { - additionalAerospikeTestOperations.assertNoScansForSet(INDEXED_SET_NAME); - } - - @Test - public void selectOnIndexedLTQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age < 26 - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(LT) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .filteredOn(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isLessThan(26); - return age == 25; - }) - .hasSize(queryEngineTestDataPopulator.ageCount.get(25)); - return true; - }) - .verifyComplete(); - }); - } - - /* - * If we use a qualifier on an indexed bin, The QueryEngine will generate a Filter. Verify that a LTEQ Filter - * Operation - * Generates the correct Filter.Range() filter. - */ - @Test - public void selectOnIndexedLTEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(LTEQ) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - AtomicInteger age25Count = new AtomicInteger(); - AtomicInteger age26Count = new AtomicInteger(); - results.forEach(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isLessThanOrEqualTo(26); - - if (age == 25) { - age25Count.incrementAndGet(); - } else if (age == 26) { - age26Count.incrementAndGet(); - } - }); - assertThat(age25Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(25)); - assertThat(age26Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(26)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectOnIndexedNumericEQQualifier() { - - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(EQ) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(26)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(26)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectOnIndexedGTEQQualifier() { - - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(GTEQ) - .setValue(Value.get(28)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - AtomicInteger age28Count = new AtomicInteger(); - AtomicInteger age29Count = new AtomicInteger(); - results.forEach(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isGreaterThanOrEqualTo(28); - - if (age == 28) { - age28Count.incrementAndGet(); - } else if (age == 29) { - age29Count.incrementAndGet(); - } - }); - assertThat(age28Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28)); - assertThat(age29Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(29)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectOnIndexedGTQualifier() { - - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier qualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(GT) - .setValue(Value.get(28)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(29)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(29)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectOnIndexedStringEQQualifier() { - withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - Qualifier qualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(EQ) - .setValue(Value.get(ORANGE)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(ORANGE)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(ORANGE)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectWithBlueColorQuery() { - withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(BLUE)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, new Query(qual1)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> { - assertThat(rec.record.getString("color")).isEqualTo(BLUE); - assertThat(rec.record.getInt("age")).isBetween(25, 29); - }) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(BLUE)); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectWithQualifiersOnly() { - withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(GREEN)) - .build(); - Qualifier qual2 = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(29)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_SET_NAME, null, - new Query(Qualifier.and(qual1, qual2))); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - results.forEach(keyRecord -> assertThat(results) - .allSatisfy(rec -> { - assertThat(rec.record.getString("color")).isEqualTo(GREEN); - assertThat(rec.record.getInt("age")).isBetween(28, 29); - })); - return true; - }) - .verifyComplete(); - }); - } - - @Test - public void selectWithGeoWithin() { - withIndex(namespace, INDEXED_GEO_SET, "geo_index", GEO_BIN_NAME, IndexType.GEO2DSPHERE, () -> { - double lon = -122.0; - double lat = 37.5; - double radius = 50000.0; - String rgnstr = String.format("{ \"type\": \"AeroCircle\", " - + "\"coordinates\": [[%.8f, %.8f], %f] }", - lon, lat, radius); - Qualifier qualifier = Qualifier.builder() - .setPath(GEO_BIN_NAME) - .setFilterOperation(GEO_WITHIN) - .setValue(Value.getAsGeoJSON(rgnstr)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, INDEXED_GEO_SET, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.generation).isGreaterThanOrEqualTo(1)); - return true; - }) - .verifyComplete(); - additionalAerospikeTestOperations.assertNoScansForSet(INDEXED_GEO_SET); - }); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java index 40d0d02c8..922b0ff4a 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java @@ -28,23 +28,14 @@ import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.BLUE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.COLOURS; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GREEN; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.ORANGE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.SET_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.SPECIAL_CHAR_BIN; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.SPECIAL_CHAR_SET; -import static org.springframework.data.aerospike.util.CollectionUtils.countingInt; +import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.*; /* * Tests to ensure that Qualifiers are built successfully for non indexed bins. @@ -68,7 +59,7 @@ void throwsExceptionWhenScansDisabled() { Qualifier qualifier = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.LT) - .setValue(Value.get(26)) + .setValue(26) .build(); StepVerifier.create(reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(qualifier))) @@ -82,129 +73,11 @@ void throwsExceptionWhenScansDisabled() { } @Test - public void lTQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age < 26 - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.LT) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .filteredOn(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isLessThan(26); - return age == 25; - }) - .hasSize(queryEngineTestDataPopulator.ageCount.get(25)); - return true; - }) - .verifyComplete(); - } - - @Test - public void numericLTEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.LTEQ) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - AtomicInteger age25Count = new AtomicInteger(); - AtomicInteger age26Count = new AtomicInteger(); - results.forEach(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isLessThanOrEqualTo(26); - - if (age == 25) { - age25Count.incrementAndGet(); - } else if (age == 26) { - age26Count.incrementAndGet(); - } - }); - assertThat(age25Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(25)); - assertThat(age26Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(26)); - return true; - }) - .verifyComplete(); - } - - @Test - public void numericEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(26)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(26)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(26)); - return true; - }) - .verifyComplete(); - } - - @Test - public void numericGTEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.GTEQ) - .setValue(Value.get(28)) - .build(); + public void selectAll() { + Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, null); - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - AtomicInteger age28Count = new AtomicInteger(); - AtomicInteger age29Count = new AtomicInteger(); - results.forEach(keyRecord -> { - int age = keyRecord.record.getInt("age"); - assertThat(age).isGreaterThanOrEqualTo(28); - - if (age == 28) { - age28Count.incrementAndGet(); - } else if (age == 29) { - age29Count.incrementAndGet(); - } - }); - assertThat(age28Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(25)); - assertThat(age29Count.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(26)); - return true; - }) - .verifyComplete(); - } - - @Test - public void numericGTQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.GT) - .setValue(Value.get(28)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(29)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(29)); - return true; - }) + StepVerifier.create(flux) + .expectNextCount(RECORD_COUNT) .verifyComplete(); } @@ -213,7 +86,7 @@ public void stringEQQualifier() { Qualifier stringEqQualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(ORANGE)) + .setValue(ORANGE) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -233,7 +106,7 @@ public void stringEQQualifierCaseSensitive() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(true) - .setValue(Value.get(ORANGE.toUpperCase())) + .setValue(ORANGE.toUpperCase()) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -254,7 +127,7 @@ public void stringStartWithQualifier() { Qualifier stringEqQualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get("blu")) + .setValue("blu") .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -273,7 +146,7 @@ public void stringStartWithEntireWordQualifier() { Qualifier stringEqQualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get(BLUE)) + .setValue(BLUE) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -295,7 +168,7 @@ public void stringStartWithICASEQualifier() { .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(true) - .setValue(Value.get("BLU")) + .setValue("BLU") .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -316,7 +189,7 @@ public void stringEndsWithQualifier() { Qualifier stringEqQualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(greenEnding)) + .setValue(greenEnding) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); @@ -330,33 +203,14 @@ public void stringEndsWithQualifier() { .verifyComplete(); } - @Test - public void stringEndsWithEntireWordQualifier() { - Qualifier stringEqQualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(GREEN)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(stringEqQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(GREEN)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(GREEN)); - return true; - }) - .verifyComplete(); - } - @Test public void betweenQualifier() { // Ages range from 25 -> 29. Get back age between 26 and 28 inclusive Qualifier ageRangeQualifier = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(26)) - .setSecondValue(Value.get(29)) // + 1 as upper limit is exclusive + .setValue(26) + .setSecondValue(29) // + 1 as upper limit is exclusive .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); @@ -384,54 +238,6 @@ public void betweenQualifier() { .verifyComplete(); } - @Test - public void containingQualifier() { - Map expectedColorCounts = Arrays.stream(COLOURS) - .filter(c -> c.contains("l")) - .collect(Collectors.toMap(c -> c, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.CONTAINING) - .setValue(Value.get("l")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - Map actualColors = results.stream() - .map(rec -> rec.record.getString("color")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(actualColors).isEqualTo(expectedColorCounts); - return true; - }) - .verifyComplete(); - } - - @Test - public void inQualifier() { - List inColours = Arrays.asList(COLOURS[0], COLOURS[2]); - Map expectedColorCounts = inColours.stream() - .collect(Collectors.toMap(c -> c, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - - Qualifier qualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.IN) - .setValue(Value.get(inColours)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - Map actualColors = results.stream() - .map(rec -> rec.record.getString("color")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(actualColors).isEqualTo(expectedColorCounts); - return true; - }) - .verifyComplete(); - } - @Test public void listContainsQualifier() { String searchColor = COLOURS[0]; @@ -441,7 +247,7 @@ public void listContainsQualifier() { Qualifier ageRangeQualifier = Qualifier.builder() .setPath(binName) .setFilterOperation(FilterOperation.COLLECTION_VAL_CONTAINING) - .setValue(Value.get(searchColor)) + .setValue(searchColor) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); @@ -471,7 +277,7 @@ public void mapKeysContainQualifier() { Qualifier ageRangeQualifier = Qualifier.builder() .setPath(binName) .setFilterOperation(FilterOperation.MAP_KEYS_CONTAIN) - .setValue(Value.get(searchColor)) + .setValue(searchColor) .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); @@ -491,41 +297,12 @@ public void mapKeysContainQualifier() { .verifyComplete(); } - @Test - public void testMapValuesContainQualifier() { - String searchColor = COLOURS[0]; - - String binName = "ageColorMap"; - - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath(binName) - .setFilterOperation(FilterOperation.MAP_VALUES_CONTAIN) - .setValue(Value.get(searchColor)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - // Every Record with a color == "color" has a one element map {"color" => #} - // so there are an equal amount of records with the map {"color" => #} as with a color == "color" - assertThat(results) - .allSatisfy(rec -> { - @SuppressWarnings("unchecked") Map colorMap = - (Map) rec.record.getMap(binName); - assertThat(colorMap).containsValue(searchColor); - }) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(searchColor)); - return true; - }) - .verifyComplete(); - } - @Test public void testContainingDoesNotUseSpecialCharacterQualifier() { Qualifier ageRangeQualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.CONTAINING) - .setValue(Value.get(".*")) + .setValue(".*") .build(); Flux flux = reactiveQueryEngine.select(namespace, SPECIAL_CHAR_SET, null, @@ -545,7 +322,7 @@ public void testStartWithDoesNotUseSpecialCharacterQualifier() { Qualifier ageRangeQualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get(".*")) + .setValue(".*") .build(); Flux flux = reactiveQueryEngine.select(namespace, SPECIAL_CHAR_SET, null, @@ -563,36 +340,13 @@ public void testStartWithDoesNotUseSpecialCharacterQualifier() { .verifyComplete(); } - @Test - public void testEndWithDoesNotUseSpecialCharacterQualifier() { - Qualifier ageRangeQualifier = Qualifier.builder() - .setPath(SPECIAL_CHAR_BIN) - .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(".*")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SPECIAL_CHAR_SET, null, - new Query(ageRangeQualifier)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> { - String scBin = rec.record.getString(SPECIAL_CHAR_BIN); - assertThat(scBin).endsWith(".*"); - }) - .hasSize(1); - return true; - }) - .verifyComplete(); - } - @Test public void testEQICaseDoesNotUseSpecialCharacter() { Qualifier ageRangeQualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(true) - .setValue(Value.get(".*")) + .setValue(".*") .build(); Flux flux = reactiveQueryEngine.select(namespace, SPECIAL_CHAR_SET, null, @@ -609,7 +363,7 @@ public void testContainingFindsSquareBracket() { .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.CONTAINING) .setIgnoreCase(true) - .setValue(Value.get(specialString)) + .setValue(specialString) .build(); Flux flux = reactiveQueryEngine.select(namespace, SPECIAL_CHAR_SET, null, @@ -639,7 +393,7 @@ public void stringEqualIgnoreCaseWorksOnIndexedBin() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get("BlUe")) + .setValue("BlUe") .build(); Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, @@ -657,6 +411,31 @@ public void stringEqualIgnoreCaseWorksOnIndexedBin() { } } + @Test + public void selectWithGeoWithin() { + double lon = -122.0; + double lat = 37.5; + double radius = 50000.0; + String rgnstr = String.format("{ \"type\": \"AeroCircle\", " + + "\"coordinates\": [[%.8f, %.8f], %f] }", + lon, lat, radius); + Qualifier qual1 = Qualifier.builder() + .setPath(GEO_BIN_NAME) + .setFilterOperation(FilterOperation.GEO_WITHIN) + .setValue(Value.getAsGeoJSON(rgnstr)) + .build(); + + Flux flux = reactiveQueryEngine.select(namespace, GEO_SET, null, new Query(qual1)); + StepVerifier.create(flux.collectList()) + .expectNextMatches(results -> { + assertThat(results) + .allSatisfy(rec -> assertThat(rec.record.generation).isPositive()) + .isNotEmpty(); + return true; + }) + .verifyComplete(); + } + @Test public void selectWithOrQualifiers() { String expectedColor = BLUE; @@ -665,13 +444,13 @@ public void selectWithOrQualifiers() { Qualifier qual1 = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(expectedColor)) + .setValue(expectedColor) .build(); Qualifier qual2 = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(30)) // + 1 as upper limit is exclusive + .setValue(28) + .setSecondValue(30) // + 1 as upper limit is exclusive .build(); Qualifier or = Qualifier.or(qual1, qual2); @@ -708,23 +487,23 @@ public void selectWithBetweenAndOrQualifiers() { Qualifier qualColorIsGreen = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("green")) + .setValue("green") .build(); Qualifier qualAgeBetween28And29 = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(30)) // + 1 as upper limit is exclusive + .setValue(28) + .setSecondValue(30) // + 1 as upper limit is exclusive .build(); Qualifier qualAgeIs25 = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(25)) + .setValue(25) .build(); Qualifier qualNameIs696 = Qualifier.builder() .setPath("name") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("name:696")) + .setValue("name:696") .build(); Qualifier or = Qualifier.or(qualAgeIs25, qualAgeBetween28And29, qualNameIs696); diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java deleted file mode 100644 index 638919781..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java +++ /dev/null @@ -1,210 +0,0 @@ -package org.springframework.data.aerospike.query.reactive; - -import com.aerospike.client.Value; -import com.aerospike.client.query.KeyRecord; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.KeyQualifier; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.BLUE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GEO_BIN_NAME; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.GEO_SET; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.ORANGE; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.RECORD_COUNT; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.SET_NAME; - -public class ReactiveSelectorTests extends BaseReactiveQueryEngineTests { - - @Test - public void selectOneWithKey() { - KeyQualifier kq = new KeyQualifier(Value.get("selector-test:3")); - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(kq)); - - StepVerifier.create(flux) - .expectNextCount(1) - .verifyComplete(); - } - - @Test - public void selectOneWithNonExistingKey() { - KeyQualifier kq = new KeyQualifier(Value.get("selector-test:no-such-record")); - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(kq)); - - StepVerifier.create(flux) - .expectNextCount(0) - .verifyComplete(); - } - - @Test - public void selectAll() { - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, null); - - StepVerifier.create(flux) - .expectNextCount(RECORD_COUNT) - .verifyComplete(); - } - - @Test - public void selectEndsWith() { - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get("e")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(qual1)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getString("color")).endsWith("e")) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(ORANGE) - + queryEngineTestDataPopulator.colourCounts.get(BLUE)); - return true; - }).verifyComplete(); - } - - @Test - public void selectStartsWith() { - Qualifier startsWithQual = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get("bl")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(startsWithQual)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getString("color")).startsWith("bl")) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(BLUE)); - return true; - }) - .verifyComplete(); - } - - @Test - public void startWithAndEqualIgnoreCaseReturnsAllItems() { - boolean ignoreCase = true; - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("BLUE")) - .build(); - - Qualifier qual2 = Qualifier.builder() - .setPath("name") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("NA")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(Qualifier.and(qual1, - qual2))); - StepVerifier.create(flux) - .expectNextCount(queryEngineTestDataPopulator.colourCounts.get("blue")) - .verifyComplete(); - } - - @Test - public void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { - boolean ignoreCase = false; - Qualifier qual1 = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("BLUE")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(qual1)); - StepVerifier.create(flux) - .expectNextCount(0) - .verifyComplete(); - } - - @Test - public void startWithIgnoreCaseReturnsNoItemsIfNoneMatched() { - boolean ignoreCase = false; - Qualifier qual1 = Qualifier.builder() - .setPath("name") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("NA")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(qual1)); - StepVerifier.create(flux) - .expectNextCount(0) - .verifyComplete(); - } - - @Test - public void stringEqualIgnoreCaseWorksOnUnindexedBin() { - boolean ignoreCase = true; - String expectedColor = "blue"; - - Qualifier caseInsensitiveQual = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("BlUe")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(caseInsensitiveQual)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(expectedColor)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(BLUE)); - return true; - }) - .verifyComplete(); - } - - @Test - public void stringEqualIgnoreCaseWorksRequiresFullMatch() { - boolean ignoreCase = true; - Qualifier caseInsensitiveQual = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue(Value.get("lue")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, SET_NAME, null, new Query(caseInsensitiveQual)); - - StepVerifier.create(flux) - .expectNextCount(0) - .verifyComplete(); - } - - @Test - public void selectWithGeoWithin() { - double lon = -122.0; - double lat = 37.5; - double radius = 50000.0; - String rgnstr = String.format("{ \"type\": \"AeroCircle\", " - + "\"coordinates\": [[%.8f, %.8f], %f] }", - lon, lat, radius); - Qualifier qual1 = Qualifier.builder() - .setPath(GEO_BIN_NAME) - .setFilterOperation(FilterOperation.GEO_WITHIN) - .setValue(Value.getAsGeoJSON(rgnstr)) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, GEO_SET, null, new Query(qual1)); - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.generation).isPositive()) - .isNotEmpty(); - return true; - }) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java deleted file mode 100644 index dfd068999..000000000 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.springframework.data.aerospike.query.reactive; - -import com.aerospike.client.Value; -import com.aerospike.client.query.KeyRecord; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.USERS_SET; - -public class ReactiveUsersTests extends BaseReactiveQueryEngineTests { - - @Test - public void usersInNorthRegion() { - Qualifier qualifier = Qualifier.builder() - .setPath("region") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("n")) - .build(); - - Flux flux = reactiveQueryEngine.select(namespace, USERS_SET, null, new Query(qualifier)); - - StepVerifier.create(flux.collectList()) - .expectNextMatches(results -> { - assertThat(results) - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("region")).isEqualTo("n")); - return true; - }) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/query/BaseQueryEngineTests.java b/src/test/java/org/springframework/data/aerospike/query/sync/BaseQueryEngineTests.java similarity index 93% rename from src/test/java/org/springframework/data/aerospike/query/BaseQueryEngineTests.java rename to src/test/java/org/springframework/data/aerospike/query/sync/BaseQueryEngineTests.java index 54561f06a..51dec02f8 100644 --- a/src/test/java/org/springframework/data/aerospike/query/BaseQueryEngineTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/sync/BaseQueryEngineTests.java @@ -1,9 +1,10 @@ -package org.springframework.data.aerospike.query; +package org.springframework.data.aerospike.query.sync; import com.aerospike.client.query.IndexType; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; +import org.springframework.data.aerospike.query.QueryEngineTestDataPopulator; import org.springframework.data.aerospike.query.model.Index; import org.springframework.data.aerospike.query.model.IndexKey; import org.springframework.data.aerospike.util.AwaitilityUtils; diff --git a/src/test/java/org/springframework/data/aerospike/query/FilterOperationRegexpBuilderTest.java b/src/test/java/org/springframework/data/aerospike/query/sync/FilterOperationRegexpBuilderTest.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/query/FilterOperationRegexpBuilderTest.java rename to src/test/java/org/springframework/data/aerospike/query/sync/FilterOperationRegexpBuilderTest.java index cec548ff1..dc3c127c2 100644 --- a/src/test/java/org/springframework/data/aerospike/query/FilterOperationRegexpBuilderTest.java +++ b/src/test/java/org/springframework/data/aerospike/query/sync/FilterOperationRegexpBuilderTest.java @@ -14,7 +14,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.data.aerospike.query; +package org.springframework.data.aerospike.query.sync; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.util.FilterOperationRegexpBuilder; diff --git a/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/sync/QualifierTests.java similarity index 77% rename from src/test/java/org/springframework/data/aerospike/query/QualifierTests.java rename to src/test/java/org/springframework/data/aerospike/query/sync/QualifierTests.java index e86213010..c948daec8 100644 --- a/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/sync/QualifierTests.java @@ -14,7 +14,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package org.springframework.data.aerospike.query; +package org.springframework.data.aerospike.query.sync; import com.aerospike.client.Value; import com.aerospike.client.query.IndexType; @@ -24,6 +24,8 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.data.aerospike.query.FilterOperation; +import org.springframework.data.aerospike.query.KeyRecordIterator; import org.springframework.data.aerospike.query.qualifier.Qualifier; import org.springframework.data.aerospike.repository.query.Query; import org.springframework.data.aerospike.util.CollectionUtils; @@ -61,7 +63,7 @@ void throwsExceptionWhenScansDisabled() { Qualifier qualifier = Qualifier.builder() .setPath("age") // bin name .setFilterOperation(FilterOperation.LT) - .setValue(Value.get(26)).build(); + .setValue(26).build(); //noinspection resource assertThatThrownBy(() -> queryEngine.select(namespace, SET_NAME, null, new Query(qualifier))) @@ -72,22 +74,6 @@ void throwsExceptionWhenScansDisabled() { } } - @SuppressWarnings("removal") - @Test - void selectOneWitKey() { - KeyQualifier kq = new KeyQualifier(Value.get("selector-test:3")); - KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, new Query(kq)); - assertThat(iterator).toIterable().hasSize(1); - } - - @SuppressWarnings("removal") - @Test - void selectOneWitKeyNonExisting() { - KeyQualifier kq = new KeyQualifier(Value.get("selector-test:unknown")); - KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, new Query(kq)); - assertThat(iterator).toIterable().isEmpty(); - } - @Test void selectAll() { KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, null); @@ -100,7 +86,7 @@ void lTQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("age") // bin name .setFilterOperation(FilterOperation.LT) - .setValue(Value.get(26)) + .setValue(26) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -113,85 +99,7 @@ void lTQualifier() { } @Test - void numericLTEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") // bin name - .setFilterOperation(FilterOperation.LTEQ) - .setValue(Value.get(26)) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - Map ageCount = CollectionUtils.toStream(it) - .map(rec -> rec.record.getInt("age")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(ageCount.keySet()) - .isNotEmpty() - .allSatisfy(age -> assertThat(age).isLessThanOrEqualTo(26)); - assertThat(ageCount.get(25)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(25)); - assertThat(ageCount.get(26)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(26)); - } - - @Test - void numericEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = Qualifier.builder() - .setPath("age") // bin name - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(26)) - .build(); - - KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - assertThat(iterator) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(26)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(26)); - } - - @Test - void numericGTEQQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = Qualifier.builder() - .setPath("age") // bin name - .setFilterOperation(FilterOperation.GTEQ) - .setValue(Value.get(28)) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - Map ageCount = CollectionUtils.toStream(it) - .map(rec -> rec.record.getInt("age")) - .collect(Collectors.groupingBy(k -> k, countingInt())); - assertThat(ageCount.keySet()) - .isNotEmpty() - .allSatisfy(age -> assertThat(age).isGreaterThanOrEqualTo(28)); - assertThat(ageCount.get(28)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28)); - assertThat(ageCount.get(29)).isEqualTo(queryEngineTestDataPopulator.ageCount.get(29)); - } - - @Test - void numericGTQualifier() { - // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier qualifier = Qualifier.builder() - .setPath("age") // bin name - .setFilterOperation(FilterOperation.GT) - .setValue(Value.get(28)) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - assertThat(it) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getInt("age")).isEqualTo(29)) - .hasSize(queryEngineTestDataPopulator.ageCount.get(29)); - } - - @Test - void metadataSinceUpdateEQQualifier() { + void metadataSinceUpdateGTQualifier() { Qualifier qualifier = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.GT) @@ -212,7 +120,7 @@ void stringEQQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(ORANGE)) + .setValue(ORANGE) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -230,7 +138,7 @@ void stringEQIgnoreCaseQualifier() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(true) - .setValue(Value.get(ORANGE.toUpperCase())) + .setValue(ORANGE.toUpperCase()) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -249,7 +157,7 @@ void stringEqualIgnoreCaseWorksOnUnindexedBin() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get("BlUe")) + .setValue("BlUe") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -269,7 +177,7 @@ void stringEqualIgnoreCaseWorksOnIndexedBin() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get("BlUe")) + .setValue("BlUe") .build(); KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -292,7 +200,7 @@ void stringEqualIgnoreCaseWorksRequiresFullMatch() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get("lue")) + .setValue("lue") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -305,7 +213,7 @@ void stringStartWithQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get(BLUE.substring(0, 2))) + .setValue(BLUE.substring(0, 2)) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -322,7 +230,7 @@ void stringStartWithEntireWordQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get(BLUE)) + .setValue(BLUE) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -340,7 +248,7 @@ void stringStartWithICASEQualifier() { .setPath("color") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(true) - .setValue(Value.get("BLU")) + .setValue("BLU") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -357,41 +265,7 @@ void stringEndsWithQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(GREEN.substring(2))) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - assertThat(it) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isEqualTo(GREEN)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(GREEN)); - } - - @Test - void selectEndsWith() { - Qualifier qualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get("e")) - .build(); - - KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); - - assertThat(it) - .toIterable() - .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.getString("color")).isIn(BLUE, ORANGE)) - .hasSize(queryEngineTestDataPopulator.colourCounts.get(BLUE) + queryEngineTestDataPopulator.colourCounts.get(ORANGE)); - } - - @Test - void stringEndsWithEntireWordQualifier() { - Qualifier qualifier = Qualifier.builder() - .setPath("color") - .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(GREEN)) + .setValue(GREEN.substring(2)) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -409,8 +283,8 @@ void betweenQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(26)) - .setSecondValue(Value.get(29)) // + 1 as upper limit is exclusive + .setValue(26) + .setSecondValue(29) // + 1 as upper limit is exclusive .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -435,7 +309,7 @@ void containingQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.CONTAINING) - .setValue(Value.get("l")) + .setValue("l") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -455,7 +329,7 @@ void inQualifier() { Qualifier qualifier = Qualifier.builder() .setPath("color") .setFilterOperation(FilterOperation.IN) - .setValue(Value.get(inColors)) + .setValue(inColors) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -474,7 +348,7 @@ void listContainsQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(binName) .setFilterOperation(FilterOperation.COLLECTION_VAL_CONTAINING) - .setValue(Value.get(searchColor)) + .setValue(searchColor) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -498,7 +372,7 @@ void mapKeysContainQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(binName) .setFilterOperation(FilterOperation.MAP_KEYS_CONTAIN) - .setValue(Value.get(searchColor)) + .setValue(searchColor) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -521,7 +395,7 @@ void mapValuesContainQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(binName) .setFilterOperation(FilterOperation.MAP_VALUES_CONTAIN) - .setValue(Value.get(searchColor)) + .setValue(searchColor) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qualifier)); @@ -541,7 +415,7 @@ void containingDoesNotUseSpecialCharacterQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.CONTAINING) - .setValue(Value.get(".*")) + .setValue(".*") .build(); KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, new Query(qualifier)); @@ -557,7 +431,7 @@ void startWithDoesNotUseSpecialCharacterQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.STARTS_WITH) - .setValue(Value.get(".*")) + .setValue(".*") .build(); KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, new Query(qualifier)); @@ -573,7 +447,7 @@ void endWithDoesNotUseSpecialCharacterQualifier() { Qualifier qualifier = Qualifier.builder() .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.ENDS_WITH) - .setValue(Value.get(".*")) + .setValue(".*") .build(); KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, new Query(qualifier)); @@ -590,7 +464,7 @@ void eQIcaseDoesNotUseSpecialCharacter() { .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(true) - .setValue(Value.get(".*")) + .setValue(".*") .build(); KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, new Query(qualifier)); @@ -605,7 +479,7 @@ void containingFindsSquareBracket(String specialString) { .setPath(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.CONTAINING) .setIgnoreCase(true) - .setValue(Value.get(specialString)) + .setValue(specialString) .build(); KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, new Query(qualifier)); @@ -644,14 +518,14 @@ void startWithAndEqualIgnoreCaseReturnsAllItems() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get(BLUE.toUpperCase())) + .setValue(BLUE.toUpperCase()) .build(); Qualifier qual2 = Qualifier.builder() .setPath("name") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(ignoreCase) - .setValue(Value.get("NA")) + .setValue("NA") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(Qualifier.and(qual1, qual2))); @@ -669,7 +543,7 @@ void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { .setPath("color") .setFilterOperation(FilterOperation.EQ) .setIgnoreCase(ignoreCase) - .setValue(Value.get(BLUE.toUpperCase())) + .setValue(BLUE.toUpperCase()) .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qual1)); @@ -684,7 +558,7 @@ void startWithIgnoreCaseReturnsNoItemsIfNoneMatched() { .setPath("name") .setFilterOperation(FilterOperation.STARTS_WITH) .setIgnoreCase(ignoreCase) - .setValue(Value.get("NA")) + .setValue("NA") .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, new Query(qual1)); @@ -697,23 +571,23 @@ void selectWithBetweenAndOrQualifiers() { Qualifier colorIsGreen = Qualifier.builder() .setPath("color") // bin name .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(GREEN)) + .setValue(GREEN) .build(); Qualifier ageBetween28And29 = Qualifier.builder() .setPath("age") // bin name .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(29)) + .setValue(28) + .setSecondValue(29) .build(); Qualifier ageIs25 = Qualifier.builder() .setPath("age") // bin name .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(25)) + .setValue(25) .build(); Qualifier nameIs696 = Qualifier.builder() .setPath("name") // bin name .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("name:696")) + .setValue("name:696") .build(); Qualifier or = Qualifier.or(ageIs25, ageBetween28And29, nameIs696); @@ -746,13 +620,13 @@ void selectWithOrQualifiers() { Qualifier colorIsBlue = Qualifier.builder() .setPath("color") // bin name .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(BLUE)) + .setValue(BLUE) .build(); Qualifier ageBetween28And29 = Qualifier.builder() .setPath("age") // bin name .setFilterOperation(FilterOperation.BETWEEN) - .setValue(Value.get(28)) - .setSecondValue(Value.get(30)) // + 1 as upper limit is exclusive + .setValue(28) + .setSecondValue(30) // + 1 as upper limit is exclusive .build(); Qualifier or = Qualifier.or(colorIsBlue, ageBetween28And29); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/IndexedPersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/IndexedPersonRepositoryQueryTests.java deleted file mode 100644 index a25287aef..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/IndexedPersonRepositoryQueryTests.java +++ /dev/null @@ -1,245 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed; - -import com.aerospike.client.Value; -import com.aerospike.client.cdt.CTX; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.TestInstance; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseBlockingIntegrationTests; -import org.springframework.data.aerospike.query.model.Index; -import org.springframework.data.aerospike.sample.Address; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.sample.IndexedPersonRepository; - -import java.util.ArrayList; -import java.util.List; - -import static com.aerospike.client.query.IndexCollectionType.LIST; -import static com.aerospike.client.query.IndexCollectionType.MAPKEYS; -import static com.aerospike.client.query.IndexCollectionType.MAPVALUES; -import static com.aerospike.client.query.IndexType.NUMERIC; -import static com.aerospike.client.query.IndexType.STRING; -import static org.springframework.data.aerospike.util.AsCollections.of; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class IndexedPersonRepositoryQueryTests extends BaseBlockingIntegrationTests { - - @BeforeEach - public void beforeEach(TestInfo testInfo) { - assertBinsAreIndexed(testInfo); - } - - @Autowired - protected IndexedPersonRepository repository; - protected static final IndexedPerson john = IndexedPerson.builder() - .id(nextId()) - .firstName("John") - .lastName("Farmer") - .age(42) - .strings(List.of("str1", "str2")) - .ints(List.of(450, 550, 990)) - .address(new Address("Foo Street 1", 1, "C0123", "Bar")) - .build(); - protected static final IndexedPerson peter = IndexedPerson.builder() - .id(nextId()) - .firstName("Peter") - .lastName("Macintosh") - .age(41) - .strings(List.of("str1", "str2", "str3")) - .build(); - protected static final IndexedPerson jane = IndexedPerson.builder() - .id(nextId()) - .firstName("Jane") - .lastName("Gillaham") - .age(49) - .intMap(of("key1", 0, "key2", 1)) - .ints(List.of(550, 600, 990)) - .address(new Address("Foo Street 2", 2, "C0124", "C0123")) - .build(); - protected static final IndexedPerson billy = IndexedPerson.builder() - .id(nextId()) - .firstName("Billy") - .lastName("Smith") - .age(25) - .stringMap(of("key1", "val1", "key2", "val2")) - .address(new Address(null, null, null, null)) - .build(); - protected static final IndexedPerson tricia = IndexedPerson.builder() - .id(nextId()) - .firstName("Tricia") - .lastName("James") - .age(31) - .intMap(of("key1", 0, "key2", 1)) - .build(); - protected static final List allIndexedPersons = List.of(john, peter, jane, billy, tricia); - - @BeforeAll - public void beforeAll() { - additionalAerospikeTestOperations.deleteAll(repository, allIndexedPersons); - additionalAerospikeTestOperations.saveAll(repository, allIndexedPersons); - String setName = template.getSetName(IndexedPerson.class); - - List newIndexes = new ArrayList<>(); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_first_name_index") - .bin("firstName") - .indexType(STRING) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_last_name_index") - .bin("lastName") - .indexType(STRING) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_age_index") - .bin("age") - .indexType(NUMERIC) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_isActive_index") - .bin("isActive") - .indexType(STRING) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_strings_index") - .bin("strings") - .indexType(STRING) - .indexCollectionType(LIST) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_ints_index") - .bin("ints") - .indexType(NUMERIC) - .indexCollectionType(LIST) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_string_map_keys_index") - .bin("stringMap") - .indexType(STRING) - .indexCollectionType(MAPKEYS) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_string_map_values_index") - .bin("stringMap") - .indexType(STRING) - .indexCollectionType(MAPVALUES).build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_int_map_keys_index") - .bin("intMap") - .indexType(STRING) - .indexCollectionType(MAPKEYS) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_int_map_values_index") - .bin("intMap") - .indexType(NUMERIC) - .indexCollectionType(MAPVALUES) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_address_values_index") - .bin("address") - .indexType(STRING) - .indexCollectionType(MAPVALUES) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_friend_address_values_index") - .bin("friend") - .indexType(STRING) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.mapKey(Value.get("address"))}) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_addressesList_0_values_index") - .bin("addressesList") - .indexType(STRING) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.listIndex(0)}) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_friend_bestFriend_address_values_index") - .bin("friend") - .indexType(STRING) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.mapKey(Value.get("bestFriend")), CTX.mapKey(Value.get("address"))}) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_friend_bestFriend_address_values_num_index") - .bin("friend") - .indexType(NUMERIC) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.mapKey(Value.get("bestFriend")), CTX.mapKey(Value.get("address"))}) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_bestFriend_friend_address_values_index") - .bin("bestFriend") - .indexType(STRING) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.mapKey(Value.get("friend")), CTX.mapKey(Value.get("address"))}) - .build()); - newIndexes.add(Index.builder() - .set(setName) - .name("indexed_person_bestFriend_friend_address_values_num_index") - .bin("bestFriend") - .indexType(NUMERIC) - .indexCollectionType(MAPVALUES) - .ctx(new CTX[]{CTX.mapKey(Value.get("friend")), CTX.mapKey(Value.get("address"))}) - .build()); - additionalAerospikeTestOperations.createIndexes(newIndexes); - } - - @AfterAll - public void afterAll() { - additionalAerospikeTestOperations.deleteAll(repository, allIndexedPersons); - List dropIndexes = new ArrayList<>(); - String setName = template.getSetName(IndexedPerson.class); - - dropIndexes.add(Index.builder().set(setName).name("indexed_person_first_name_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_last_name_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_age_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_isActive_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_strings_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_ints_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_string_map_keys_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_string_map_values_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_int_map_keys_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_int_map_values_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_address_keys_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_address_values_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_friend_address_keys_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_friend_address_values_index").build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_friend_bestFriend_address_keys_index") - .build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_friend_bestFriend_address_values_num_index") - .build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_bestFriend_friend_address_values_index") - .build()); - dropIndexes.add(Index.builder().set(setName).name("indexed_person_bestFriend_friend_address_values_num_index") - .build()); - additionalAerospikeTestOperations.dropIndexes(dropIndexes); - } - - @AfterEach - public void assertNoScans() { - additionalAerospikeTestOperations.assertNoScansForSet(template.getSetName(IndexedPerson.class)); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/countBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/countBy/EqualsTests.java deleted file mode 100644 index 5a5e38ece..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/countBy/EqualsTests.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.countBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.NoSecondaryIndexRequired; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * Tests for the "Equals" repository query. Keywords: Is, Equals (or no keyword). - */ -public class EqualsTests extends IndexedPersonRepositoryQueryTests { - - @Test - @NoSecondaryIndexRequired - public void countBySimpleProperty_String_NegativeTest() { - assertThatThrownBy(() -> repository.countByLastName("Lerois")) - .isInstanceOf(UnsupportedOperationException.class) - .hasMessage("Query method IndexedPerson.countByLastName is not supported"); - - assertThatThrownBy(() -> repository.countByLastName("Smirnova")) - .isInstanceOf(UnsupportedOperationException.class) - .hasMessage("Query method IndexedPerson.countByLastName is not supported"); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/BetweenTests.java deleted file mode 100644 index 1aa0379bd..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/BetweenTests.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import com.aerospike.client.Value; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.util.TestUtils; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Is between" repository query. Keywords: Between, IsBetween. - */ -public class BetweenTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyBetween_Integer() { - assertQueryHasSecIndexFilter("findByAgeBetween", IndexedPerson.class, 40, 45); - Iterable it = repository.findByAgeBetween(40, 45); - assertThat(it).hasSize(2).contains(john, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyBetween_Integer_OrderBySimpleProperty() { - assertQueryHasSecIndexFilter("findByAgeBetweenOrderByLastName", IndexedPerson.class, 30, 45); - Iterable it = repository.findByAgeBetweenOrderByLastName(30, 45); - assertThat(it).hasSize(3); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyBetween_Integer_AND_SimplePropertyEquals_String() { - QueryParam ageBetween = QueryParam.of(40, 45); - QueryParam lastName = QueryParam.of("Matthews"); - assertQueryHasSecIndexFilter("findByAgeBetweenAndLastName", IndexedPerson.class, ageBetween, lastName); - Iterable it = repository.findByAgeBetweenAndLastName(ageBetween, lastName); - assertThat(it).hasSize(0); - - ageBetween = QueryParam.of(20, 26); - lastName = QueryParam.of("Smith"); - assertQueryHasSecIndexFilter("findByAgeBetweenAndLastName", IndexedPerson.class, ageBetween, lastName); - Iterable result = repository.findByAgeBetweenAndLastName(ageBetween, lastName); - assertThat(result).hasSize(1).contains(billy); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyBetween_Integer_OR_SimplePropertyEquals_String() { - QueryParam ageBetween = QueryParam.of(40, 45); - QueryParam lastName = QueryParam.of("James"); - assertThat(queryHasSecIndexFilter("findByAgeBetween", IndexedPerson.class, 40, 45) - || queryHasSecIndexFilter("findByLastName", IndexedPerson.class, "James")).isTrue(); - Iterable it = repository.findByAgeBetweenOrLastName(ageBetween, lastName); - assertThat(it).containsExactlyInAnyOrder(john, peter, tricia); - - ageBetween = QueryParam.of(20, 26); - lastName = QueryParam.of("Macintosh"); - assertThat(queryHasSecIndexFilter("findByAgeBetween", IndexedPerson.class, 20, 26) - || queryHasSecIndexFilter("findByLastName", IndexedPerson.class, "Macintosh")).isTrue(); - Iterable result = repository.findByAgeBetweenOrLastName(ageBetween, lastName); - assertThat(result).containsExactlyInAnyOrder(billy, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "bestFriend", entityClass = IndexedPerson.class) - void findByNestedSimplePropertyBetween_Integer_3_levels() { - int apartment = 2; - assertThat(jane.getAddress().getApartment()).isEqualTo(apartment); - tricia.setFriend(jane); - repository.save(tricia); - billy.setBestFriend(tricia); - repository.save(billy); - assertThat(billy.getBestFriend().getFriend().getAddress().getApartment()).isEqualTo(apartment); - - assertQueryHasSecIndexFilter("findByBestFriendFriendAddressApartmentBetween", IndexedPerson.class, 1, 3); - List persons = repository.findByBestFriendFriendAddressApartmentBetween(1, 3); - assertThat(persons).contains(billy); - - // An alternative way to perform the same using a custom query - Qualifier nestedApartmentBetween = Qualifier.builder() - // find records having a map with a key between given values - // POJOs are saved as Maps - .setFilterOperation(FilterOperation.MAP_VAL_BETWEEN_BY_KEY) // POJOs are saved as Maps - .setPath("bestFriend.friend.address.apartment") // path includes bin name, context and the required map key - .setValue(Value.get(1)) // lower limit for the value of the nested key - .setSecondValue(Value.get(3)) // lower limit for the value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedApartmentBetween), IndexedPerson.class); - Iterable persons2 = repository.findUsingQuery(new Query(nestedApartmentBetween)); - assertThat(persons).isEqualTo(persons2); - TestUtils.setFriendsToNull(repository, tricia, billy); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/ContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/ContainingTests.java deleted file mode 100644 index d4b7d54dd..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/ContainingTests.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY_VALUE_PAIR; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.VALUE; - -/** - * Tests for the "Contains" repository query. Keywords: Containing, IsContaining, Contains. - */ -public class ContainingTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "strings", entityClass = IndexedPerson.class) - void findByCollectionContaining_String() { - assertQueryHasSecIndexFilter("findByStringsContaining", IndexedPerson.class, "str1"); - assertThat(repository.findByStringsContaining("str1")).containsOnly(john, peter); - assertThat(repository.findByStringsContaining("str2")).containsOnly(john, peter); - assertThat(repository.findByStringsContaining("str3")).containsOnly(peter); - assertThat(repository.findByStringsContaining("str5")).isEmpty(); - } - - @Test - @AssertBinsAreIndexed(binNames = "ints", entityClass = IndexedPerson.class) - void findByCollectionContaining_Integer() { - assertQueryHasSecIndexFilter("findByIntsContaining", IndexedPerson.class, 550); - assertThat(repository.findByIntsContaining(550)).containsOnly(john, jane); - assertThat(repository.findByIntsContaining(990)).containsOnly(john, jane); - assertThat(repository.findByIntsContaining(600)).containsOnly(jane); - assertThat(repository.findByIntsContaining(7777)).isEmpty(); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - void findByMapKeysContaining_String() { - assertThat(billy.getStringMap()).containsKey("key1"); - assertQueryHasSecIndexFilter("findByStringMapContaining", IndexedPerson.class, KEY, "key1"); - - List persons = repository.findByStringMapContaining(KEY, "key1"); - assertThat(persons).contains(billy); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - void findByMapValuesContaining_String() { - assertThat(billy.getStringMap()).containsValue("val1"); - assertQueryHasSecIndexFilter("findByStringMapContaining", IndexedPerson.class, VALUE, "key1"); - - List persons = repository.findByStringMapContaining(VALUE, "val1"); - assertThat(persons).contains(billy); - } - - @Test - @AssertBinsAreIndexed(binNames = "intMap", entityClass = IndexedPerson.class) - void findByExactMapKeyAndValue_Integer() { - assertThat(tricia.getIntMap()).containsKey("key1"); - assertThat(tricia.getIntMap().get("key1")).isEqualTo(0); - assertQueryHasSecIndexFilter("findByIntMapContaining", IndexedPerson.class, KEY_VALUE_PAIR, "key1", 0); - - Iterable result = repository.findByIntMapContaining(KEY_VALUE_PAIR, "key1", 0); - assertThat(result).contains(tricia); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CrudRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CrudRepositoryQueryTests.java deleted file mode 100644 index da77500da..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CrudRepositoryQueryTests.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.NoSecondaryIndexRequired; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.sample.Person; - -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the CrudRepository queries API. - */ -public class CrudRepositoryQueryTests extends IndexedPersonRepositoryQueryTests { - - @Test - @NoSecondaryIndexRequired - public void findsPersonById() { - Optional person = repository.findById(john.getId()); - - assertThat(person).hasValueSatisfying(actual -> { - assertThat(actual).isInstanceOf(Person.class); - assertThat(actual).isEqualTo(john); - }); - } - - @Test - @NoSecondaryIndexRequired - public void findsAllWithGivenIds() { - List result = (List) repository.findAllById(List.of(john.getId(), - billy.getId())); - - assertThat(result) - .contains(john, billy) - .hasSize(2) - .doesNotContain(jane, peter, tricia); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CustomQueriesTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CustomQueriesTests.java deleted file mode 100644 index c2d167cdd..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/CustomQueriesTests.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import com.aerospike.client.Value; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.Address; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.util.TestUtils; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CustomQueriesTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String_map_in_map() { - String zipCode = "C0123"; - assertThat(john.getAddress().getZipCode()).isEqualTo(zipCode); - jane.setFriend(john); - repository.save(jane); - - Qualifier nestedZipCodeEq = Qualifier.builder() - // find records having a nested map with a key that equals a value - // POJOs are saved as Maps - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // where address's key 'zipCode' has value "C0123" - .setPath("friend.address.zipCode") // path includes bin name, context and the required map key - .setValue(zipCode) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedZipCodeEq), IndexedPerson.class); - Iterable result = repository.findUsingQuery(new Query(nestedZipCodeEq)); - assertThat(result).contains(jane); - TestUtils.setFriendsToNull(repository, jane); - } - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String_map_in_list() { - String zipCode = "ZipCode"; - john.setAddressesList(List.of(new Address("Street", 100, zipCode, "City"))); - repository.save(john); - assertThat(john.getAddressesList().get(0).getZipCode()).isEqualTo(zipCode); - - Qualifier nestedZipCodeEq = Qualifier.builder() - // find records having a nested map with a key that equals a value - // POJOs are saved as Maps - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // where list element 'zipCode' has value "ZipCode" - .setPath("addressesList.[0].zipCode") // path: bin name, context (list index) and the required map key - .setValue(Value.get(zipCode)) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedZipCodeEq), IndexedPerson.class); - Iterable resultTest2 = repository.findUsingQuery(new Query(nestedZipCodeEq)); - Assertions.assertThat(resultTest2).contains(john); - john.setAddressesList(null); - repository.save(john); - } - - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String_3_levels() { - String zipCode = "C0123"; - assertThat(john.getAddress().getZipCode()).isEqualTo(zipCode); - jane.setBestFriend(john); - repository.save(jane); - peter.setFriend(jane); - repository.save(peter); - - Qualifier nestedZipCodeEq = Qualifier.builder() - // find records having a nested map with a key that equals a value - // POJOs are saved as Maps - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // where address's key 'zipCode' has value "C0123" - .setPath("friend.bestFriend.address.zipCode") // path includes bin name, context and the required map key - .setValue(Value.get(zipCode)) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedZipCodeEq), IndexedPerson.class); - Iterable result = repository.findUsingQuery(new Query(nestedZipCodeEq)); - assertThat(result).contains(peter); - TestUtils.setFriendsToNull(repository, jane, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_Integer_3_levels() { - int apartment = 1; - assertThat(john.getAddress().getApartment()).isEqualTo(apartment); - jane.setBestFriend(john); - repository.save(jane); - peter.setFriend(jane); - repository.save(peter); - - Qualifier nestedApartmentEq = Qualifier.builder() - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // where address's key 'apartment' has value 1 - .setPath("friend.bestFriend.address.apartment") // path includes bin name, context and the required map key - .setValue(Value.get(apartment)) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedApartmentEq), IndexedPerson.class); - Iterable result = repository.findUsingQuery(new Query(nestedApartmentEq)); - assertThat(result).contains(peter); - TestUtils.setFriendsToNull(repository, jane, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "bestFriend", entityClass = IndexedPerson.class) - void findByNestedSimplePropertyBetween_Integer_3_levels() { - int apartment = 2; - assertThat(jane.getAddress().getApartment()).isEqualTo(apartment); - tricia.setFriend(jane); - repository.save(tricia); - billy.setBestFriend(tricia); - repository.save(billy); - assertThat(billy.getBestFriend().getFriend().getAddress().getApartment()).isEqualTo(apartment); - - // An alternative way to perform the same using a custom query - Qualifier nestedApartmentBetween = Qualifier.builder() - // find records having a map with a key between given values - // POJOs are saved as Maps - // where address's key 'apartment' has value between 1 and 3 - .setFilterOperation(FilterOperation.MAP_VAL_BETWEEN_BY_KEY) - .setPath("bestFriend.friend.address.apartment") // path includes bin name, context and the required map key - .setValue(Value.get(1)) // lower limit for the value of the nested key - .setSecondValue(Value.get(3)) // lower limit for the value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedApartmentBetween), IndexedPerson.class); - Iterable persons = repository.findUsingQuery(new Query(nestedApartmentBetween)); - assertThat(persons).contains(billy); - TestUtils.setFriendsToNull(repository, tricia, billy); - } -} - diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/EqualsTests.java deleted file mode 100644 index 620336106..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/EqualsTests.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import com.aerospike.client.Value; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.BaseIntegrationTests; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.sample.Person; -import org.springframework.data.aerospike.util.TestUtils; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Equals" repository query. Keywords: Is, Equals (or no keyword). - */ -public class EqualsTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "lastName", entityClass = IndexedPerson.class) - public void findBySimplePropertyEquals_String() { - assertQueryHasSecIndexFilter("findByLastName", IndexedPerson.class, "Gillaham"); - List result = repository.findByLastName("Gillaham"); - assertThat(result).containsOnly(jane); - - assertQueryHasSecIndexFilter("findByFirstName", IndexedPerson.class, "Tricia"); - assertBinIsIndexed("firstName", IndexedPerson.class); - List result2 = repository.findByFirstName("Tricia"); - assertThat(result2).containsOnly(tricia); - } - - @Test - @AssertBinsAreIndexed(binNames = "isActive", entityClass = IndexedPerson.class) - void findBySimplePropertyEquals_Boolean_NoSecondaryIndexFilter() { - boolean initialValue = Value.UseBoolBin; - Value.UseBoolBin = true; // save boolean as bool, available since Server 5.6+ - - IndexedPerson boolBinPerson = IndexedPerson.from( - Person.builder() - .id(BaseIntegrationTests.nextId()) - .isActive(true) - .firstName("Test") - .build() - ); - repository.save(boolBinPerson); - - assertThat(queryHasSecIndexFilter("findByIsActive", IndexedPerson.class, true)).isFalse(); - assertThat(repository.findByIsActive(true)).contains(boolBinPerson); - - Value.UseBoolBin = initialValue; // set back to the default value - repository.delete(boolBinPerson); - } - - @Test - @AssertBinsAreIndexed(binNames = {"isActive", "firstName"}, entityClass = IndexedPerson.class) - public void findByTwoSimplePropertiesEqual_BooleanAndString() { - assertThat(tricia.isActive()).isFalse(); - QueryParam paramFalse = QueryParam.of(false); - QueryParam paramTricia = QueryParam.of("Tricia"); - - assertQueryHasSecIndexFilter("findByIsActiveAndFirstName", IndexedPerson.class, paramFalse, paramTricia); - List result = repository.findByIsActiveAndFirstName(paramFalse, paramTricia); - - assertThat(result).containsOnly(tricia); - } - - @Test - @AssertBinsAreIndexed(binNames = {"firstName", "age"}, entityClass = IndexedPerson.class) - public void findByTwoSimplePropertiesEqual_StringAndInteger() { - QueryParam firstName = QueryParam.of("Billy"); - QueryParam age = QueryParam.of(25); - assertQueryHasSecIndexFilter("findByFirstNameAndAge", IndexedPerson.class, firstName, age); - List result = repository.findByFirstNameAndAge(firstName, age); - assertThat(result).containsOnly(billy); - - firstName = QueryParam.of("Peter"); - age = QueryParam.of(41); - assertQueryHasSecIndexFilter("findByFirstNameAndAge", IndexedPerson.class, firstName, age); - result = repository.findByFirstNameAndAge(firstName, age); - assertThat(result).containsOnly(peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "address", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String() { - String zipCode = "C0123"; - assertThat(john.getAddress().getZipCode()).isEqualTo(zipCode); - assertQueryHasSecIndexFilter("findByAddressZipCode", IndexedPerson.class, zipCode); - List result = repository.findByAddressZipCode(zipCode); - assertThat(result).contains(john); - } - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String_2_levels() { - String zipCode = "C0123"; - assertThat(john.getAddress().getZipCode()).isEqualTo(zipCode); - jane.setFriend(john); - repository.save(jane); - - assertQueryHasSecIndexFilter("findByFriendAddressZipCode", IndexedPerson.class, zipCode); - List result = repository.findByFriendAddressZipCode(zipCode); - assertThat(result).contains(jane); - - // An alternative way to perform the same using a custom query - Qualifier nestedZipCodeEq = Qualifier.builder() - // find records having a map with a key that equals a value - // POJOs are saved as Maps - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps - .setPath("friend.address.zipCode") // path - .setValue(Value.get(zipCode)) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedZipCodeEq), IndexedPerson.class); - Iterable result2 = repository.findUsingQuery(new Query(nestedZipCodeEq)); - assertThat(result).isEqualTo(result2); - TestUtils.setFriendsToNull(repository, jane); - } - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_String_3_levels() { - String zipCode = "C0123"; - assertThat(john.getAddress().getZipCode()).isEqualTo(zipCode); - jane.setBestFriend(john); - repository.save(jane); - peter.setFriend(jane); - repository.save(peter); - - assertQueryHasSecIndexFilter("findByFriendBestFriendAddressZipCode", IndexedPerson.class, zipCode); - List result = repository.findByFriendBestFriendAddressZipCode(zipCode); - assertThat(result).contains(peter); - - // An alternative way to perform the same using a custom query - Qualifier nestedZipCodeEq = Qualifier.builder() - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps - .setPath("friend.bestFriend.address.zipCode") // path - .setValue(Value.get(zipCode)) // value of the nested key - .build(); - - assertQueryHasSecIndexFilter(new Query(nestedZipCodeEq), IndexedPerson.class); - Iterable result2 = repository.findUsingQuery(new Query(nestedZipCodeEq)); - assertThat(result).isEqualTo(result2); - TestUtils.setFriendsToNull(repository, jane, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "friend", entityClass = IndexedPerson.class) - void findByNestedSimpleProperty_Integer_3_levels() { - int apartment = 1; - assertThat(john.getAddress().getApartment()).isEqualTo(apartment); - jane.setBestFriend(john); - repository.save(jane); - peter.setFriend(jane); - repository.save(peter); - - assertQueryHasSecIndexFilter("findByFriendBestFriendAddressApartment", IndexedPerson.class, apartment); - List result = repository.findByFriendBestFriendAddressApartment(apartment); - assertThat(result).contains(peter); - - // An alternative way to perform the same using a custom query - Qualifier nestedApartmentEq = Qualifier.builder() - .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps - .setPath("friend.bestFriend.address.apartment") // path - .setValue(Value.get(apartment)) // value of the nested key - .build(); - - Iterable result2 = repository.findUsingQuery(new Query(nestedApartmentEq)); - assertThat(result).isEqualTo(result2); - TestUtils.setFriendsToNull(repository, jane, peter); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/GreaterThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/GreaterThanTests.java deleted file mode 100644 index 64d5ebeea..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/GreaterThanTests.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.Sort; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Is greater than" repository query. Keywords: GreaterThan, IsGreaterThan. - */ -public class GreaterThanTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "firstName", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_String_NoSecondaryIndexFilter() { - // "Greater than a String" has no secondary index Filter - assertThat(queryHasSecIndexFilter("findByFirstNameGreaterThan", IndexedPerson.class, "Bill")).isFalse(); - List result = repository.findByFirstNameGreaterThan("Bill"); - assertThat(result).containsAll(allIndexedPersons); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_Integer_Paginated() { - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 40); - Slice slice = repository.findByAgeGreaterThan(40, PageRequest.of(0, 10)); - assertThat(slice.hasContent()).isTrue(); - assertThat(slice.hasNext()).isFalse(); - assertThat(slice.getContent()).hasSize(3).contains(john, jane, peter); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_Integer_Paginated_respectsLimitAndOffsetAndSort() { - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 40); - List result = IntStream.range(0, 4) - .mapToObj(index -> repository.findByAgeGreaterThan(40, PageRequest.of(index, 1, Sort.by("age")))) - .flatMap(slice -> slice.getContent().stream()) - .collect(Collectors.toList()); - - assertThat(result) - .hasSize(3) - .containsSequence(peter, john, jane); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_Integer_Paginated_validHasPrevAndHasNext() { - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 40); - Slice first = repository.findByAgeGreaterThan(40, PageRequest.of(0, 1, Sort.by("age"))); - assertThat(first.hasContent()).isTrue(); - assertThat(first.getNumberOfElements()).isEqualTo(1); - assertThat(first.hasNext()).isTrue(); - assertThat(first.isFirst()).isTrue(); - assertThat(first.isLast()).isFalse(); - - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 40); - Slice last = repository.findByAgeGreaterThan(40, PageRequest.of(2, 1, Sort.by("age"))); - assertThat(last.hasContent()).isTrue(); - assertThat(last.getNumberOfElements()).isEqualTo(1); - assertThat(last.hasNext()).isFalse(); - assertThat(last.isLast()).isTrue(); - - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 100); - Slice slice = repository.findByAgeGreaterThan(100, PageRequest.of(0, 10)); - assertThat(slice.hasContent()).isFalse(); - assertThat(slice.hasNext()).isFalse(); - assertThat(slice.getContent()).isEmpty(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/NotContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/NotContainingTests.java deleted file mode 100644 index eac0a98c7..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/indexed/findBy/NotContainingTests.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.blocking.indexed.IndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.VALUE; - -/** - * Tests for the "Does not contain" repository query. Keywords: IsNotContaining, NotContaining, NotContains. - */ -public class NotContainingTests extends IndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - void findByMapKeysNotContaining_String_NoSecondaryIndexFilter() { - assertThat(billy.getStringMap()).containsKey("key1"); - // "Not containing" has no secondary index Filter - assertThat(queryHasSecIndexFilter("findByStringMapNotContaining", IndexedPerson.class, KEY, "key3")).isFalse(); - - List persons = repository.findByStringMapNotContaining(KEY, "key3"); - assertThat(persons).contains(billy); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - void findByMapValuesNotContaining_String() { - assertThat(billy.getStringMap()).containsValue("val1"); - // "Not containing" has no secondary index Filter - assertThat(queryHasSecIndexFilter("findByStringMapNotContaining", IndexedPerson.class, VALUE, "val3")).isFalse(); - - List persons = repository.findByStringMapNotContaining(VALUE, "val3"); - assertThat(persons).contains(billy); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java index c3ae53510..9aab25ab1 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java @@ -1,6 +1,5 @@ package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; -import com.aerospike.client.Value; import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.qualifier.Qualifier; @@ -43,7 +42,7 @@ void findBySimplePropertyEquals_Enum() { Qualifier genderEqFemale = Qualifier.builder() .setPath("gender") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(Person.Gender.FEMALE)) + .setValue(Person.Gender.FEMALE) .build(); assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia); } @@ -58,7 +57,7 @@ void findBySimplePropertyEquals_String() { // custom bin name has been set to "email" via @Field annotation .setPath("email") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(email)) + .setValue(email) .build(); assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia); } @@ -95,14 +94,14 @@ void findPersonsByQuery() { Qualifier firstNameEqCarter = Qualifier.builder() .setPath("firstName") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("Carter")) + .setValue("Carter") .build(); // creating an expression "age is equal to 49" Qualifier ageEq49 = Qualifier.builder() .setPath("age") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(49)) + .setValue(49) .build(); result = repository.findUsingQuery(new Query(ageEq49)); assertThat(result).containsOnly(carter); @@ -111,7 +110,7 @@ void findPersonsByQuery() { Qualifier firstNameEqLeroi = Qualifier.builder() .setPath("firstName") .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("Leroi")) + .setValue("Leroi") .build(); Query query = new Query(firstNameEqLeroi); query.setSort(Sort.by("age")); @@ -123,7 +122,7 @@ void findPersonsByQuery() { Qualifier ageGt49 = Qualifier.builder() .setFilterOperation(FilterOperation.GT) .setPath("age") - .setValue(Value.get(49)) + .setValue(49) .build(); result = repository.findUsingQuery(new Query(ageGt49)); assertThat(result).doesNotContain(carter); @@ -288,7 +287,7 @@ void mapValuesTest() { Qualifier stringMapValuesContainString = Qualifier.builder() .setPath("stringMap") .setFilterOperation(FilterOperation.MAP_VALUES_CONTAIN) - .setValue(Value.get(valueToSearch)) + .setValue(valueToSearch) .build(); assertThat(repository.findUsingQuery(new Query(stringMapValuesContainString))).containsOnly(donny, boyd); @@ -300,7 +299,7 @@ void mapValuesTest() { Qualifier intMapWithExactKeyAndValueLt100 = Qualifier.builder() .setPath("intMap." + keyExactMatch) // Map bin name .setFilterOperation(FilterOperation.MAP_VAL_LT_BY_KEY) - .setValue(Value.get(valueToSearchLessThan)) // Map value to compare with + .setValue(valueToSearchLessThan) // Map value to compare with .build(); assertThat(repository.findUsingQuery(new Query(intMapWithExactKeyAndValueLt100))).containsOnly(carter); } diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java index 835e119d9..f0854617d 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java @@ -227,7 +227,7 @@ void findByNestedSimplePropertyEquals() { // POJOs are saved as Maps .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps .setPath("friend.address.zipCode") // path includes bin name, context and the required map key - .setValue(Value.get(zipCode)) // value of the nested key + .setValue(zipCode) // value of the nested key .build(); Iterable result2 = repository.findUsingQuery(new Query(nestedZipCodeEq)); @@ -288,7 +288,7 @@ void findByDeeplyNestedSimplePropertyEquals_PojoField_String_10_levels() { .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps // path includes bin name, context and the required map key .setPath("friend.friend.friend.friend.friend.friend.friend.friend.bestFriend.address.zipCode") - .setValue(Value.get(zipCode)) // value of the nested key + .setValue(zipCode) // value of the nested key .build(); Iterable result2 = repository.findUsingQuery(new Query(nestedZipCodeEq)); @@ -320,7 +320,7 @@ void findByDeeplyNestedSimplePropertyEquals_PojoField_Integer_10_levels() { // POJOs are saved as Maps .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps .setPath("friend.friend.friend.friend.friend.friend.friend.friend.bestFriend.address.apartment") // path - .setValue(Value.get(apartment)) // value of the nested key + .setValue(apartment) // value of the nested key .build(); Iterable result2 = repository.findUsingQuery(new Query(nestedApartmentEq)); @@ -352,7 +352,7 @@ void findByDeeplyNestedSimplePropertyEquals_Pojo_9_levels() { // POJOs are saved as Maps .setFilterOperation(FilterOperation.MAP_VAL_EQ_BY_KEY) // POJOs are saved as Maps .setPath("friend.friend.friend.friend.friend.friend.friend.friend.bestFriend.address") // path - .setValue(Value.get(pojoToMap(address))) // value of the nested key + .setValue(pojoToMap(address)) // value of the nested key .build(); Iterable result2 = repository.findUsingQuery(new Query(nestedAddressEq)); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/ReactiveIndexedPersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/ReactiveIndexedPersonRepositoryQueryTests.java deleted file mode 100644 index 65fa0233a..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/ReactiveIndexedPersonRepositoryQueryTests.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed; - -import com.aerospike.client.query.IndexCollectionType; -import com.aerospike.client.query.IndexType; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.TestInstance; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.ReactiveBlockingAerospikeTestOperations; -import org.springframework.data.aerospike.sample.Address; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.sample.ReactiveIndexedPersonRepository; -import org.springframework.data.aerospike.util.AsCollections; - -import java.util.Arrays; -import java.util.List; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class ReactiveIndexedPersonRepositoryQueryTests extends BaseReactiveIntegrationTests { - - @BeforeEach - public void beforeEach(TestInfo testInfo) { - assertBinsAreIndexed(testInfo); - } - - protected static final IndexedPerson alain = IndexedPerson.builder() - .id(nextId()) - .firstName("Alain") - .lastName("Sebastian") - .age(42) - .strings(Arrays.asList("str1", "str2")) - .address(new Address("Foo Street 1", 1, "C0123", "Bar")) - .build(); - protected static final IndexedPerson luc = IndexedPerson.builder() - .id(nextId()) - .firstName("Luc") - .lastName("Besson") - .age(39) - .stringMap(AsCollections.of("key1", "val1", "key2", "val2")) - .address(new Address(null, null, null, null)) - .build(); - protected static final IndexedPerson lilly = IndexedPerson.builder() - .id(nextId()) - .firstName("Lilly") - .lastName("Bertineau") - .age(28) - .intMap(AsCollections.of("key1", 1, "key2", 2)) - .address(new Address("Foo Street 2", 2, "C0124", "C0123")) - .build(); - protected static final IndexedPerson daniel = IndexedPerson.builder() - .id(nextId()) - .firstName("Daniel") - .lastName("Morales") - .age(29) - .ints(Arrays.asList(500, 550, 990)) - .build(); - protected static final IndexedPerson petra = IndexedPerson.builder() - .id(nextId()) - .firstName("Petra") - .lastName("Coutant-Kerbalec") - .age(34) - .stringMap(AsCollections.of("key1", "val1", "key2", "val2", "key3", "val3")) - .build(); - protected static final IndexedPerson emilien = IndexedPerson.builder() - .id(nextId()) - .firstName("Emilien") - .lastName("Coutant-Kerbalec") - .age(30) - .intMap(AsCollections.of("key1", 0, "key2", 1)) - .ints(Arrays.asList(450, 550, 990)) - .build(); - protected static final List allIndexedPersons = Arrays.asList(alain, luc, lilly, daniel, petra, - emilien); - @Autowired - protected ReactiveIndexedPersonRepository reactiveRepository; - @Autowired - protected ReactiveBlockingAerospikeTestOperations reactiveBlockingAerospikeTestOperations; - - @BeforeAll - public void beforeAll() { - reactiveBlockingAerospikeTestOperations.deleteAll(reactiveRepository, allIndexedPersons); - reactiveBlockingAerospikeTestOperations.saveAll(reactiveRepository, allIndexedPersons); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_first_name_index", "firstName", - IndexType.STRING).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_last_name_index", "lastName", - IndexType.STRING).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_age_index", "age", IndexType.NUMERIC).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_strings_index", "strings", - IndexType.STRING, IndexCollectionType.LIST).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_ints_index", "ints", IndexType.NUMERIC, - IndexCollectionType.LIST).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_string_map_keys_index", "stringMap", - IndexType.STRING, IndexCollectionType.MAPKEYS).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_string_map_values_index", "stringMap", - IndexType.STRING, IndexCollectionType.MAPVALUES).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_int_map_keys_index", "intMap", - IndexType.STRING, IndexCollectionType.MAPKEYS).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_int_map_values_index", "intMap", - IndexType.NUMERIC, IndexCollectionType.MAPVALUES).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_address_keys_index", "address", - IndexType.STRING, IndexCollectionType.MAPKEYS).block(); - reactiveTemplate.createIndex(IndexedPerson.class, "indexed_person_address_values_index", "address", - IndexType.STRING, IndexCollectionType.MAPVALUES).block(); - } - - @AfterAll - public void afterAll() { - reactiveBlockingAerospikeTestOperations.deleteAll(reactiveRepository, allIndexedPersons); - - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_first_name_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_last_name_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_strings_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_ints_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, - "indexed_person_string_map_keys_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, - "indexed_person_string_map_values_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_int_map_keys_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_int_map_values_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_address_keys_index"); - additionalAerospikeTestOperations.dropIndex(IndexedPerson.class, "indexed_person_address_values_index"); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/BetweenTests.java deleted file mode 100644 index 6db789518..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/BetweenTests.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import reactor.core.scheduler.Schedulers; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Is between" repository query. Keywords: Between, IsBetween. - */ -public class BetweenTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyBetween_Integer() { - assertQueryHasSecIndexFilter("findByAgeBetween", IndexedPerson.class, 39, 45); - List results = reactiveRepository.findByAgeBetween(39, 45) - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).hasSize(2).contains(alain, luc); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/ContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/ContainingTests.java deleted file mode 100644 index 37de61c88..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/ContainingTests.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import reactor.core.scheduler.Schedulers; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.KEY_VALUE_PAIR; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeQueryCriterion.VALUE; - -/** - * Tests for the "Contains" repository query. Keywords: Containing, IsContaining, Contains. - */ -public class ContainingTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "strings", entityClass = IndexedPerson.class) - public void findByCollectionContaining_String() { - assertQueryHasSecIndexFilter("findByStringsContaining", IndexedPerson.class, "str1"); - List results = reactiveRepository.findByStringsContaining("str1") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).containsExactlyInAnyOrder(alain); - } - - @Test - @AssertBinsAreIndexed(binNames = "ints", entityClass = IndexedPerson.class) - public void findByCollectionContaining_Integer() { - assertQueryHasSecIndexFilter("findByIntsContaining", IndexedPerson.class, 550); - List results = reactiveRepository.findByIntsContaining(550) - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).containsExactlyInAnyOrder(daniel, emilien); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - public void findByMapKeysContaining_String() { - assertQueryHasSecIndexFilter("findByStringMapContaining", IndexedPerson.class, KEY, "key1"); - List results = reactiveRepository.findByStringMapContaining(KEY, "key1") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).contains(luc, petra); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - public void findByMapValuesContaining_String() { - assertQueryHasSecIndexFilter("findByStringMapContaining", IndexedPerson.class, VALUE, "val1"); - List results = reactiveRepository.findByStringMapContaining(VALUE, "val1") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).contains(luc, petra); - } - - @Test - @AssertBinsAreIndexed(binNames = "stringMap", entityClass = IndexedPerson.class) - public void findByExactMapKeyAndValue_String() { - assertThat(petra.getStringMap().containsKey("key1")).isTrue(); - assertThat(petra.getStringMap().containsValue("val1")).isTrue(); - assertThat(luc.getStringMap().containsKey("key1")).isTrue(); - assertThat(luc.getStringMap().containsValue("val1")).isTrue(); - assertQueryHasSecIndexFilter("findByStringMapContaining", IndexedPerson.class, KEY_VALUE_PAIR, "key1", "val1"); - - List results = reactiveRepository.findByStringMapContaining(KEY_VALUE_PAIR, "key1", "val1") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).contains(petra, luc); - } - - @Test - @AssertBinsAreIndexed(binNames = "intMap", entityClass = IndexedPerson.class) - public void findByExactMapKeyAndValue_Integer() { - assertThat(emilien.getIntMap().containsKey("key1")).isTrue(); - assertThat(emilien.getIntMap().get("key1")).isZero(); - assertThat(lilly.getIntMap().containsKey("key1")).isTrue(); - assertThat(lilly.getIntMap().get("key1")).isNotZero(); - assertQueryHasSecIndexFilter("findByIntMapContaining", IndexedPerson.class, KEY_VALUE_PAIR, "key1", 0); - - List results = reactiveRepository.findByIntMapContaining(KEY_VALUE_PAIR, "key1", 0) - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).containsExactly(emilien); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CrudRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CrudRepositoryQueryTests.java deleted file mode 100644 index b3ab82962..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CrudRepositoryQueryTests.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; - -/** - * Tests for the CrudRepository queries API. - */ -public class CrudRepositoryQueryTests extends ReactiveIndexedPersonRepositoryQueryTests { - -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CustomQueriesTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CustomQueriesTests.java deleted file mode 100644 index cab91960a..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/CustomQueriesTests.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import com.aerospike.client.Value; -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.config.NoSecondaryIndexRequired; -import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.qualifier.Qualifier; -import org.springframework.data.aerospike.repository.query.Query; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMetadata.SINCE_UPDATE_TIME; - -public class CustomQueriesTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @NoSecondaryIndexRequired - public void findPersonsByMetadata() { - // creating an expression "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt50Seconds = Qualifier.metadataBuilder() - .setMetadataField(SINCE_UPDATE_TIME) - .setFilterOperation(FilterOperation.LT) - .setValue(50000L) - .build(); - assertThat(reactiveRepository.findUsingQuery(new Query(sinceUpdateTimeLt50Seconds)).collectList().block()) - .containsAll(allIndexedPersons); - - // creating an expression "since_update_time metadata value is between 1 millisecond and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() - .setMetadataField(SINCE_UPDATE_TIME) - .setFilterOperation(FilterOperation.BETWEEN) - .setValue(1L) - .setSecondValue(50000L) - .build(); - assertThat(reactiveRepository.findUsingQuery(new Query(sinceUpdateTimeBetween1And50000)).collectList().block()) - .containsAll(reactiveRepository.findUsingQuery(new Query(sinceUpdateTimeLt50Seconds)).collectList() - .block()); - } - - @Test - @AssertBinsAreIndexed(binNames = {"firstName", "age",}, entityClass = IndexedPerson.class) - public void findPersonsByQuery() { - Iterable result; - - // creating an expression "since_update_time metadata value is greater than 1 millisecond" - Qualifier sinceUpdateTimeGt1 = Qualifier.metadataBuilder() - .setMetadataField(SINCE_UPDATE_TIME) - .setFilterOperation(FilterOperation.GT) - .setValue(1L) - .build(); - - // creating an expression "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt50Seconds = Qualifier.metadataBuilder() - .setMetadataField(SINCE_UPDATE_TIME) - .setFilterOperation(FilterOperation.LT) - .setValue(50000L) - .build(); - assertThat(reactiveRepository.findUsingQuery(new Query(sinceUpdateTimeLt50Seconds)).collectList().block()) - .containsAll(allIndexedPersons); - - // creating an expression "since_update_time metadata value is between 1 and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() - .setMetadataField(SINCE_UPDATE_TIME) - .setFilterOperation(FilterOperation.BETWEEN) - .setValue(1L) - .setSecondValue(50000L) - .build(); - - // creating an expression "firsName is equal to Petra" - Qualifier firstNameEqPetra = Qualifier.builder() - .setPath("firstName") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get("Petra")) - .build(); - - // creating an expression "age is equal to 34" - Qualifier ageEq34 = Qualifier.builder() - .setPath("age") - .setFilterOperation(FilterOperation.EQ) - .setValue(Value.get(34)) - .build(); - result = reactiveRepository.findUsingQuery(new Query(ageEq34)).collectList().block(); - assertThat(result).containsOnly(petra); - - // creating an expression "age is greater than 34" - Qualifier ageGt34 = Qualifier.builder() - .setFilterOperation(FilterOperation.GT) - .setPath("age") - .setValue(Value.get(34)) - .build(); - result = reactiveRepository.findUsingQuery(new Query(ageGt34)).collectList().block(); - assertThat(result).doesNotContain(petra); - - result = reactiveRepository.findUsingQuery(new Query(Qualifier.and(sinceUpdateTimeGt1, - sinceUpdateTimeLt50Seconds, - ageEq34, - firstNameEqPetra, sinceUpdateTimeBetween1And50000))).collectList().block(); - assertThat(result).containsOnly(petra); - - // conditions "age == 34", "firstName is Petra" and "since_update_time metadata value is less than 50 seconds" - // are combined with OR - Qualifier orWide = Qualifier.or(ageEq34, firstNameEqPetra, sinceUpdateTimeLt50Seconds); - result = reactiveRepository.findUsingQuery(new Query(orWide)).collectList().block(); - assertThat(result).containsAll(allIndexedPersons); - - // conditions "age == 34" and "firstName is Petra" are combined with OR - Qualifier orNarrow = Qualifier.or(ageEq34, firstNameEqPetra); - result = reactiveRepository.findUsingQuery(new Query(orNarrow)).collectList().block(); - assertThat(result).containsOnly(petra); - - result = reactiveRepository.findUsingQuery(new Query(Qualifier.and(ageEq34, ageGt34))).collectList().block(); - assertThat(result).isEmpty(); - - // conditions "age == 34" and "age > 34" are not overlapping - result = reactiveRepository.findUsingQuery(new Query(Qualifier.and(ageEq34, ageGt34))).collectList().block(); - assertThat(result).isEmpty(); - - // conditions "age == 34" and "age > 34" are combined with OR - Qualifier ageEqOrGt34 = Qualifier.or(ageEq34, ageGt34); - - result = reactiveRepository.findUsingQuery(new Query(ageEqOrGt34)).collectList().block(); - List personsWithAgeEqOrGt34 = allIndexedPersons.stream().filter(person -> person.getAge() >= 34) - .toList(); - assertThat(result).containsAll(personsWithAgeEqOrGt34); - - // a condition that returns all entities and a condition that returns one entity are combined using AND - result = reactiveRepository.findUsingQuery(new Query(Qualifier.and(orWide, orNarrow))).collectList().block(); - assertThat(result).containsOnly(petra); - - // a condition that returns all entities and a condition that returns one entity are combined using AND - // another way of running the same query - Qualifier orCombinedWithAnd = Qualifier.and(orWide, orNarrow); - result = reactiveRepository.findUsingQuery(new Query(orCombinedWithAnd)).collectList().block(); - assertThat(result).containsOnly(petra); - } -} - diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/EqualsTests.java deleted file mode 100644 index cd054b81b..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/EqualsTests.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import reactor.core.scheduler.Schedulers; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Equals" repository query. Keywords: Is, Equals (or no keyword). - */ -public class EqualsTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = {"lastName", "firstName"}, entityClass = IndexedPerson.class) - public void findBySimpleProperty_String() { - assertQueryHasSecIndexFilter("findByLastName", IndexedPerson.class, "Coutant-Kerbalec"); - List results = reactiveRepository.findByLastName("Coutant-Kerbalec") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).containsOnly(petra, emilien); - - assertQueryHasSecIndexFilter("findByFirstName", IndexedPerson.class, "Lilly"); - List results2 = reactiveRepository.findByFirstName("Lilly") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results2).containsExactlyInAnyOrder(lilly); - } - - @Test - @AssertBinsAreIndexed(binNames = {"firstName", "age"}, entityClass = IndexedPerson.class) - public void findBySimpleProperty_String_AND_SimpleProperty_Integer() { - QueryParam firstName = QueryParam.of("Lilly"); - QueryParam age = QueryParam.of(28); - - assertQueryHasSecIndexFilter("findByFirstNameAndAge", IndexedPerson.class, firstName, age); - List results = reactiveRepository.findByFirstNameAndAge(firstName, age) - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).containsOnly(lilly); - } - - @Test - @AssertBinsAreIndexed(binNames = "address", entityClass = IndexedPerson.class) - public void findByNestedSimpleProperty_String() { - String zipCode = "C0123"; - assertThat(alain.getAddress().getZipCode()).isEqualTo(zipCode); - assertQueryHasSecIndexFilter("findByAddressZipCode", IndexedPerson.class, zipCode); - List results = reactiveRepository.findByAddressZipCode(zipCode) - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results).contains(alain); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/GreaterThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/GreaterThanTests.java deleted file mode 100644 index 6841bfcee..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/GreaterThanTests.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.Sort; -import reactor.core.scheduler.Schedulers; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * Tests for the "Is greater than" repository query. Keywords: GreaterThan, IsGreaterThan. - */ -public class GreaterThanTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_Integer_Paginated() { - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 1, PageRequest.of(0, 1)); - Page page = reactiveRepository.findByAgeGreaterThan(1, PageRequest.of(0, 1)) - .subscribeOn(Schedulers.parallel()).block(); - assertThat(page).containsAnyElementsOf(allIndexedPersons); - - Slice slice = reactiveRepository.findByAgeGreaterThan(1, PageRequest.of(0, 2)) - .subscribeOn(Schedulers.parallel()).block(); - assertThat(slice).hasSize(2).containsAnyElementsOf(allIndexedPersons); - - Slice sliceSorted = reactiveRepository.findByAgeGreaterThan(1, PageRequest.of(1, 2, Sort.by( - "age"))) - .subscribeOn(Schedulers.parallel()).block(); - assertThat(sliceSorted).hasSize(2).containsAnyElementsOf(allIndexedPersons); - - assertThatThrownBy(() -> reactiveRepository.findByAgeGreaterThan(1, PageRequest.of(1, 2))) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Unsorted query must not have offset value. For retrieving paged results use sorted query."); - } - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyGreaterThan_Integer_Unpaged() { - assertQueryHasSecIndexFilter("findByAgeGreaterThan", IndexedPerson.class, 40, Pageable.unpaged()); - Slice slice = reactiveRepository.findByAgeGreaterThan(40, Pageable.unpaged()) - .subscribeOn(Schedulers.parallel()).block(); - assertThat(slice.hasContent()).isTrue(); - assertThat(slice.getNumberOfElements()).isGreaterThan(0); - assertThat(slice.hasNext()).isFalse(); - assertThat(slice.isLast()).isTrue(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/LessThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/LessThanTests.java deleted file mode 100644 index 2323601cc..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/LessThanTests.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import reactor.core.scheduler.Schedulers; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for the "Is less than" repository query. Keywords: LessThan, IsLessThan. - */ -public class LessThanTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "age", entityClass = IndexedPerson.class) - public void findBySimplePropertyLessThan_Integer_Unpaged() { - assertQueryHasSecIndexFilter("findByAgeLessThan", IndexedPerson.class, 40, Pageable.unpaged()); - Page page = reactiveRepository.findByAgeLessThan(40, Pageable.unpaged()) - .subscribeOn(Schedulers.parallel()).block(); - assertThat(page.hasContent()).isTrue(); - assertThat(page.getNumberOfElements()).isGreaterThan(1); - assertThat(page.hasNext()).isFalse(); - assertThat(page.getTotalPages()).isEqualTo(1); - assertThat(page.getTotalElements()).isEqualTo(page.getSize()); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/StartsWithTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/StartsWithTests.java deleted file mode 100644 index 1ee5865bc..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/indexed/findBy/StartsWithTests.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.springframework.data.aerospike.repository.query.reactive.indexed.findBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.config.AssertBinsAreIndexed; -import org.springframework.data.aerospike.config.NoSecondaryIndexRequired; -import org.springframework.data.aerospike.repository.query.reactive.indexed.ReactiveIndexedPersonRepositoryQueryTests; -import org.springframework.data.aerospike.sample.IndexedPerson; -import org.springframework.data.aerospike.util.TestUtils; -import reactor.core.scheduler.Schedulers; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * Tests for the "Starts with" repository query. Keywords: StartingWith, IsStartingWith, StartsWith. - */ -public class StartsWithTests extends ReactiveIndexedPersonRepositoryQueryTests { - - @Test - @AssertBinsAreIndexed(binNames = "lastName", entityClass = IndexedPerson.class) - void findBySimplePropertyStartingWith_String_Distinct_NoSecondaryIndexFilter() { - // There is no secondary index filter for "starts with" - assertThat(queryHasSecIndexFilter("findDistinctByLastNameStartingWith", IndexedPerson.class, "Coutant-Kerbalec")).isFalse(); - List persons = reactiveRepository.findDistinctByLastNameStartingWith("Coutant-Kerbalec") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(persons).hasSize(1); - - // There is no secondary index filter for "starts with" - assertThat(queryHasSecIndexFilter("findByLastNameStartingWith", IndexedPerson.class, "Coutant-Kerbalec")).isFalse(); - List persons2 = reactiveRepository.findByLastNameStartingWith("Coutant-Kerbalec") - .subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(persons2).hasSize(2); - } - - @Test - @NoSecondaryIndexRequired - void findByNestedSimplePropertyStartingWith_String_Distinct_NegativeTest() { - alain.setFriend(luc); - reactiveRepository.save(alain); - lilly.setFriend(petra); - reactiveRepository.save(lilly); - daniel.setFriend(emilien); - reactiveRepository.save(daniel); - - assertThatThrownBy(() -> reactiveRepository.findDistinctByFriendLastNameStartingWith("l")) - .isInstanceOf(UnsupportedOperationException.class) - .hasMessage("DISTINCT queries are currently supported only for the first level objects, got a query for " + - "friend.lastName"); - - TestUtils.setFriendsToNull(reactiveRepository, alain, lilly, daniel); - } -} diff --git a/src/test/resources/bootstrap.properties b/src/test/resources/bootstrap.properties index 2b64c1290..0a9afb9df 100644 --- a/src/test/resources/bootstrap.properties +++ b/src/test/resources/bootstrap.properties @@ -1 +1,2 @@ -embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 \ No newline at end of file +embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 +embedded.aerospike.enabled=true