Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 18, 2023
1 parent c8ff954 commit 4ef23f7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public <T> void save(T document, String setName) {

@Override
public <T> void saveAll(Iterable<T> documents) {
validateForBatchWrite(documents, "IDsDocuments for saving");
validateForBatchWrite(documents, "Documents for saving");

saveAll(documents, getSetName(documents.iterator().next()));
}
Expand Down Expand Up @@ -460,11 +460,8 @@ private void deleteByIds(Collection<?> ids, String setName) {

@Override
public void deleteByIds(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys, "Grouped keys must not be null!");
Assert.notNull(groupedKeys.getEntitiesKeys(), "Entities keys must not be null!");
validateGroupedKeys(groupedKeys);
Assert.notEmpty(groupedKeys.getEntitiesKeys(), "Entities keys must not be empty!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
"server version " + SERVER_VERSION_6 + ", see serverMajorVersion configuration parameter");

if (groupedKeys.getEntitiesKeys() == null || groupedKeys.getEntitiesKeys().isEmpty()) {
return;
Expand Down Expand Up @@ -839,9 +836,7 @@ public <T, S> List<S> findByIds(Iterable<?> ids, Class<T> entityClass, Class<S>

@Override
public GroupedEntities findByIds(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys, "Grouped keys must not be null!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
"server version " + SERVER_VERSION_6 + ", see serverMajorVersion configuration parameter");
validateGroupedKeys(groupedKeys);

if (groupedKeys.getEntitiesKeys() == null || groupedKeys.getEntitiesKeys().isEmpty()) {
return GroupedEntities.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ public <T> BatchWriteData<T> getBatchWriteForUpdate(T document, String setName)
entity.hasVersionProperty());
}

protected void validateGroupedKeys(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys, "Grouped keys must not be null!");
Assert.notNull(groupedKeys.getEntitiesKeys(), "Entities keys must not be null!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
"server version " + SERVER_VERSION_6 + ", see serverMajorVersion configuration parameter");
}

protected boolean batchWriteSizeMatch(int batchSize, int currentSize) {
return batchSize > 0 && currentSize == batchSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,8 @@ private Mono<Void> batchDeleteAndCheckForErrors(IAerospikeReactorClient reactorC

@Override
public Mono<Void> deleteByIds(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys, "Grouped keys must not be null!");
Assert.notNull(groupedKeys.getEntitiesKeys(), "Entities keys must not be null!");
validateGroupedKeys(groupedKeys);
Assert.notEmpty(groupedKeys.getEntitiesKeys(), "Entities keys must not be empty!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
"server version " + SERVER_VERSION_6 + ", see serverMajorVersion configuration parameter");

if (groupedKeys.getEntitiesKeys() == null || groupedKeys.getEntitiesKeys().isEmpty()) {
return Mono.empty();
Expand Down Expand Up @@ -766,9 +763,7 @@ private <T> Flux<T> findByIds(Collection<?> ids, Class<T> targetClass, String se

@Override
public Mono<GroupedEntities> findByIds(GroupedKeys groupedKeys) {
Assert.notNull(groupedKeys, "Grouped keys must not be null!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
"server version " + SERVER_VERSION_6 + ", see serverMajorVersion configuration parameter");
validateGroupedKeys(groupedKeys);

if (groupedKeys.getEntitiesKeys() == null || groupedKeys.getEntitiesKeys().isEmpty()) {
return Mono.just(GroupedEntities.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public interface AbstractFindByEntitiesTest {

@Test
default void shouldFindAllRequestedEntities() {
List<Person> persons = generatePersons(5);
List<Customer> customers = generateCustomers(3);
List<Person> persons = saveGeneratedPersons(5);
List<Customer> customers = saveGeneratedCustomers(3);

GroupedKeys groupedKeys = getGroupedKeys(persons, customers);
GroupedEntities byIds = findByIds(groupedKeys);
Expand All @@ -38,8 +38,8 @@ default void shouldFindAllRequestedEntities() {

@Test
default void shouldReturnAnEmptyResultIfKeysWhereSetToWrongEntities() {
List<Person> persons = generatePersons(5);
List<Customer> customers = generateCustomers(3);
List<Person> persons = saveGeneratedPersons(5);
List<Customer> customers = saveGeneratedCustomers(3);

Set<String> requestedPersonsIds = persons.stream()
.map(Person::getId)
Expand All @@ -59,8 +59,8 @@ default void shouldReturnAnEmptyResultIfKeysWhereSetToWrongEntities() {

@Test
default void shouldFindSomeOfIdsOfRequestedEntities() {
List<Person> persons = generatePersons(2);
List<Customer> customers = generateCustomers(3);
List<Person> persons = saveGeneratedPersons(2);
List<Customer> customers = saveGeneratedCustomers(3);

GroupedKeys requestMapWithRandomExtraIds = getGroupedEntitiesKeysWithRandomExtraIds(persons, customers);
GroupedEntities results = findByIds(requestMapWithRandomExtraIds);
Expand All @@ -72,7 +72,7 @@ default void shouldFindSomeOfIdsOfRequestedEntities() {

@Test
default void shouldFindResultsOfOneOfRequestedEntity() {
List<Person> persons = generatePersons(3);
List<Person> persons = saveGeneratedPersons(3);

GroupedKeys groupedKeysWithRandomExtraIds = getGroupedEntitiesKeysWithRandomExtraIds(persons, emptyList());
GroupedEntities results = findByIds(groupedKeysWithRandomExtraIds);
Expand All @@ -84,7 +84,7 @@ default void shouldFindResultsOfOneOfRequestedEntity() {

@Test
default void shouldFindForOneEntityIfAnotherContainsEmptyRequestList() {
List<Person> persons = generatePersons(3);
List<Person> persons = saveGeneratedPersons(3);

GroupedKeys groupedKeys = getGroupedKeys(persons, emptyList());
GroupedEntities batchGroupedEntities = findByIds(groupedKeys);
Expand Down Expand Up @@ -126,7 +126,7 @@ default void shouldReturnMapWithEmptyResultsIfNoEntitiesWhereFound() {

@Test
default void shouldThrowMappingExceptionOnNonAerospikeEntityClass() {
List<Person> persons = generatePersons(2);
List<Person> persons = saveGeneratedPersons(2);
Set<String> personIds = persons.stream()
.map(Person::getId)
.collect(Collectors.toSet());
Expand Down Expand Up @@ -188,7 +188,7 @@ default GroupedKeys getGroupedEntitiesKeysWithRandomExtraIds(Collection<Person>
.build();
}

default List<Customer> generateCustomers(int count) {
default List<Customer> saveGeneratedCustomers(int count) {
return IntStream.range(0, count)
.mapToObj(i -> Customer.builder().id(nextId())
.firstName("firstName" + i)
Expand All @@ -198,7 +198,7 @@ default List<Customer> generateCustomers(int count) {
.collect(Collectors.toList());
}

default List<Person> generatePersons(int count) {
default List<Person> saveGeneratedPersons(int count) {
return IntStream.range(0, count)
.mapToObj(i -> Person.builder().id(nextId())
.firstName("firstName" + i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.policy.Policy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.aerospike.BaseBlockingIntegrationTests;
Expand Down Expand Up @@ -48,9 +48,12 @@
// this test class does not require secondary indexes created on startup
public class AerospikeTemplateInsertTests extends BaseBlockingIntegrationTests {

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

@Test
Expand All @@ -63,7 +66,6 @@ public void insertsAndFindsWithCustomCollectionSet() {
assertThat(record.getString("data")).isEqualTo("data0");
CustomCollectionClass result = template.findById(id, CustomCollectionClass.class);
assertThat(result).isEqualTo(initial);
template.delete(result); // cleanup
}

@Test
Expand All @@ -86,7 +88,6 @@ public void insertsDocumentWithListMapDateStringLongValues() {

Person actual = template.findById(id, Person.class);
assertThat(actual).isEqualTo(customer);
template.delete(actual); // cleanup
}

@Test
Expand All @@ -109,7 +110,6 @@ public void insertsDocumentWithListMapDateStringLongValuesAndSetName() {

Person actual = template.findById(id, Person.class, OVERRIDE_SET_NAME);
assertThat(actual).isEqualTo(customer);
template.delete(actual, OVERRIDE_SET_NAME); // cleanup
}

@Test
Expand All @@ -119,7 +119,6 @@ public void insertsAndFindsDocumentWithByteArrayField() {

DocumentWithByteArray result = template.findById(id, DocumentWithByteArray.class);
assertThat(result).isEqualTo(document);
template.delete(result); // cleanup
}

@Test
Expand All @@ -128,7 +127,6 @@ public void insertsDocumentWithNullFields() {
template.insert(document);

assertThat(document.getField()).isNull();
template.delete(template.findById(id, VersionedClass.class)); // cleanup
}

@Test
Expand All @@ -137,7 +135,6 @@ public void insertsDocumentWithZeroVersionIfThereIsNoDocumentWithSameKey() {
template.insert(document);

assertThat(document.getVersion()).isEqualTo(1);
template.delete(template.findById(id, VersionedClass.class)); // cleanup
}

@Test
Expand All @@ -148,7 +145,6 @@ public void insertsDocumentWithVersionGreaterThanZeroIfThereIsNoDocumentWithSame
template.insert(document);

assertThat(document.getVersion()).isEqualTo(1);
template.delete(template.findById(id, VersionedClass.class)); // cleanup
}

@Test
Expand All @@ -158,7 +154,6 @@ public void throwsExceptionForDuplicateId() {

assertThatThrownBy(() -> template.insert(person))
.isInstanceOf(DuplicateKeyException.class);
template.delete(template.findById(id, Person.class)); // cleanup
}

@Test
Expand All @@ -168,7 +163,6 @@ public void throwsExceptionForDuplicateIdForVersionedDocument() {
template.insert(document);
assertThatThrownBy(() -> template.insert(document))
.isInstanceOf(DuplicateKeyException.class);
template.delete(template.findById(id, VersionedClass.class)); // cleanup
}

@Test
Expand All @@ -188,7 +182,6 @@ public void insertsOnlyFirstDocumentAndNextAttemptsShouldFailWithDuplicateKeyExc
});

assertThat(duplicateKeyCounter.intValue()).isEqualTo(numberOfConcurrentSaves - 1);
template.delete(template.findById(id, VersionedClass.class)); // cleanup
}

@Test
Expand All @@ -208,7 +201,6 @@ public void insertsOnlyFirstDocumentAndNextAttemptsShouldFailWithDuplicateKeyExc
});

assertThat(duplicateKeyCounter.intValue()).isEqualTo(numberOfConcurrentSaves - 1);
template.delete(template.findById(id, Person.class)); // cleanup
}

@Test
Expand Down Expand Up @@ -239,7 +231,6 @@ public void insertAll_insertsAllDocuments() {
.collect(Collectors.toList());
result = template.findByIds(ids, Person.class);
assertThat(result).hasSameElementsAs(personsToInsert);
template.deleteAll(Person.class); // cleanup
}
}

Expand All @@ -262,7 +253,6 @@ public void insertAllWithSetName_insertsAllDocuments() {
.collect(Collectors.toList()), Person.class, OVERRIDE_SET_NAME);

assertThat(result).hasSameElementsAs(persons);
template.deleteAll(Person.class); // cleanup
}

@Test
Expand All @@ -275,7 +265,6 @@ public void insertAll_rejectsDuplicateIds() {
.isInstanceOf(AerospikeException.BatchRecordArray.class)
.hasMessageContaining("Errors during batch insert");
Assertions.assertEquals(1, (long) first.getVersion());
template.delete(first); // cleanup
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ public void deleteAllFromDifferentSets_ShouldDeleteAllDocuments() {
.entityKeys(SampleClasses.VersionedClass.class, List.of(entity2_1.getId(), entity2_2.getId()))
.entityKeys(Person.class, List.of(entity3_1.getId(), entity3_2.getId()))
.build();
// reactiveTemplate.deleteByIds(GroupedKeys.builder()
// .entityKeys(SampleClasses.DocumentWithExpiration.class, List.of(entity1_1.getId())).build()).block();
// .entityKeys(SampleClasses.DocumentWithExpiration.class, List.of(entity1_1.getId(), entity1_2.getId
// ())).build()).block();
// reactiveTemplate.deleteByIds(GroupedKeys.builder()
// .entityKeys(SampleClasses.VersionedClass.class, List.of(entity2.getId())).build()).block();
// .entityKeys(SampleClasses.VersionedClass.class, List.of(entity2_1.getId(), entity2_2.getId()))
// .build()).block();
reactiveTemplate.deleteByIds(groupedKeys).block();

List<SampleClasses.DocumentWithExpiration> list1 = reactiveTemplate.findByIds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ReactiveAerospikeTemplateFindByQueryProjectionTest extends BaseReac
@BeforeAll
public void beforeAllSetUp() {
reactiveTemplate.deleteAll(Person.class);
reactiveTemplate.deleteAll(OVERRIDE_SET_NAME);
additionalAerospikeTestOperations.createIndex(
Person.class, "person_age_index", "age", IndexType.NUMERIC);
additionalAerospikeTestOperations.createIndex(
Expand All @@ -50,6 +51,7 @@ public void beforeAllSetUp() {
@BeforeEach
public void setUp() {
super.setUp();
reactiveTemplate.deleteAll(Person.class).block();
}

@AfterAll
Expand All @@ -59,7 +61,7 @@ public void afterAll() {
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);
additionalAerospikeTestOperations.dropIndex(OVERRIDE_SET_NAME, "person_first_name_index" + OVERRIDE_SET_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
import com.aerospike.client.policy.Policy;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.OptimisticLockingFailureException;
Expand Down Expand Up @@ -31,8 +31,8 @@
// this test class does not require secondary indexes created on startup
public class ReactiveAerospikeTemplateUpdateTests extends BaseReactiveIntegrationTests {

@AfterEach
public void afterEach() {
@BeforeEach
public void beforeEach() {
reactiveTemplate.deleteAll(Person.class).block();
reactiveTemplate.deleteAll(VersionedClass.class).block();
}
Expand Down Expand Up @@ -390,8 +390,6 @@ public void updateAllIfDocumentsChanged() {
assertThat(result1.getFirstName()).isEqualTo("Wolfgang M");
assertThat(result2.getAge()).isEqualTo(age2);
assertThat(result2.getFirstName()).isEqualTo("Johann B");
reactiveTemplate.delete(result1).block(); // cleanup
reactiveTemplate.delete(result2).block(); // cleanup

List<Person> persons = additionalAerospikeTestOperations.saveGeneratedPersons(101);
Iterable<Person> personsWithUpdate = persons.stream()
Expand Down

0 comments on commit 4ef23f7

Please sign in to comment.