Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-439 Find by "enum in" fails with AerospikeException Parameter error #741

Merged
merged 19 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Exp filterExp(Map<QualifierKey, Object> qualifierMap) {
.getFilterExp()
).toArray(Exp[]::new);

return Exp.or(arrElementsExp);
return arrElementsExp.length > 1 ? Exp.or(arrElementsExp) : arrElementsExp[0];
});
}

Expand All @@ -150,7 +150,7 @@ public Exp filterExp(Map<QualifierKey, Object> qualifierMap) {
.getFilterExp()
).toArray(Exp[]::new);

return Exp.and(arrElementsExp);
return arrElementsExp.length > 1 ? Exp.and(arrElementsExp) : arrElementsExp[0];
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,21 @@ protected boolean queryHasSecIndexFilter(String namespace, String setName, Query

throw new IllegalArgumentException("The result of conversion is not a Map, expecting only a POJO argument");
}

/**
* Delete all entities of a class or a set.
*
* @param objectsToDelete Each of the objects must be either a Class or a String.
*/
protected void deleteAll(Object... objectsToDelete) {
for (Object toDelete : objectsToDelete) {
if (toDelete instanceof Class<?>) {
template.deleteAll((Class<?>) toDelete);
} else if (toDelete instanceof String) {
template.deleteAll((String) toDelete);
} else {
throw new IllegalArgumentException("Expecting either a Class<?> or a String");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public class AerospikeTemplateFindByQueryTests extends BaseBlockingIntegrationTe

@BeforeAll
public void beforeAllSetUp() {
deleteOneByOne(allPersons);
template.deleteAll(Person.class);
template.deleteAll(OVERRIDE_SET_NAME);

// batch write operations are supported starting with Server version 6.0+
if (serverVersionSupport.isBatchWriteSupported()) {
Expand Down Expand Up @@ -118,8 +119,14 @@ public void setUp() {

@AfterAll
public void afterAll() {
deleteOneByOne(allPersons);
deleteOneByOne(allPersons, OVERRIDE_SET_NAME);
// batch write operations are supported starting with Server version 6.0+
if (serverVersionSupport.isBatchWriteSupported()) {
template.deleteAll(allPersons);
template.deleteAll(allPersons, OVERRIDE_SET_NAME);
} else {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.policy.Policy;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.aerospike.BaseBlockingIntegrationTests;
Expand All @@ -42,14 +44,19 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.data.aerospike.sample.SampleClasses.VersionedClass;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AerospikeTemplateInsertTests extends BaseBlockingIntegrationTests {

@BeforeEach
public void beforeEach() {
template.deleteAll(Person.class);
template.deleteAll(CustomCollectionClass.class);
template.deleteAll(DocumentWithByteArray.class);
template.deleteAll(VersionedClass.class);
deleteAll(Person.class, CustomCollectionClass.class, DocumentWithByteArray.class, VersionedClass.class,
OVERRIDE_SET_NAME);
}

@AfterAll
public void afterAll() {
deleteAll(Person.class, CustomCollectionClass.class, DocumentWithByteArray.class, VersionedClass.class,
OVERRIDE_SET_NAME);
}

@Test
Expand Down Expand Up @@ -77,7 +84,7 @@ public void insertsDocumentWithListMapDateStringLongValues() {
.strings(Arrays.asList("a", "b", "c"))
.friend(new Person(null, "Anna", 43))
.isActive(true)
.sex(Person.Sex.MALE)
.gender(Person.Gender.MALE)
.dateOfBirth(new Date())
.build();
template.insert(customer);
Expand All @@ -99,7 +106,7 @@ public void insertsDocumentWithListMapDateStringLongValuesAndSetName() {
.strings(Arrays.asList("a", "b", "c"))
.friend(new Person(null, "Anna", 43))
.isActive(true)
.sex(Person.Sex.MALE)
.gender(Person.Gender.MALE)
.dateOfBirth(new Date())
.build();
template.insert(customer, OVERRIDE_SET_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void insertsDocumentWithListMapDateStringLongValues() {
.strings(Arrays.asList("a", "b", "c"))
.friend(new Person(null, "Anna", 43))
.isActive(true)
.sex(Person.Sex.MALE)
.gender(Person.Gender.MALE)
.dateOfBirth(new Date())
.build();

Expand All @@ -100,7 +100,7 @@ public void insertsDocumentWithListMapDateStringLongValuesAndSetName() {
.strings(Arrays.asList("a", "b", "c"))
.friend(new Person(null, "Anna", 43))
.isActive(true)
.sex(Person.Sex.MALE)
.gender(Person.Gender.MALE)
.dateOfBirth(new Date())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.util.List;

import static org.springframework.data.aerospike.sample.Person.Sex.FEMALE;
import static org.springframework.data.aerospike.sample.Person.Gender.FEMALE;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests {
Expand Down Expand Up @@ -45,7 +45,7 @@ public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests {
.id(nextId())
.firstName("Alicia")
.lastName("Keys")
.sex(FEMALE)
.gender(FEMALE)
.age(30)
.ints(List.of(550, 600, 990))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ private MappingAerospikeConverter getMappingAerospikeConverter(AerospikeCustomCo

@Test
void findBySimplePropertyEquals_Enum() {
Qualifier sexEqFemale = Qualifier.builder()
.setBinName("sex")
Qualifier genderEqFemale = Qualifier.builder()
.setBinName("gender")
.setFilterOperation(FilterOperation.EQ)
.setValue(Value.get(Person.Sex.FEMALE))
.setValue(Value.get(Person.Gender.FEMALE))
.build();
assertThat(repository.findUsingQuery(new Query(sexEqFemale))).containsOnly(alicia);
assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void findBySimplePropertyEquals_String_NegativeTest() {

@Test
void findBySimplePropertyEquals_Enum() {
List<Person> result = repository.findBySex(Person.Sex.FEMALE);
List<Person> result = repository.findByGender(Person.Gender.FEMALE);
assertThat(result).containsOnly(alicia);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ void findByNestedSimplePropertyIn_String() {
.containsExactlyInAnyOrder(dave, carter);
}

@Test
void findByEnumIn() {
List<Person> result;
result = repository.findByGenderIn(List.of(Person.Gender.FEMALE, Person.Gender.MALE));
assertThat(result).contains(alicia);

result = repository.findByGenderIn(List.of(Person.Gender.FEMALE));
assertThat(result).contains(alicia);

result = repository.findByGenderIn(List.of(Person.Gender.MALE));
assertThat(result).isEmpty();
}

@Test
void findByCollectionIn() {
if (serverVersionSupport.isFindByCDTSupported()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static IndexedPerson from(Person person) {
.lastName(person.getLastName())
.age(person.getAge())
.waist(person.getWaist())
.sex(person.getSex())
.gender(person.getGender())
.intMap(person.getIntMap())
.stringMap(person.getStringMap())
.friend(person.getFriend())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Person {
private BigInteger ageBigInteger;
private BigDecimal ageBigDecimal;
private int waist;
private Sex sex;
private Gender gender;
private Map<String, String> stringMap;
private Map<String, Integer> intMap;
private Map<Long, Integer> longIntMap;
Expand Down Expand Up @@ -100,7 +100,7 @@ public PersonSomeFields toPersonSomeFields() {
.build();
}

public enum Sex {
public enum Gender {
MALE, FEMALE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,9 @@ List<P> findByFriendStringMapNotContaining(AerospikeQueryCriterion criterion,

List<P> findByFirstName(String name);

List<P> findBySex(Person.Sex sex);
List<P> findByGender(Person.Gender gender);

List<P> findByGenderIn(List<Person.Gender> list);

List<P> findByFirstNameIs(String name);

Expand Down
Loading