From 3adc8b9cd46d32c67b66bff7a72483a10315ce41 Mon Sep 17 00:00:00 2001 From: agrgr Date: Sun, 22 Dec 2024 19:05:11 +0200 Subject: [PATCH] use distributed configuration, add client-only modules, refactoring --- pom.xml | 37 +++++---- .../pom.xml | 23 +----- .../aerospike/AerospikeAutoConfiguration.java | 19 ++++- .../aerospike/AerospikeProperties.java | 5 +- .../aerospike/AerospikeDataProperties.java | 0 .../util}/AerospikeConfigurationUtils.java | 25 +++--- .../boot/autoconfigure/util/IsClientOnly.java | 20 +++++ .../autoconfigure/util/IsNotClientOnly.java | 22 ++++++ .../util/ValidateHostsProperty.java | 24 ++++++ .../main/resources/META-INF/spring.factories | 3 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/test/resources/logback-test.xml | 0 .../utils/HasNamespaceProperty.java | 15 ---- .../utils/NoNamespaceProperty.java | 15 ---- .../main/resources/META-INF/spring.factories | 8 -- ...ot.autoconfigure.AutoConfiguration.imports | 6 -- .../AerospikeTestConfigurations.java | 76 ------------------- .../pom.xml | 43 +++++++++++ .../AerospikeReactorClientConfiguration.java | 56 ++++++++++++++ .../main/resources/META-INF/spring.factories | 3 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + spring-boot-starter-aerospike/pom.xml | 35 +++++++++ .../AerospikeClientConfiguration.java | 42 +++------- .../main/resources/META-INF/spring.factories | 3 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../pom.xml | 20 +++-- ...erospikeReactiveDataAutoConfiguration.java | 21 +++-- .../AerospikeReactiveDataConfiguration.java | 9 ++- ...ReactiveRepositoriesAutoConfiguration.java | 4 +- ...erospikeReactiveRepositoriesRegistrar.java | 2 +- .../main/resources/META-INF/spring.factories | 4 + ...ot.autoconfigure.AutoConfiguration.imports | 2 + ...pikeReactiveDataAutoConfigurationTest.java | 30 ++++---- ...tiveRepositoriesAutoConfigurationTest.java | 39 +++++----- .../data/AerospikeTestConfigurations.java | 36 +++++++++ .../data/TestAutoConfigurationPackage.java | 45 +++++++++++ ...TestAutoConfigurationPackageRegistrar.java | 43 +++++++++++ .../aerospike/reactive/data}/TestUtils.java | 2 +- .../aerospike/reactive/data}/city/City.java | 2 +- .../reactive/data}/city/CityRepository.java | 2 +- .../data}/city/ReactiveCityRepository.java | 2 +- .../data}/empty/EmptyDataPackage.java | 2 +- spring-boot-starter-data-aerospike/pom.xml | 18 ++++- .../data}/AerospikeDataAutoConfiguration.java | 24 ++++-- .../data}/AerospikeDataConfiguration.java | 8 +- ...erospikeRepositoriesAutoConfiguration.java | 12 +-- .../data}/AerospikeRepositoriesRegistrar.java | 2 +- .../main/resources/META-INF/spring.factories | 4 + ...ot.autoconfigure.AutoConfiguration.imports | 2 + .../AerospikeDataAutoConfigurationTest.java | 37 +++++---- ...pikeRepositoriesAutoConfigurationTest.java | 43 +++++------ .../data/AerospikeTestConfigurations.java | 35 +++++++++ .../data}/TestAutoConfigurationPackage.java | 3 +- ...TestAutoConfigurationPackageRegistrar.java | 4 +- .../boot/aerospike/data/TestUtils.java | 14 ++++ .../boot/aerospike/data/city/City.java | 37 +++++++++ .../aerospike/data/city/CityRepository.java | 23 ++++++ .../data/city/ReactiveCityRepository.java | 28 +++++++ .../data/empty/EmptyDataPackage.java | 26 +++++++ .../pom.xml | 12 ++- .../reactive-client/pom.xml | 26 +++++++ ...ctorAerospikeClientExampleApplication.java | 13 ++++ .../src/main/resources/application.properties | 1 + .../client/reactive/ReactiveClientTest.java | 24 ++++++ .../reactive-data}/pom.xml | 10 +-- .../aerospike/example/reactive/Customer.java | 0 .../reactive/ReactiveCustomerController.java | 1 - .../reactive/ReactiveCustomerRepository.java | 0 ...SpringDataAerospikeExampleApplication.java | 1 - .../src/main/resources/application.properties | 0 .../src/main/resources/bootstrap.properties | 0 .../reactive/ReactiveIntegrationTest.java | 0 .../src/test/resources/logback-test.xml | 0 .../sync-client/pom.xml | 27 +++++++ ...SyncAerospikeClientExampleApplication.java | 13 ++++ .../src/main/resources/application.properties | 1 + .../example/client/sync/SyncClientTest.java | 24 ++++++ .../sync-data}/pom.xml | 10 +-- .../com/aerospike/example/sync/Customer.java | 0 .../example/sync/SyncCustomerController.java | 1 - .../example/sync/SyncCustomerRepository.java | 0 ...SpringDataAerospikeExampleApplication.java | 1 - .../src/main/resources/application.properties | 0 .../src/main/resources/bootstrap.properties | 0 .../example/sync/SyncIntegrationTest.java | 0 .../src/test/resources/logback-test.xml | 0 86 files changed, 878 insertions(+), 355 deletions(-) rename {spring-boot-autoconfigure-data-aerospike => spring-boot-autoconfigure-aerospike-common}/pom.xml (79%) rename {spring-boot-autoconfigure-data-aerospike => spring-boot-autoconfigure-aerospike-common}/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java (66%) rename {spring-boot-autoconfigure-data-aerospike => spring-boot-autoconfigure-aerospike-common}/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java (97%) rename {spring-boot-autoconfigure-data-aerospike => spring-boot-autoconfigure-aerospike-common}/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataProperties.java (100%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils => spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util}/AerospikeConfigurationUtils.java (96%) create mode 100644 spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsClientOnly.java create mode 100644 spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsNotClientOnly.java create mode 100644 spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/ValidateHostsProperty.java create mode 100644 spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename {spring-boot-autoconfigure-data-aerospike => spring-boot-autoconfigure-aerospike-common}/src/test/resources/logback-test.xml (100%) delete mode 100644 spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/HasNamespaceProperty.java delete mode 100644 spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/NoNamespaceProperty.java delete mode 100644 spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring.factories delete mode 100644 spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeTestConfigurations.java create mode 100644 spring-boot-starter-aerospike-reactive/pom.xml create mode 100644 spring-boot-starter-aerospike-reactive/src/main/java/org/springframework/boot/client/reactive/autoconfigure/AerospikeReactorClientConfiguration.java create mode 100644 spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 spring-boot-starter-aerospike/pom.xml rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike => spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure}/AerospikeClientConfiguration.java (61%) create mode 100644 spring-boot-starter-aerospike/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-starter-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveDataAutoConfiguration.java (69%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveDataConfiguration.java (82%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveRepositoriesAutoConfiguration.java (94%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveRepositoriesRegistrar.java (96%) create mode 100644 spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveDataAutoConfigurationTest.java (82%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/AerospikeReactiveRepositoriesAutoConfigurationTest.java (68%) create mode 100644 spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeTestConfigurations.java create mode 100644 spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackage.java create mode 100644 spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackageRegistrar.java rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/TestUtils.java (85%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/city/City.java (92%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/city/CityRepository.java (91%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/city/ReactiveCityRepository.java (92%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data}/empty/EmptyDataPackage.java (91%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data}/AerospikeDataAutoConfiguration.java (70%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data}/AerospikeDataConfiguration.java (83%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data}/AerospikeRepositoriesAutoConfiguration.java (79%) rename {spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data}/AerospikeRepositoriesRegistrar.java (96%) create mode 100644 spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data}/AerospikeDataAutoConfigurationTest.java (85%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike => spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data}/AerospikeRepositoriesAutoConfigurationTest.java (66%) create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeTestConfigurations.java rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure => spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data}/TestAutoConfigurationPackage.java (90%) rename {spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure => spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data}/TestAutoConfigurationPackageRegistrar.java (93%) create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestUtils.java create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/City.java create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/CityRepository.java create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/ReactiveCityRepository.java create mode 100644 spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/empty/EmptyDataPackage.java rename {spring-boot-starter-data-aerospike-example => spring-boot-starter-example-aerospike}/pom.xml (84%) create mode 100644 spring-boot-starter-example-aerospike/reactive-client/pom.xml create mode 100644 spring-boot-starter-example-aerospike/reactive-client/src/main/java/com/aerospike/example/client/reactive/SpringReactorAerospikeClientExampleApplication.java create mode 100644 spring-boot-starter-example-aerospike/reactive-client/src/main/resources/application.properties create mode 100644 spring-boot-starter-example-aerospike/reactive-client/src/test/java/com/aerospike/example/client/reactive/ReactiveClientTest.java rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/pom.xml (78%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/java/com/aerospike/example/reactive/Customer.java (100%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java (99%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/java/com/aerospike/example/reactive/ReactiveCustomerRepository.java (100%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java (99%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/resources/application.properties (100%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/main/resources/bootstrap.properties (100%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/test/java/com/aerospike/example/reactive/ReactiveIntegrationTest.java (100%) rename {spring-boot-starter-data-aerospike-example/reactive => spring-boot-starter-example-aerospike/reactive-data}/src/test/resources/logback-test.xml (100%) create mode 100644 spring-boot-starter-example-aerospike/sync-client/pom.xml create mode 100644 spring-boot-starter-example-aerospike/sync-client/src/main/java/com/aerospike/example/client/sync/SpringSyncAerospikeClientExampleApplication.java create mode 100644 spring-boot-starter-example-aerospike/sync-client/src/main/resources/application.properties create mode 100644 spring-boot-starter-example-aerospike/sync-client/src/test/java/com/aerospike/example/client/sync/SyncClientTest.java rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/pom.xml (78%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/java/com/aerospike/example/sync/Customer.java (100%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/java/com/aerospike/example/sync/SyncCustomerController.java (99%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/java/com/aerospike/example/sync/SyncCustomerRepository.java (100%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java (99%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/resources/application.properties (100%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/main/resources/bootstrap.properties (100%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/test/java/com/aerospike/example/sync/SyncIntegrationTest.java (100%) rename {spring-boot-starter-data-aerospike-example/sync => spring-boot-starter-example-aerospike/sync-data}/src/test/resources/logback-test.xml (100%) diff --git a/pom.xml b/pom.xml index d88ea77..eae29b1 100644 --- a/pom.xml +++ b/pom.xml @@ -24,10 +24,12 @@ pom - spring-boot-autoconfigure-data-aerospike - spring-boot-starter-data-aerospike - spring-boot-starter-data-aerospike-reactive - spring-boot-starter-data-aerospike-example + spring-boot-autoconfigure-aerospike-common + spring-boot-starter-aerospike + spring-boot-starter-aerospike-reactive + spring-boot-starter-data-aerospike + spring-boot-starter-data-aerospike-reactive + spring-boot-starter-example-aerospike @@ -40,7 +42,7 @@ 1.6 1.6.0 - 4.8.0 + 4.8.0-local-554_latest 7.1.0 7.2.1 3.1.6 @@ -102,12 +104,17 @@ com.aerospike - spring-boot-autoconfigure-data-aerospike + spring-boot-autoconfigure-aerospike-common ${project.version} com.aerospike - spring-boot-starter-data-aerospike-reactive + spring-boot-starter-aerospike + ${project.version} + + + com.aerospike + spring-boot-starter-aerospike-reactive ${project.version} @@ -115,24 +122,26 @@ spring-boot-starter-data-aerospike ${project.version} - com.aerospike - spring-data-aerospike - ${spring-data-aerospike.version} + spring-boot-starter-data-aerospike-reactive + ${project.version} - com.aerospike - aerospike-reactor-client - ${aerospike-reactor-client.version} + spring-data-aerospike + ${spring-data-aerospike.version} com.aerospike aerospike-client ${aerospike-client.version} - + + com.aerospike + aerospike-reactor-client + ${aerospike-reactor-client.version} + org.springframework.cloud spring-cloud-test-support diff --git a/spring-boot-autoconfigure-data-aerospike/pom.xml b/spring-boot-autoconfigure-aerospike-common/pom.xml similarity index 79% rename from spring-boot-autoconfigure-data-aerospike/pom.xml rename to spring-boot-autoconfigure-aerospike-common/pom.xml index d15d712..7ded945 100644 --- a/spring-boot-autoconfigure-data-aerospike/pom.xml +++ b/spring-boot-autoconfigure-aerospike-common/pom.xml @@ -9,41 +9,25 @@ ${revision} - Spring Data Aerospike Starters: spring-boot-autoconfigure-data-aerospike - spring-boot-autoconfigure-data-aerospike + Spring Data Aerospike Starters: spring-boot-autoconfigure-aerospike-common + spring-boot-autoconfigure-aerospike-common Auto configuration for using Spring Data Aerospike - org.projectlombok lombok provided - - - com.aerospike - spring-data-aerospike - true - - org.springframework.boot spring-boot-autoconfigure - com.aerospike - aerospike-client - true - - - - com.aerospike - aerospike-reactor-client + spring-data-aerospike true - org.springframework.boot spring-boot-autoconfigure-processor @@ -54,7 +38,6 @@ spring-boot-configuration-processor true - org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java similarity index 66% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java rename to spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java index 14a71fe..273b48b 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java @@ -17,12 +17,17 @@ package org.springframework.boot.autoconfigure.aerospike; import com.aerospike.client.IAerospikeClient; +import com.aerospike.client.policy.ClientPolicy; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.util.ValidateHostsProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; + +import static org.springframework.boot.autoconfigure.util.AerospikeConfigurationUtils.getClientPolicyConfig; /** * {@link EnableAutoConfiguration Auto-configuration} for Aerospike client. @@ -31,7 +36,13 @@ */ @AutoConfiguration @ConditionalOnClass(IAerospikeClient.class) -@ConditionalOnProperty("spring.aerospike.hosts") -@EnableConfigurationProperties({AerospikeProperties.class, AerospikeDataProperties.class}) // TODO: should data properties be here? +@Conditional(ValidateHostsProperty.class) +@EnableConfigurationProperties(AerospikeProperties.class) public class AerospikeAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties) { + return getClientPolicyConfig(new ClientPolicy(), properties); + } } diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java similarity index 97% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java rename to spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java index 41eb916..b032b49 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeProperties.java @@ -19,10 +19,11 @@ import com.aerospike.client.policy.AuthMode; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.data.aerospike.config.AerospikeDataSettings; import java.time.Duration; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION; + /** * Basic configuration properties for Aerospike client. * For more details on each option see corresponding field documentation in {@link com.aerospike.client.policy.ClientPolicy}. @@ -30,7 +31,7 @@ * @author Anastasiia Smirnova */ @Data -@ConfigurationProperties(prefix = "spring.aerospike") +@ConfigurationProperties(prefix = CONFIG_PREFIX_CONNECTION) public class AerospikeProperties { /** diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataProperties.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataProperties.java similarity index 100% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataProperties.java rename to spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataProperties.java diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/AerospikeConfigurationUtils.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/AerospikeConfigurationUtils.java similarity index 96% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/AerospikeConfigurationUtils.java rename to spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/AerospikeConfigurationUtils.java index abfbe98..72d6357 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/AerospikeConfigurationUtils.java +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/AerospikeConfigurationUtils.java @@ -1,4 +1,4 @@ -package org.springframework.boot.autoconfigure.utils; +package org.springframework.boot.autoconfigure.util; import com.aerospike.client.Host; import com.aerospike.client.policy.BatchDeletePolicy; @@ -28,14 +28,6 @@ public static Collection getClientHosts(AerospikeProperties properties) { } } - public static String getNamespace(AerospikeDataProperties dataProperties) { - if (dataProperties.getNamespace() != null) { - return dataProperties.getNamespace(); - } else { - return null; - } - } - public static ClientPolicy getClientPolicyConfig(ClientPolicy clientPolicy, AerospikeProperties properties) { whenPresent(properties.getUser(), p -> clientPolicy.user = p); whenPresent(properties.getPassword(), p -> clientPolicy.password = p); @@ -57,11 +49,6 @@ public static ClientPolicy getClientPolicyConfig(ClientPolicy clientPolicy, Aero clientPolicy.batchWritePolicyDefault = setupBatchWritePolicy(properties); clientPolicy.batchDeletePolicyDefault = setupBatchDeletePolicy(properties); clientPolicy.batchUDFPolicyDefault = setupBatchUDFPolicy(properties); -// aerospikeEventLoops.ifPresent(loops -> clientPolicy.eventLoops = loops); // TODO - -// clientPolicy.user = "tester"; -// clientPolicy.password = "psw"; - return clientPolicy; } @@ -137,8 +124,16 @@ private static void whenPresent(T param, Consumer consumer) { consumer.accept(param); } + public static String getNamespace(AerospikeDataProperties dataProperties) { + if (dataProperties.getNamespace() != null) { + return dataProperties.getNamespace(); + } else { + return null; + } + } + public static void getDataSettings(AerospikeDataProperties dataProperties, - AerospikeDataSettings aerospikeDataSettings) { + AerospikeDataSettings aerospikeDataSettings) { whenPresent(dataProperties.isScansEnabled(), aerospikeDataSettings::setScansEnabled); whenPresent(dataProperties.isCreateIndexesOnStartup(), aerospikeDataSettings::setCreateIndexesOnStartup); whenPresent(dataProperties.getIndexCacheRefreshSeconds(), aerospikeDataSettings::setIndexCacheRefreshSeconds); diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsClientOnly.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsClientOnly.java new file mode 100644 index 0000000..a62f86f --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsClientOnly.java @@ -0,0 +1,20 @@ +package org.springframework.boot.autoconfigure.util; + +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA; + +public class IsClientOnly implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String strIsClientOnly = context.getEnvironment().getProperty("starters.aerospike.client-only"); + String namespace = context.getEnvironment().getProperty(CONFIG_PREFIX_DATA + ".namespace"); + boolean isClientOnly = strIsClientOnly != null && strIsClientOnly.equalsIgnoreCase("true"); + boolean hasNamespace = namespace != null && !namespace.isEmpty(); + // if the explicit client-only property is true, no need to check for namespace + return isClientOnly || !hasNamespace; + } +} diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsNotClientOnly.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsNotClientOnly.java new file mode 100644 index 0000000..703d8e9 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/IsNotClientOnly.java @@ -0,0 +1,22 @@ +package org.springframework.boot.autoconfigure.util; + +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA; + +public class IsNotClientOnly implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String strIsClientOnly = context.getEnvironment().getProperty("starters.aerospike.client-only"); + String namespace = context.getEnvironment().getProperty(CONFIG_PREFIX_DATA + ".namespace"); + boolean isClientOnly = strIsClientOnly != null + && !strIsClientOnly.isEmpty() + && Boolean.getBoolean(strIsClientOnly); + boolean hasNamespace = namespace != null && !namespace.isEmpty(); + // if the explicit client-only property is true, no need to check for namespace + return !isClientOnly && hasNamespace; + } +} diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/ValidateHostsProperty.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/ValidateHostsProperty.java new file mode 100644 index 0000000..cfe2a31 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/util/ValidateHostsProperty.java @@ -0,0 +1,24 @@ +package org.springframework.boot.autoconfigure.util; + +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +import java.security.InvalidParameterException; + +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION; + +public class ValidateHostsProperty implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + String hostsProperty = CONFIG_PREFIX_CONNECTION + ".hosts"; + String hosts = context.getEnvironment().getProperty(hostsProperty); + boolean hasHosts = hosts != null && !hosts.isEmpty(); + + if (!hasHosts) { + throw new InvalidParameterException("Required property '" + hostsProperty + "' is missing"); + } + return true; + } +} diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..67b9295 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration,\ diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..caa37f6 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/resources/logback-test.xml b/spring-boot-autoconfigure-aerospike-common/src/test/resources/logback-test.xml similarity index 100% rename from spring-boot-autoconfigure-data-aerospike/src/test/resources/logback-test.xml rename to spring-boot-autoconfigure-aerospike-common/src/test/resources/logback-test.xml diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/HasNamespaceProperty.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/HasNamespaceProperty.java deleted file mode 100644 index 144005a..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/HasNamespaceProperty.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.springframework.boot.autoconfigure.utils; - -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - - -public class HasNamespaceProperty implements Condition { - - @Override - public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - String namespace = context.getEnvironment().getProperty("spring.data.aerospike.namespace"); - return namespace != null && !namespace.isEmpty(); - } -} diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/NoNamespaceProperty.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/NoNamespaceProperty.java deleted file mode 100644 index eda5943..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/utils/NoNamespaceProperty.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.springframework.boot.autoconfigure.utils; - -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - - -public class NoNamespaceProperty implements Condition { - - @Override - public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - String namespace = context.getEnvironment().getProperty("spring.data.aerospike.namespace"); - return namespace == null || namespace.isEmpty(); - } -} diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 91815cd..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,8 +0,0 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration,\ -org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataAutoConfiguration,\ -org.springframework.boot.autoconfigure.aerospike.AerospikeClientConfiguration,\ -org.springframework.boot.autoconfigure.data.aerospike.AerospikeRepositoriesAutoConfiguration,\ -org.springframework.boot.autoconfigure.data.aerospike.AerospikeReactiveDataAutoConfiguration,\ -org.springframework.boot.autoconfigure.data.aerospike.AerospikeReactiveRepositoriesAutoConfiguration diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 2ca48b0..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,6 +0,0 @@ -org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration -org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataAutoConfiguration -org.springframework.boot.autoconfigure.aerospike.AerospikeClientConfiguration -org.springframework.boot.autoconfigure.data.aerospike.AerospikeRepositoriesAutoConfiguration -org.springframework.boot.autoconfigure.data.aerospike.AerospikeReactiveDataAutoConfiguration -org.springframework.boot.autoconfigure.data.aerospike.AerospikeReactiveRepositoriesAutoConfiguration diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeTestConfigurations.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeTestConfigurations.java deleted file mode 100644 index 04a7111..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeTestConfigurations.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.springframework.boot.autoconfigure.data.aerospike; - -import com.aerospike.client.IAerospikeClient; -import com.aerospike.client.cluster.Node; -import com.aerospike.client.policy.WritePolicy; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.converter.Converter; -import org.springframework.data.aerospike.convert.AerospikeCustomConverters; -import org.springframework.data.aerospike.query.cache.ReactorIndexRefresher; -import org.springframework.data.aerospike.server.version.ServerVersionSupport; - -import java.util.List; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class AerospikeTestConfigurations { - - @AutoConfiguration - public static class AerospikeClientMockConfiguration { - - @Bean - public IAerospikeClient aerospikeClientMock() { - IAerospikeClient client = mock(IAerospikeClient.class); - when(client.getNodes()).thenReturn(new Node[]{}); - when(client.getWritePolicyDefault()).thenReturn(new WritePolicy()); - return client; - } - } - - @AutoConfiguration - public static class AerospikeServerVersionSupportMockConfiguration { - - @Bean - public ServerVersionSupport aerospikeServerVersionSupportMock() { - ServerVersionSupport serverVersionSupport = mock(ServerVersionSupport.class); - when(serverVersionSupport.getServerVersion()).thenReturn("5.0.0.0"); - return serverVersionSupport; - } - } - - @AutoConfiguration - public static class MockReactiveIndexRefresher { - - @Bean - public ReactorIndexRefresher reactiveAerospikeIndexRefresher() { - return mock(ReactorIndexRefresher.class); - } - } - - @AutoConfiguration - @EntityScan("org.springframework.boot.autoconfigure.data.aerospike.city") - public static class EntityScanConfiguration { - - } - - @AutoConfiguration - public static class CustomConversionsConfig { - - @Bean - AerospikeCustomConverters myCustomConversions() { - return new AerospikeCustomConverters(List.of(new CityToStringConverter())); - } - } - - public static class CityToStringConverter implements Converter { - - @Override - public String convert(City value) { - return value.getName(); - } - } -} diff --git a/spring-boot-starter-aerospike-reactive/pom.xml b/spring-boot-starter-aerospike-reactive/pom.xml new file mode 100644 index 0000000..3884930 --- /dev/null +++ b/spring-boot-starter-aerospike-reactive/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + com.aerospike + spring-data-aerospike-starters + ${revision} + + + Spring Data Aerospike Starters: spring-boot-starter-aerospike-reactive + spring-boot-starter-aerospike-reactive + Starter for using Aerospike Reactor Java client + + + + org.springframework.boot + spring-boot-starter + + + com.aerospike + spring-boot-autoconfigure-aerospike-common + + + com.aerospike + spring-boot-starter-aerospike + + + io.projectreactor + reactor-core + + + com.aerospike + aerospike-reactor-client + + + org.projectlombok + lombok + provided + + + \ No newline at end of file diff --git a/spring-boot-starter-aerospike-reactive/src/main/java/org/springframework/boot/client/reactive/autoconfigure/AerospikeReactorClientConfiguration.java b/spring-boot-starter-aerospike-reactive/src/main/java/org/springframework/boot/client/reactive/autoconfigure/AerospikeReactorClientConfiguration.java new file mode 100644 index 0000000..4bbe309 --- /dev/null +++ b/spring-boot-starter-aerospike-reactive/src/main/java/org/springframework/boot/client/reactive/autoconfigure/AerospikeReactorClientConfiguration.java @@ -0,0 +1,56 @@ +package org.springframework.boot.client.reactive.autoconfigure; + +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.aerospike.client.IAerospikeClient; +import com.aerospike.client.reactor.AerospikeReactorClient; +import com.aerospike.client.reactor.IAerospikeReactorClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.util.IsClientOnly; +import org.springframework.boot.client.autoconfigure.AerospikeClientConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import reactor.core.publisher.Flux; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Aerospike client. + * Loaded only for client-only modules or when no namespace property is given. + * + * @author Anastasiia Smirnova + */ +//@EnableAutoConfiguration +@AutoConfiguration +@Conditional(IsClientOnly.class) +@ConditionalOnClass({IAerospikeClient.class, IAerospikeReactorClient.class, Flux.class}) +@AutoConfigureAfter({AerospikeClientConfiguration.class}) +@Slf4j +public class AerospikeReactorClientConfiguration { + + @Bean(name = "aerospikeReactorClient", destroyMethod = "") + @ConditionalOnMissingBean + // disable destroy method, because we do not want AerospikeReactorClient to close AerospikeClient + public IAerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient) { + log.info("Initializing Aerospike Reactor Java client"); + return new AerospikeReactorClient(aerospikeClient); + + } +} \ No newline at end of file diff --git a/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring.factories b/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..02930cf --- /dev/null +++ b/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.boot.client.reactive.autoconfigure.AerospikeReactorClientConfiguration diff --git a/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..ab86734 --- /dev/null +++ b/spring-boot-starter-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.boot.client.reactive.autoconfigure.AerospikeReactorClientConfiguration \ No newline at end of file diff --git a/spring-boot-starter-aerospike/pom.xml b/spring-boot-starter-aerospike/pom.xml new file mode 100644 index 0000000..40df572 --- /dev/null +++ b/spring-boot-starter-aerospike/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + com.aerospike + spring-data-aerospike-starters + ${revision} + + + Spring Data Aerospike Starters: spring-boot-starter-aerospike + spring-boot-starter-aerospike + Starter for using Aerospike Java client + + + + org.springframework.boot + spring-boot-starter + + + com.aerospike + spring-boot-autoconfigure-aerospike-common + + + com.aerospike + aerospike-client + + + org.projectlombok + lombok + provided + + + \ No newline at end of file diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeClientConfiguration.java b/spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java similarity index 61% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeClientConfiguration.java rename to spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java index ae9b305..dfb8e52 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeClientConfiguration.java +++ b/spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java @@ -1,3 +1,5 @@ +package org.springframework.boot.client.autoconfigure; + /* * Copyright 2019 the original author or authors. * @@ -14,38 +16,33 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.aerospike; - import com.aerospike.client.AerospikeClient; import com.aerospike.client.Host; import com.aerospike.client.IAerospikeClient; -import com.aerospike.client.async.EventLoops; import com.aerospike.client.policy.ClientPolicy; -import com.aerospike.client.reactor.AerospikeReactorClient; -import com.aerospike.client.reactor.IAerospikeReactorClient; +import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.utils.NoNamespaceProperty; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration; +import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.util.IsClientOnly; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; -import reactor.core.publisher.Flux; - -import java.util.Optional; - -import static org.springframework.boot.autoconfigure.utils.AerospikeConfigurationUtils.getClientPolicyConfig; /** * {@link EnableAutoConfiguration Auto-configuration} for Aerospike client. - * Loaded only when no namespace property is given. + * Loaded only for client-only modules or when no namespace property is given. * * @author Anastasiia Smirnova */ +//@EnableAutoConfiguration @AutoConfiguration -@Conditional(NoNamespaceProperty.class) +@Conditional(IsClientOnly.class) +@ConditionalOnClass(IAerospikeClient.class) @AutoConfigureAfter({AerospikeAutoConfiguration.class}) @Slf4j public class AerospikeClientConfiguration { @@ -54,25 +51,8 @@ public class AerospikeClientConfiguration { @ConditionalOnMissingBean(IAerospikeClient.class) public IAerospikeClient aerospikeClient(AerospikeProperties properties, ClientPolicy aerospikeClientPolicy) { - log.info("Initializing only Aerospike Java client due to no namespace property given"); + log.info("Initializing Aerospike Java client"); Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort()); return new AerospikeClient(aerospikeClientPolicy, hosts); } - - - @ConditionalOnClass({IAerospikeReactorClient.class, Flux.class}) - public static class AerospikeReactiveAutoConfiguration { - - @Bean(name = "aerospikeReactorClient", destroyMethod = "") - @ConditionalOnMissingBean - // disable destroy method, because we do not want AerospikeReactorClient to close AerospikeClient - public IAerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient) { - return new AerospikeReactorClient(aerospikeClient); - } - } - - @ConditionalOnMissingBean - public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties) { - return getClientPolicyConfig(new ClientPolicy(), properties); - } } diff --git a/spring-boot-starter-aerospike/src/main/resources/META-INF/spring.factories b/spring-boot-starter-aerospike/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..8f53498 --- /dev/null +++ b/spring-boot-starter-aerospike/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.boot.client.autoconfigure.AerospikeClientConfiguration diff --git a/spring-boot-starter-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..74ff002 --- /dev/null +++ b/spring-boot-starter-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.boot.client.autoconfigure.AerospikeClientConfiguration \ No newline at end of file diff --git a/spring-boot-starter-data-aerospike-reactive/pom.xml b/spring-boot-starter-data-aerospike-reactive/pom.xml index 0b2c827..eaf01db 100644 --- a/spring-boot-starter-data-aerospike-reactive/pom.xml +++ b/spring-boot-starter-data-aerospike-reactive/pom.xml @@ -18,25 +18,35 @@ org.springframework.boot spring-boot-starter - + + com.aerospike + spring-boot-autoconfigure-aerospike-common + com.aerospike spring-data-aerospike - com.aerospike - spring-boot-autoconfigure-data-aerospike + spring-boot-starter-aerospike-reactive - io.projectreactor reactor-core - com.aerospike aerospike-reactor-client + + org.projectlombok + lombok + provided + + + org.springframework.boot + spring-boot-starter-test + test + \ No newline at end of file diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfiguration.java b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfiguration.java similarity index 69% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfiguration.java rename to spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfiguration.java index 879254e..250a247 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfiguration.java +++ b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfiguration.java @@ -14,16 +14,19 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import com.aerospike.client.reactor.IAerospikeReactorClient; +import jakarta.annotation.PostConstruct; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; -import org.springframework.boot.autoconfigure.utils.HasNamespaceProperty; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.util.IsClientOnly; +import org.springframework.boot.autoconfigure.util.IsNotClientOnly; +import org.springframework.boot.client.reactive.autoconfigure.AerospikeReactorClientConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Import; @@ -38,10 +41,18 @@ */ @AutoConfiguration @ConditionalOnClass({IAerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class}) -@Conditional(HasNamespaceProperty.class) @AutoConfigureAfter(AerospikeAutoConfiguration.class) -@EnableConfigurationProperties({AerospikeProperties.class, AerospikeDataProperties.class}) @Import(AerospikeReactiveDataConfiguration.class) public class AerospikeReactiveDataAutoConfiguration { + @Conditional(IsNotClientOnly.class) + @EnableConfigurationProperties(AerospikeDataProperties.class) + static class ReactiveDataConfigurationImport { + } + + @Conditional(IsClientOnly.class) + // Import client configuration if 'namespace' is missing + @Import(AerospikeReactorClientConfiguration.class) + static class ReactiveClientConfigurationImport { + } } diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java similarity index 82% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java rename to spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java index 7c7a386..d8c4197 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java +++ b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java @@ -14,22 +14,25 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import com.aerospike.client.Host; import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.NioEventLoops; import com.aerospike.client.policy.ClientPolicy; +import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.util.AerospikeConfigurationUtils; import org.springframework.context.annotation.Configuration; import org.springframework.data.aerospike.config.AbstractReactiveAerospikeDataConfiguration; import org.springframework.data.aerospike.config.AerospikeDataSettings; import java.util.Collection; -import static org.springframework.boot.autoconfigure.utils.AerospikeConfigurationUtils.*; +import static org.springframework.boot.autoconfigure.util.AerospikeConfigurationUtils.*; /** * Configure Spring Data's Aerospike support. @@ -40,7 +43,7 @@ */ @Slf4j @Configuration -public class AerospikeReactiveDataConfiguration extends AbstractReactiveAerospikeDataConfiguration { +public class AerospikeReactiveDataConfiguration extends AbstractReactiveAerospikeDataConfiguration { @Autowired private AerospikeProperties properties; diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfiguration.java b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfiguration.java similarity index 94% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfiguration.java rename to spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfiguration.java index 33b2a45..e54ee89 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfiguration.java +++ b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfiguration.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import com.aerospike.client.reactor.IAerospikeReactorClient; +import jakarta.annotation.PostConstruct; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.ConditionalOnRepositoryType; import org.springframework.boot.autoconfigure.data.RepositoryType; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.data.aerospike.repository.ReactiveAerospikeRepository; import org.springframework.data.aerospike.repository.support.ReactiveAerospikeRepositoryFactoryBean; diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesRegistrar.java b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesRegistrar.java similarity index 96% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesRegistrar.java rename to spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesRegistrar.java index b5d078a..f8a98c5 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesRegistrar.java +++ b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesRegistrar.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; diff --git a/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring.factories b/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..dde67b9 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.boot.aerospike.reactive.data.AerospikeReactiveDataAutoConfiguration,\ +org.springframework.boot.aerospike.reactive.data.AerospikeReactiveRepositoriesAutoConfiguration diff --git a/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..c0a10eb --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +org.springframework.boot.aerospike.reactive.data.AerospikeReactiveDataAutoConfiguration +org.springframework.boot.aerospike.reactive.data.AerospikeReactiveRepositoriesAutoConfiguration diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfigurationTest.java similarity index 82% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfigurationTest.java index 9bc5844..b03d4ff 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataAutoConfigurationTest.java @@ -14,17 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import com.aerospike.client.IAerospikeClient; +import com.aerospike.client.reactor.IAerospikeReactorClient; import org.junit.jupiter.api.Test; +import org.springframework.boot.aerospike.reactive.data.city.City; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration; import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.AerospikeClientMockConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.AerospikeServerVersionSupportMockConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.MockReactiveIndexRefresher; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.data.aerospike.convert.AerospikeConverter; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; @@ -35,7 +34,8 @@ import org.springframework.data.util.TypeInformation; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.autoconfigure.data.aerospike.TestUtils.getField; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.springframework.boot.aerospike.reactive.data.TestUtils.getField; /** * Tests for {@link AerospikeReactiveDataAutoConfiguration}. @@ -46,17 +46,15 @@ public class AerospikeReactiveDataAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AerospikeReactiveDataAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class)) + .withConfiguration(AutoConfigurations.of(AerospikeReactiveDataAutoConfiguration.class)) + .withPropertyValues("starters.aerospike.reactive=true"); @Test - public void aerospikeTemplateAndClientAreNotSetupWhenNeitherClientNorDataPropertiesConfigured() { - contextRunner.run(context -> { - assertThat(context).doesNotHaveBean(IAerospikeClient.class); - assertThat(context).doesNotHaveBean(AerospikeTemplate.class); - assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeDataProperties.class); - assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); - }); + public void aerospikeTemplateAndClientAreNotSetupWhenNoHostsPropertyGiven() { + assertThatThrownBy(() -> contextRunner.run(context -> context.getBean(AerospikeTemplate.class))) + .cause() + .hasMessageContaining("Required property 'spring.aerospike.hosts' is missing"); } @Test @@ -118,6 +116,8 @@ public void configurationIsApplied() { .run(context -> { assertThat(context).doesNotHaveBean(AerospikeTemplate.class); assertThat(context).hasSingleBean(ReactiveAerospikeTemplate.class); + assertThat(context).hasSingleBean(IAerospikeClient.class); + assertThat(context).hasSingleBean(IAerospikeReactorClient.class); assertThat(context).hasSingleBean(AerospikeProperties.class); assertThat(context).hasSingleBean(AerospikeDataProperties.class); assertThat(context).hasSingleBean(AerospikeMappingContext.class); diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfigurationTest.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java similarity index 68% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfigurationTest.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java index c8b037f..c0950e1 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfigurationTest.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import org.springframework.boot.aerospike.reactive.data.city.City; +import org.springframework.boot.aerospike.reactive.data.city.CityRepository; +import org.springframework.boot.aerospike.reactive.data.city.ReactiveCityRepository; +import org.springframework.boot.aerospike.reactive.data.empty.EmptyDataPackage; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; -import org.springframework.boot.autoconfigure.data.aerospike.city.CityRepository; -import org.springframework.boot.autoconfigure.data.aerospike.city.ReactiveCityRepository; -import org.springframework.boot.autoconfigure.data.aerospike.empty.EmptyDataPackage; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,10 +31,6 @@ import org.springframework.data.aerospike.mapping.AerospikeMappingContext; import org.springframework.data.mapping.context.MappingContext; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - /** * Tests for {@link AerospikeReactiveRepositoriesAutoConfiguration}. * @@ -42,15 +38,16 @@ */ public class AerospikeReactiveRepositoriesAutoConfigurationTest { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AerospikeReactiveRepositoriesAutoConfiguration.class, MockConfiguration.class)); + .withConfiguration(AutoConfigurations.of(AerospikeReactiveRepositoriesAutoConfiguration.class, + MockConfiguration.class)); @Test public void reactiveRepositoryIsCreated() { contextRunner .withUserConfiguration(DefaultConfiguration.class) .run(context -> { - assertThat(context).hasSingleBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).hasSingleBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -59,8 +56,8 @@ public void repositoryIsNotCreatedWhenRepositoryInterfaceNotExists() { contextRunner .withUserConfiguration(NoRepositoryConfiguration.class) .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -70,8 +67,8 @@ public void repositoryIsNotCreatedForTypeImperative() { .withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.aerospike.repositories.type=imperative") .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -81,8 +78,8 @@ public void repositoryIsNotCreatedForTypeNone() { .withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.aerospike.repositories.type=none") .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -104,14 +101,14 @@ static class MockConfiguration { public ReactiveAerospikeTemplate reactiveAerospikeTemplate() { AerospikeMappingContext context = new AerospikeMappingContext(); ReactiveAerospikeTemplate mock = Mockito.mock(ReactiveAerospikeTemplate.class); - when(mock.getMappingContext()).thenReturn((MappingContext) context); + Mockito.when(mock.getMappingContext()).thenReturn((MappingContext) context); return mock; } @Bean public MappingContext aerospikeMappingContext() { - return mock(MappingContext.class); + return Mockito.mock(MappingContext.class); } } diff --git a/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeTestConfigurations.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeTestConfigurations.java new file mode 100644 index 0000000..103df76 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeTestConfigurations.java @@ -0,0 +1,36 @@ +package org.springframework.boot.aerospike.reactive.data; + +import org.springframework.boot.aerospike.reactive.data.city.City; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.aerospike.convert.AerospikeCustomConverters; + +import java.util.List; + +public class AerospikeTestConfigurations { + + @AutoConfiguration + @EntityScan("org.springframework.boot.autoconfigure.data.aerospike.city") + public static class EntityScanConfiguration { + + } + + @AutoConfiguration + public static class CustomConversionsConfig { + + @Bean + AerospikeCustomConverters myCustomConversions() { + return new AerospikeCustomConverters(List.of(new CityToStringConverter())); + } + } + + public static class CityToStringConverter implements Converter { + + @Override + public String convert(City value) { + return value.getName(); + } + } +} diff --git a/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackage.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackage.java new file mode 100644 index 0000000..04afa6c --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackage.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.reactive.data; + +import org.springframework.boot.autoconfigure.AutoConfigurationPackages; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Test annotation to configure the {@link AutoConfigurationPackages} to an arbitrary + * value. + * + * @author Phillip Webb + * + * Copied from spring-boot project + * https://github.com/spring-projects/spring-boot/issues/6718 + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Import(TestAutoConfigurationPackageRegistrar.class) +public @interface TestAutoConfigurationPackage { + + Class value(); + +} diff --git a/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackageRegistrar.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackageRegistrar.java new file mode 100644 index 0000000..a0f1d71 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackageRegistrar.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.reactive.data; + +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.boot.autoconfigure.AutoConfigurationPackages; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.annotation.AnnotationAttributes; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.util.ClassUtils; + +/** + * {@link ImportBeanDefinitionRegistrar} to store the base package for tests. + * + * @author Phillip Webb + * + * Copied from spring-boot project + * https://github.com/spring-projects/spring-boot/issues/6718 + */ +public class TestAutoConfigurationPackageRegistrar implements ImportBeanDefinitionRegistrar { + + @Override + public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) { + AnnotationAttributes attributes = AnnotationAttributes + .fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true)); + AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value"))); + } + +} diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestUtils.java similarity index 85% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestUtils.java index 7b1e4fb..e88531f 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestUtils.java @@ -1,4 +1,4 @@ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.reactive.data; import org.springframework.util.ReflectionUtils; diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/City.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/City.java similarity index 92% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/City.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/City.java index 59d355b..bf83a34 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/City.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/City.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike.city; +package org.springframework.boot.aerospike.reactive.data.city; import org.springframework.data.aerospike.mapping.Document; import org.springframework.data.annotation.Id; diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/CityRepository.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/CityRepository.java similarity index 91% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/CityRepository.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/CityRepository.java index 918f4e6..0fe337b 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/CityRepository.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/CityRepository.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike.city; +package org.springframework.boot.aerospike.reactive.data.city; import org.springframework.data.repository.Repository; diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/ReactiveCityRepository.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/ReactiveCityRepository.java similarity index 92% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/ReactiveCityRepository.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/ReactiveCityRepository.java index 86f52a1..38fee4e 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/city/ReactiveCityRepository.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/city/ReactiveCityRepository.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike.city; +package org.springframework.boot.aerospike.reactive.data.city; import org.springframework.data.repository.Repository; import reactor.core.publisher.Mono; diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/empty/EmptyDataPackage.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/empty/EmptyDataPackage.java similarity index 91% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/empty/EmptyDataPackage.java rename to spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/empty/EmptyDataPackage.java index 3555442..d6304a8 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/empty/EmptyDataPackage.java +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/empty/EmptyDataPackage.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike.empty; +package org.springframework.boot.aerospike.reactive.data.empty; /** * Empty package used with data tests. diff --git a/spring-boot-starter-data-aerospike/pom.xml b/spring-boot-starter-data-aerospike/pom.xml index d17c5ec..aa1ea40 100644 --- a/spring-boot-starter-data-aerospike/pom.xml +++ b/spring-boot-starter-data-aerospike/pom.xml @@ -18,15 +18,27 @@ org.springframework.boot spring-boot-starter - + + com.aerospike + spring-boot-autoconfigure-aerospike-common + com.aerospike spring-data-aerospike - com.aerospike - spring-boot-autoconfigure-data-aerospike + spring-boot-starter-aerospike + + + org.projectlombok + lombok + provided + + + org.springframework.boot + spring-boot-starter-test + test \ No newline at end of file diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfiguration.java b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfiguration.java similarity index 70% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfiguration.java rename to spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfiguration.java index e1ae8f8..d17e41f 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfiguration.java +++ b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfiguration.java @@ -14,16 +14,18 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; import com.aerospike.client.IAerospikeClient; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.utils.HasNamespaceProperty; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.util.IsClientOnly; +import org.springframework.boot.autoconfigure.util.IsNotClientOnly; +import org.springframework.boot.client.autoconfigure.AerospikeClientConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Import; @@ -36,13 +38,19 @@ * @author Anastasiia Smirnova */ @AutoConfiguration -// match only if we do not have reactive client -// we want sync context to be loaded when only sync client is on classpath -@ConditionalOnMissingClass("com.aerospike.client.reactor.IAerospikeReactorClient") @ConditionalOnClass({IAerospikeClient.class, AerospikeRepository.class}) -@Conditional(HasNamespaceProperty.class) -@EnableConfigurationProperties(AerospikeDataProperties.class) @AutoConfigureAfter({AerospikeAutoConfiguration.class}) @Import(AerospikeDataConfiguration.class) public class AerospikeDataAutoConfiguration { + + @Conditional(IsNotClientOnly.class) + @EnableConfigurationProperties(AerospikeDataProperties.class) + static class DataConfigurationImport { + } + + @Conditional(IsClientOnly.class) + // Import client configuration if 'namespace' is missing + @Import(AerospikeClientConfiguration.class) + static class ClientConfigurationImport { + } } diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java similarity index 83% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java rename to spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java index 9c7ed8e..14b79bf 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java +++ b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java @@ -14,20 +14,23 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; import com.aerospike.client.Host; import com.aerospike.client.policy.ClientPolicy; +import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; import org.springframework.context.annotation.Configuration; import org.springframework.data.aerospike.config.AbstractAerospikeDataConfiguration; import org.springframework.data.aerospike.config.AerospikeDataSettings; import java.util.Collection; -import static org.springframework.boot.autoconfigure.utils.AerospikeConfigurationUtils.*; +import static org.springframework.boot.autoconfigure.util.AerospikeConfigurationUtils.*; /** * Configure Spring Data's Aerospike support. @@ -38,6 +41,7 @@ */ @Slf4j @Configuration +@AutoConfigureAfter({AerospikeDataAutoConfiguration.class}) public class AerospikeDataConfiguration extends AbstractAerospikeDataConfiguration { @Autowired diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfiguration.java b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfiguration.java similarity index 79% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfiguration.java rename to spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfiguration.java index 7945dc6..33395a8 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfiguration.java +++ b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfiguration.java @@ -14,28 +14,20 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; -import com.aerospike.client.Host; import com.aerospike.client.IAerospikeClient; -import org.springframework.beans.factory.annotation.Autowired; +import jakarta.annotation.PostConstruct; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.ConditionalOnRepositoryType; import org.springframework.boot.autoconfigure.data.RepositoryType; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; -import org.springframework.core.annotation.Order; -import org.springframework.data.aerospike.config.AbstractAerospikeDataConfiguration; import org.springframework.data.aerospike.repository.ReactiveAerospikeRepository; import org.springframework.data.aerospike.repository.support.AerospikeRepositoryFactoryBean; -import java.util.Arrays; -import java.util.Collection; - /** * {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Aerospike Repositories. * diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesRegistrar.java b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesRegistrar.java similarity index 96% rename from spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesRegistrar.java rename to spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesRegistrar.java index c0f1156..10f4871 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesRegistrar.java +++ b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesRegistrar.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; diff --git a/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring.factories b/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..7d668d7 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.boot.aerospike.data.AerospikeDataAutoConfiguration,\ +org.springframework.boot.aerospike.data.AerospikeRepositoriesAutoConfiguration diff --git a/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..0f606eb --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +org.springframework.boot.aerospike.data.AerospikeDataAutoConfiguration +org.springframework.boot.aerospike.data.AerospikeRepositoriesAutoConfiguration diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfigurationTest.java similarity index 85% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java rename to spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfigurationTest.java index e8ed9e9..56bf362 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeDataAutoConfigurationTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; import com.aerospike.client.AerospikeClient; import com.aerospike.client.IAerospikeClient; @@ -22,11 +22,11 @@ import com.aerospike.client.reactor.IAerospikeReactorClient; import com.aerospike.client.reactor.retry.AerospikeReactorRetryClient; import org.junit.jupiter.api.Test; +import org.springframework.boot.aerospike.data.city.City; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration; import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.EntityScanConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.data.aerospike.convert.AerospikeConverter; @@ -36,10 +36,9 @@ import org.springframework.data.aerospike.core.ReactiveAerospikeTemplate; import org.springframework.data.aerospike.mapping.AerospikeMappingContext; import org.springframework.data.util.TypeInformation; - import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.CustomConversionsConfig; -import static org.springframework.boot.autoconfigure.data.aerospike.TestUtils.getField; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.springframework.boot.aerospike.data.TestUtils.getField; /** * Tests for {@link AerospikeDataAutoConfiguration}. @@ -55,13 +54,10 @@ public class AerospikeDataAutoConfigurationTest { AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class)); @Test - public void aerospikeTemplateAndClientAreNotSetupWhenNeitherClientNorDataPropertiesConfigured() { - contextRunner.run(context -> { - assertThat(context).doesNotHaveBean(AerospikeClient.class); - assertThat(context).doesNotHaveBean(AerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeDataProperties.class); - assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); - }); + public void aerospikeTemplateAndClientAreNotSetupWhenNoHostsPropertyGiven() { + assertThatThrownBy(() -> contextRunner.run(context -> context.getBean(AerospikeTemplate.class))) + .cause() + .hasMessageContaining("Required property 'spring.aerospike.hosts' is missing"); } @Test @@ -69,7 +65,7 @@ public void entityScanShouldSetInitialEntitySet() { contextRunner .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(EntityScanConfiguration.class) + .withUserConfiguration(AerospikeTestConfigurations.EntityScanConfiguration.class) .run(context -> { AerospikeMappingContext mappingContext = context.getBean(AerospikeMappingContext.class); assertThat(mappingContext.getManagedTypes()).containsOnly(TypeInformation.of(City.class)); @@ -122,7 +118,7 @@ public void customConversions() { contextRunner .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(CustomConversionsConfig.class) + .withUserConfiguration(AerospikeTestConfigurations.CustomConversionsConfig.class) .run(context -> { MappingAerospikeConverter converter = context.getBean(MappingAerospikeConverter.class); assertThat(converter.getConversionService().canConvert(City.class, String.class)).isTrue(); @@ -156,6 +152,7 @@ public void configurationIsApplied() { .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") .run(context -> { + // In Spring Data Aerospike only the relevant flow beans are loaded (sync in this case) assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); assertThat(context).hasSingleBean(AerospikeTemplate.class); assertThat(context).hasSingleBean(AerospikeDataProperties.class); @@ -165,16 +162,16 @@ public void configurationIsApplied() { } @Test - public void dataConfigurationIsNotAppliedWithBothClients() { + public void dataConfigurationIsAppliedWithDifferentClients() { contextRunner .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") .withClassLoader(AerospikeReactorClient.class.getClassLoader()) .run(context -> { assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeTemplate.class); + assertThat(context).hasSingleBean(AerospikeTemplate.class); assertThat(context).hasSingleBean(AerospikeProperties.class); - assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); + assertThat(context).hasSingleBean(AerospikeMappingContext.class); }); contextRunner @@ -183,9 +180,9 @@ public void dataConfigurationIsNotAppliedWithBothClients() { .withClassLoader(AerospikeReactorRetryClient.class.getClassLoader()) .run(context -> { assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeTemplate.class); + assertThat(context).hasSingleBean(AerospikeTemplate.class); assertThat(context).hasSingleBean(AerospikeProperties.class); - assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); + assertThat(context).hasSingleBean(AerospikeMappingContext.class); }); } } diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java similarity index 66% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java rename to spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java index 78e50b9..4c684d5 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java @@ -14,15 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.boot.aerospike.data.city.ReactiveCityRepository; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; -import org.springframework.boot.autoconfigure.data.aerospike.city.CityRepository; -import org.springframework.boot.autoconfigure.data.aerospike.city.ReactiveCityRepository; -import org.springframework.boot.autoconfigure.data.aerospike.empty.EmptyDataPackage; +import org.springframework.boot.aerospike.data.city.City; +import org.springframework.boot.aerospike.data.city.CityRepository; +import org.springframework.boot.aerospike.data.empty.EmptyDataPackage; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -30,10 +31,6 @@ import org.springframework.data.aerospike.mapping.AerospikeMappingContext; import org.springframework.data.mapping.context.MappingContext; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - /** * Tests for {@link AerospikeRepositoriesAutoConfiguration}. * @@ -41,15 +38,16 @@ */ public class AerospikeRepositoriesAutoConfigurationTest { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AerospikeRepositoriesAutoConfiguration.class, MockConfiguration.class)); + .withConfiguration(AutoConfigurations.of(AerospikeRepositoriesAutoConfiguration.class, + MockConfiguration.class)); @Test public void repositoryIsCreated() { contextRunner .withUserConfiguration(DefaultConfiguration.class) .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).hasSingleBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).hasSingleBean(CityRepository.class); }); } @@ -58,8 +56,8 @@ public void repositoryIsNotCreatedWhenRepositoryInterfaceDoesNotExists() { contextRunner .withUserConfiguration(NoRepositoryConfiguration.class) .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -69,8 +67,8 @@ public void repositoryIsNotCreatedForTypeReactive() { .withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.aerospike.repositories.type=reactive") .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -80,8 +78,8 @@ public void repositoryIsNotCreatedForTypeNone() { .withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.aerospike.repositories.type=none") .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); }); } @@ -101,15 +99,14 @@ static class MockConfiguration { @Bean public AerospikeTemplate aerospikeTemplate() { AerospikeMappingContext context = new AerospikeMappingContext(); - AerospikeTemplate mock = mock(AerospikeTemplate.class); - when(mock.getMappingContext()).thenReturn((MappingContext) context); + AerospikeTemplate mock = Mockito.mock(AerospikeTemplate.class); + Mockito.when(mock.getMappingContext()).thenReturn((MappingContext) context); return mock; } @Bean public MappingContext aerospikeMappingContext() { - return mock(MappingContext.class); + return Mockito.mock(MappingContext.class); } } - } diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeTestConfigurations.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeTestConfigurations.java new file mode 100644 index 0000000..ad57f61 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeTestConfigurations.java @@ -0,0 +1,35 @@ +package org.springframework.boot.aerospike.data; + +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.aerospike.data.city.City; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.aerospike.convert.AerospikeCustomConverters; +import java.util.List; + +public class AerospikeTestConfigurations { + + @AutoConfiguration + @EntityScan("org.springframework.boot.autoconfigure.data.aerospike.city") + public static class EntityScanConfiguration { + + } + + @AutoConfiguration + public static class CustomConversionsConfig { + + @Bean + AerospikeCustomConverters myCustomConversions() { + return new AerospikeCustomConverters(List.of(new CityToStringConverter())); + } + } + + public static class CityToStringConverter implements Converter { + + @Override + public String convert(City value) { + return value.getName(); + } + } +} diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackage.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackage.java similarity index 90% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackage.java rename to spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackage.java index 5532d35..907d624 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackage.java +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackage.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.aerospike.data; +import org.springframework.boot.autoconfigure.AutoConfigurationPackages; import org.springframework.context.annotation.Import; import java.lang.annotation.*; diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackageRegistrar.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackageRegistrar.java similarity index 93% rename from spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackageRegistrar.java rename to spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackageRegistrar.java index c16fea8..e9a854c 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/TestAutoConfigurationPackageRegistrar.java +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestAutoConfigurationPackageRegistrar.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure; +package org.springframework.boot.aerospike.data; import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.boot.autoconfigure.AutoConfigurationPackages; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; @@ -38,5 +39,4 @@ public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionR .fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true)); AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value"))); } - } diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestUtils.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestUtils.java new file mode 100644 index 0000000..9889109 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/TestUtils.java @@ -0,0 +1,14 @@ +package org.springframework.boot.aerospike.data; + +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Field; + +public class TestUtils { + + public static T getField(Object object, String fieldName) { + Field typeKeyField = ReflectionUtils.findField(object.getClass(), fieldName); + typeKeyField.setAccessible(true); + return (T) ReflectionUtils.getField(typeKeyField, object); + } +} diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/City.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/City.java new file mode 100644 index 0000000..328400b --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/City.java @@ -0,0 +1,37 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.data.city; + +import org.springframework.data.aerospike.mapping.Document; +import org.springframework.data.annotation.Id; + +@Document +public class City { + + @Id + private String id; + + private String name; + + public String getId() { + return id; + } + + public String getName() { + return name; + } +} diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/CityRepository.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/CityRepository.java new file mode 100644 index 0000000..12638ec --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/CityRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.data.city; + +import org.springframework.data.repository.Repository; + +public interface CityRepository extends Repository { + +} diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/ReactiveCityRepository.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/ReactiveCityRepository.java new file mode 100644 index 0000000..cf086d6 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/city/ReactiveCityRepository.java @@ -0,0 +1,28 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.data.city; + +import org.springframework.data.repository.Repository; +import reactor.core.publisher.Mono; + +public interface ReactiveCityRepository extends Repository { + + Mono save(City city); + + Mono findById(Long id); + +} diff --git a/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/empty/EmptyDataPackage.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/empty/EmptyDataPackage.java new file mode 100644 index 0000000..3705666 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/empty/EmptyDataPackage.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.aerospike.data.empty; + +/** + * Empty package used with data tests. + * + * @author Phillip Webb + */ +public class EmptyDataPackage { + +} diff --git a/spring-boot-starter-data-aerospike-example/pom.xml b/spring-boot-starter-example-aerospike/pom.xml similarity index 84% rename from spring-boot-starter-data-aerospike-example/pom.xml rename to spring-boot-starter-example-aerospike/pom.xml index aeed54c..eb2e8b6 100644 --- a/spring-boot-starter-data-aerospike-example/pom.xml +++ b/spring-boot-starter-example-aerospike/pom.xml @@ -9,15 +9,14 @@ ${revision} - pom - Spring Data Aerospike Starters: spring-boot-starter-data-aerospike-example - spring-boot-starter-data-aerospike-example - Example for using Spring Boot Data Aerospike Starter + Spring Data Aerospike Starters: spring-boot-starter-example-aerospike + spring-boot-starter-example-aerospike + Examples for using Spring Boot Data Aerospike Starter - reactive - sync + sync-data + reactive-data @@ -30,7 +29,6 @@ lombok provided - org.springframework.cloud diff --git a/spring-boot-starter-example-aerospike/reactive-client/pom.xml b/spring-boot-starter-example-aerospike/reactive-client/pom.xml new file mode 100644 index 0000000..08b25c9 --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-client/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + spring-boot-starter-example-aerospike + com.aerospike + ${revision} + + + Spring Data Aerospike Starters: spring-boot-starter-example-aerospike, reactive client + reactive-client + + + + org.springframework.boot + spring-boot-starter-webflux + + + com.aerospike + spring-boot-starter-aerospike-reactive + + + + \ No newline at end of file diff --git a/spring-boot-starter-example-aerospike/reactive-client/src/main/java/com/aerospike/example/client/reactive/SpringReactorAerospikeClientExampleApplication.java b/spring-boot-starter-example-aerospike/reactive-client/src/main/java/com/aerospike/example/client/reactive/SpringReactorAerospikeClientExampleApplication.java new file mode 100644 index 0000000..da0490e --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-client/src/main/java/com/aerospike/example/client/reactive/SpringReactorAerospikeClientExampleApplication.java @@ -0,0 +1,13 @@ +package com.aerospike.example.client.reactive; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringReactorAerospikeClientExampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringReactorAerospikeClientExampleApplication.class, args); + } + +} diff --git a/spring-boot-starter-example-aerospike/reactive-client/src/main/resources/application.properties b/spring-boot-starter-example-aerospike/reactive-client/src/main/resources/application.properties new file mode 100644 index 0000000..e4e9f72 --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-client/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.aerospike.hosts=${embedded.aerospike.host}:${embedded.aerospike.port} \ No newline at end of file diff --git a/spring-boot-starter-example-aerospike/reactive-client/src/test/java/com/aerospike/example/client/reactive/ReactiveClientTest.java b/spring-boot-starter-example-aerospike/reactive-client/src/test/java/com/aerospike/example/client/reactive/ReactiveClientTest.java new file mode 100644 index 0000000..3f216ba --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-client/src/test/java/com/aerospike/example/client/reactive/ReactiveClientTest.java @@ -0,0 +1,24 @@ +package com.aerospike.example.client.reactive; + +import com.aerospike.client.reactor.AerospikeReactorClient; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class ReactiveClientTest { + + @Autowired + AerospikeReactorClient reactorClient; + + @Test + void contextLoads() { + } + + @Test + void reactorClientExists() { + assertThat(reactorClient.getReadPolicyDefault()).isNotNull(); + } +} diff --git a/spring-boot-starter-data-aerospike-example/reactive/pom.xml b/spring-boot-starter-example-aerospike/reactive-data/pom.xml similarity index 78% rename from spring-boot-starter-data-aerospike-example/reactive/pom.xml rename to spring-boot-starter-example-aerospike/reactive-data/pom.xml index ef0f7cf..d23fafe 100644 --- a/spring-boot-starter-data-aerospike-example/reactive/pom.xml +++ b/spring-boot-starter-example-aerospike/reactive-data/pom.xml @@ -2,15 +2,16 @@ + 4.0.0 + - spring-boot-starter-data-aerospike-example + spring-boot-starter-example-aerospike com.aerospike ${revision} - 4.0.0 - Spring Data Aerospike Starters: spring-boot-starter-data-aerospike-example, reactive - reactive + Spring Data Aerospike Starters: spring-boot-starter-example-aerospike, reactive + reactive-data @@ -23,5 +24,4 @@ - \ No newline at end of file diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/Customer.java b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/Customer.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/Customer.java rename to spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/Customer.java diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java similarity index 99% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java rename to spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java index 73a9aba..fbf0063 100644 --- a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java +++ b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveCustomerController.java @@ -88,5 +88,4 @@ public Flux deleteCustomers() { .flatMap(customer -> repository.deleteById(customer.getId())) .doOnComplete(() -> log.info("Deleted all customers")); } - } diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveCustomerRepository.java b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveCustomerRepository.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveCustomerRepository.java rename to spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveCustomerRepository.java diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java similarity index 99% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java rename to spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java index 8d0d2ad..b11b085 100644 --- a/spring-boot-starter-data-aerospike-example/reactive/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java +++ b/spring-boot-starter-example-aerospike/reactive-data/src/main/java/com/aerospike/example/reactive/ReactiveSpringDataAerospikeExampleApplication.java @@ -9,5 +9,4 @@ public class ReactiveSpringDataAerospikeExampleApplication { public static void main(String[] args) { SpringApplication.run(ReactiveSpringDataAerospikeExampleApplication.class, args); } - } diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/resources/application.properties b/spring-boot-starter-example-aerospike/reactive-data/src/main/resources/application.properties similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/resources/application.properties rename to spring-boot-starter-example-aerospike/reactive-data/src/main/resources/application.properties diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/reactive-data/src/main/resources/bootstrap.properties similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/main/resources/bootstrap.properties rename to spring-boot-starter-example-aerospike/reactive-data/src/main/resources/bootstrap.properties diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/test/java/com/aerospike/example/reactive/ReactiveIntegrationTest.java b/spring-boot-starter-example-aerospike/reactive-data/src/test/java/com/aerospike/example/reactive/ReactiveIntegrationTest.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/test/java/com/aerospike/example/reactive/ReactiveIntegrationTest.java rename to spring-boot-starter-example-aerospike/reactive-data/src/test/java/com/aerospike/example/reactive/ReactiveIntegrationTest.java diff --git a/spring-boot-starter-data-aerospike-example/reactive/src/test/resources/logback-test.xml b/spring-boot-starter-example-aerospike/reactive-data/src/test/resources/logback-test.xml similarity index 100% rename from spring-boot-starter-data-aerospike-example/reactive/src/test/resources/logback-test.xml rename to spring-boot-starter-example-aerospike/reactive-data/src/test/resources/logback-test.xml diff --git a/spring-boot-starter-example-aerospike/sync-client/pom.xml b/spring-boot-starter-example-aerospike/sync-client/pom.xml new file mode 100644 index 0000000..279c6f1 --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-client/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + + spring-boot-starter-example-aerospike + com.aerospike + ${revision} + + + Spring Data Aerospike Starters: spring-boot-starter-aerospike-example, sync client + sync-client + + + + org.springframework.boot + spring-boot-starter-web + + + com.aerospike + spring-boot-starter-aerospike + + + + \ No newline at end of file diff --git a/spring-boot-starter-example-aerospike/sync-client/src/main/java/com/aerospike/example/client/sync/SpringSyncAerospikeClientExampleApplication.java b/spring-boot-starter-example-aerospike/sync-client/src/main/java/com/aerospike/example/client/sync/SpringSyncAerospikeClientExampleApplication.java new file mode 100644 index 0000000..eaa175b --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-client/src/main/java/com/aerospike/example/client/sync/SpringSyncAerospikeClientExampleApplication.java @@ -0,0 +1,13 @@ +package com.aerospike.example.client.sync; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringSyncAerospikeClientExampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSyncAerospikeClientExampleApplication.class, args); + } + +} diff --git a/spring-boot-starter-example-aerospike/sync-client/src/main/resources/application.properties b/spring-boot-starter-example-aerospike/sync-client/src/main/resources/application.properties new file mode 100644 index 0000000..e4e9f72 --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-client/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.aerospike.hosts=${embedded.aerospike.host}:${embedded.aerospike.port} \ No newline at end of file diff --git a/spring-boot-starter-example-aerospike/sync-client/src/test/java/com/aerospike/example/client/sync/SyncClientTest.java b/spring-boot-starter-example-aerospike/sync-client/src/test/java/com/aerospike/example/client/sync/SyncClientTest.java new file mode 100644 index 0000000..b93abcf --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-client/src/test/java/com/aerospike/example/client/sync/SyncClientTest.java @@ -0,0 +1,24 @@ +package com.aerospike.example.client.sync; + +import com.aerospike.client.AerospikeClient; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class SyncClientTest { + + @Autowired + AerospikeClient client; + + @Test + void contextLoads() { + } + + @Test + void syncClientExists() { + assertThat(client.getReadPolicyDefault()).isNotNull(); + } +} diff --git a/spring-boot-starter-data-aerospike-example/sync/pom.xml b/spring-boot-starter-example-aerospike/sync-data/pom.xml similarity index 78% rename from spring-boot-starter-data-aerospike-example/sync/pom.xml rename to spring-boot-starter-example-aerospike/sync-data/pom.xml index b8a0cd0..80bccfb 100644 --- a/spring-boot-starter-data-aerospike-example/sync/pom.xml +++ b/spring-boot-starter-example-aerospike/sync-data/pom.xml @@ -2,15 +2,15 @@ + 4.0.0 - spring-boot-starter-data-aerospike-example + spring-boot-starter-example-aerospike com.aerospike ${revision} - 4.0.0 - Spring Data Aerospike Starters: spring-boot-starter-data-aerospike-example, sync - sync + Spring Data Aerospike Starters: spring-boot-starter-example-aerospike, sync + sync-data @@ -22,6 +22,4 @@ spring-boot-starter-data-aerospike - - \ No newline at end of file diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/Customer.java b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/Customer.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/Customer.java rename to spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/Customer.java diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncCustomerController.java b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncCustomerController.java similarity index 99% rename from spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncCustomerController.java rename to spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncCustomerController.java index 10bf875..e15fe1c 100644 --- a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncCustomerController.java +++ b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncCustomerController.java @@ -87,5 +87,4 @@ public List getAllCustomersByLastName(@RequestParam(value = "lastName" log.info("Retrieved all customers with last name " + lastName); return result; } - } diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncCustomerRepository.java b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncCustomerRepository.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncCustomerRepository.java rename to spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncCustomerRepository.java diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java similarity index 99% rename from spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java rename to spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java index e577875..9880e4b 100644 --- a/spring-boot-starter-data-aerospike-example/sync/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java +++ b/spring-boot-starter-example-aerospike/sync-data/src/main/java/com/aerospike/example/sync/SyncSpringDataAerospikeExampleApplication.java @@ -9,5 +9,4 @@ public class SyncSpringDataAerospikeExampleApplication { public static void main(String[] args) { SpringApplication.run(SyncSpringDataAerospikeExampleApplication.class, args); } - } diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/resources/application.properties b/spring-boot-starter-example-aerospike/sync-data/src/main/resources/application.properties similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/main/resources/application.properties rename to spring-boot-starter-example-aerospike/sync-data/src/main/resources/application.properties diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/sync-data/src/main/resources/bootstrap.properties similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/main/resources/bootstrap.properties rename to spring-boot-starter-example-aerospike/sync-data/src/main/resources/bootstrap.properties diff --git a/spring-boot-starter-data-aerospike-example/sync/src/test/java/com/aerospike/example/sync/SyncIntegrationTest.java b/spring-boot-starter-example-aerospike/sync-data/src/test/java/com/aerospike/example/sync/SyncIntegrationTest.java similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/test/java/com/aerospike/example/sync/SyncIntegrationTest.java rename to spring-boot-starter-example-aerospike/sync-data/src/test/java/com/aerospike/example/sync/SyncIntegrationTest.java diff --git a/spring-boot-starter-data-aerospike-example/sync/src/test/resources/logback-test.xml b/spring-boot-starter-example-aerospike/sync-data/src/test/resources/logback-test.xml similarity index 100% rename from spring-boot-starter-data-aerospike-example/sync/src/test/resources/logback-test.xml rename to spring-boot-starter-example-aerospike/sync-data/src/test/resources/logback-test.xml