Skip to content

Commit

Permalink
FMWK-525 Make template.findAll() work correctly with id-only records (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr authored Sep 1, 2024
1 parent 5abebb5 commit d7fef31
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,12 @@ private String[] getBinNamesFromTargetClass(Class<?> targetClass) {
List<String> binNamesList = new ArrayList<>();

targetEntity.doWithProperties(
(PropertyHandler<AerospikePersistentProperty>) property -> binNamesList.add(property.getFieldName()));
(PropertyHandler<AerospikePersistentProperty>) property -> {
if (!property.isIdProperty()) {
binNamesList.add(property.getFieldName());
}
}
);

return binNamesList.toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ public static String[] getBinNamesFromTargetClass(Class<?> targetClass,

List<String> binNamesList = new ArrayList<>();

targetEntity.doWithProperties((PropertyHandler<AerospikePersistentProperty>) property
-> binNamesList.add(property.getFieldName()));
targetEntity.doWithProperties(
(PropertyHandler<AerospikePersistentProperty>) property -> {
if (!property.isIdProperty()) {
binNamesList.add(property.getFieldName());
}
});

return binNamesList.toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.aerospike.sample.SampleClasses;
import reactor.core.scheduler.Schedulers;

import java.util.List;
Expand Down Expand Up @@ -52,4 +53,24 @@ public void findAll_findNothing() {

assertThat(actual).isEmpty();
}

@Test
public void findAll_findIdOnlyRecord() {
var id = 100;
var doc = new SampleClasses.DocumentWithPrimitiveIntId(id); // id-only document
var clazz = SampleClasses.DocumentWithPrimitiveIntId.class;

var existingDoc = reactiveTemplate.findById(id, clazz).block();
assertThat(existingDoc).withFailMessage("The same record already exists").isNull();

reactiveTemplate.insert(doc).block();
var resultsFindById = reactiveTemplate.findById(id, clazz).block();
assertThat(resultsFindById).withFailMessage("findById error").isEqualTo(doc);
var resultsFindAll = reactiveTemplate.findAll(clazz).collectList().block();
// findAll() must correctly find the record that contains id and no bins
assertThat(resultsFindAll).size().withFailMessage("findAll error").isEqualTo(1);

// cleanup
reactiveTemplate.delete(doc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.aerospike.sample.SampleClasses;
import org.springframework.data.domain.Sort;

import java.util.List;
Expand Down Expand Up @@ -65,11 +66,32 @@ public void findAll_findNothing() {
Stream<Person> result = template.findAll(Person.class);
assertThat(result).isEmpty();

// bring records back
// 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 findAll_findIdOnlyRecord() {
var id = 100;
var doc = new SampleClasses.DocumentWithPrimitiveIntId(id); // id-only document
var clazz = SampleClasses.DocumentWithPrimitiveIntId.class;

var existingDoc = template.findById(id, clazz);
assertThat(existingDoc).withFailMessage("The same record already exists").isNull();

template.insert(doc);
var resultsFindById = template.findById(id, clazz);
assertThat(resultsFindById).withFailMessage("findById error").isEqualTo(doc);
var resultsFindAll = template.findAll(clazz);
// findAll() must correctly find the record that contains id and no bins
assertThat(resultsFindAll.toList()).size().withFailMessage("findAll error").isEqualTo(1);

// cleanup
template.delete(doc);
}
}

0 comments on commit d7fef31

Please sign in to comment.