From 9694962d4a5210436b79fff5699b821de784e94d Mon Sep 17 00:00:00 2001 From: Roi Menashe <33356310+roimenashe@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:24:11 +0200 Subject: [PATCH] FMWK-287 Map Key/Value Not Containing Fix (#677) * Map key/value not containing operation using a secondary index should not be supported, it's a bug. * Increase count check wait duration to 20 seconds * Add truncate and verification that set was truncated before each test * Remove redundant cleanup (required only once before running each test) --- .../data/aerospike/query/FilterOperation.java | 4 ++-- ...tiveAerospikeTemplateCountRelatedTests.java | 18 ++++-------------- .../IndexedPersonRepositoryQueryTests.java | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 16 deletions(-) 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 958c43b4c..0ef8fc2a9 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -863,7 +863,7 @@ public Exp filterExp(Map qualifierMap) { @Override public Filter sIndexFilter(Map qualifierMap) { - return collectionContains(IndexCollectionType.MAPKEYS, qualifierMap); + return null; // currently not supported } }, MAP_VALUES_CONTAIN { @@ -885,7 +885,7 @@ public Exp filterExp(Map qualifierMap) { @Override public Filter sIndexFilter(Map qualifierMap) { - return collectionContains(IndexCollectionType.MAPVALUES, qualifierMap); + return null; // currently not supported } }, MAP_KEYS_BETWEEN { 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 03744dba7..c4fb6fd24 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 @@ -29,6 +29,10 @@ class ReactiveAerospikeTemplateCountRelatedTests extends BaseReactiveIntegration @BeforeEach public void setUp() { super.setUp(); + reactiveTemplate.deleteAll(Person.class).block(); + Awaitility.await() + .atMost(Duration.ofSeconds(15)) + .until(() -> isCountExactlyNum(0L)); } @Test @@ -77,11 +81,6 @@ void count_shouldFindAllItemsByGivenCriteria() { assertThat(reactiveTemplate.count(null, Person.class).subscribeOn(Schedulers.parallel()) .block()).isEqualTo(4); - - reactiveTemplate.delete(reactiveTemplate.findById(id1, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id2, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id3, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id4, Person.class).block()).block(); // cleanup } @Test @@ -112,10 +111,6 @@ void count_shouldFindAllItemsByGivenCriteriaAndRespectsIgnoreCase() { assertThat(reactiveTemplate.count(query2, Person.class) .subscribeOn(Schedulers.parallel()) .block()).isEqualTo(1); - - reactiveTemplate.delete(reactiveTemplate.findById(id1, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id2, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id3, Person.class).block()).block(); // cleanup } @Test @@ -152,11 +147,6 @@ void count_shouldCountAllByPassingEntityClass() { Awaitility.await() .atMost(Duration.ofSeconds(15)) .until(() -> isCountExactlyNum(4L)); - - reactiveTemplate.delete(reactiveTemplate.findById(id1, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id2, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id3, Person.class).block()).block(); // cleanup - reactiveTemplate.delete(reactiveTemplate.findById(id4, Person.class).block()).block(); // cleanup } @SuppressWarnings("SameParameterValue") diff --git a/src/test/java/org/springframework/data/aerospike/repository/IndexedPersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/IndexedPersonRepositoryQueryTests.java index f1aaacb1e..ab15bbed8 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/IndexedPersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/IndexedPersonRepositoryQueryTests.java @@ -356,6 +356,15 @@ void findByMapKeysContaining() { assertThat(persons).contains(billy); } + @Test + void findByMapKeysNotContaining() { + assertThat(billy.getStringMap()).containsKey("key1"); + + List persons = repository.findByStringMapNotContaining("key3", + CriteriaDefinition.AerospikeMapCriteria.KEY); + assertThat(persons).contains(billy); + } + @Test void findByMapValuesContaining() { assertThat(billy.getStringMap()).containsValue("val1"); @@ -365,6 +374,15 @@ void findByMapValuesContaining() { assertThat(persons).contains(billy); } + @Test + void findByMapValuesNotContaining() { + assertThat(billy.getStringMap()).containsValue("val1"); + + List persons = repository.findByStringMapNotContaining("val3", + VALUE); + assertThat(persons).contains(billy); + } + @Test void findByMapKeyValueContainingInt() { assertThat(tricia.getIntMap()).containsKey("key1");