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-525 Make template.findAll() work correctly with id-only records #772

Merged
merged 2 commits into from
Sep 1, 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 @@ -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);
}
}
Loading