diff --git a/README.adoc b/README.adoc index f0ff7e6..5829ab9 100644 --- a/README.adoc +++ b/README.adoc @@ -9,6 +9,11 @@ image:https://github.com/aerospike-community/spring-data-aerospike-starters/work |=== |`spring-data-aerospike-starters` |`spring-data-aerospike` |`aerospike-client` |`aerospike-reactor-client` +|0.17.x +|5.0.x +|7.2.x +|7.1.x + |0.15.x, 0.16.x |4.8.x |7.2.x @@ -108,11 +113,11 @@ spring.data.aerospike.repositories.type=NONE == Example -You can find usage example in {repo-master}/spring-boot-starter-data-aerospike-example[_spring-boot-starter-data-aerospike-example_] module. +You can find usage example in {repo-master}/spring-boot-starter-example-aerospike[_spring-boot-starter-example-aerospike_] module. -Both reactive and sync examples are based on `embedded-aerospike` dependency usage (which requires docker to be running on the machine). This is the only requirement to be able to run the tests on your machine. +Both reactive and sync examples are based on `embedded-aerospike` dependency usage (which requires Docker to be running on the machine). This is the only requirement to be able to run the tests on your machine. -If you want to run the tests in these modules against your Aerospike instance follow the steps: +If you want to run the tests in these modules against your Aerospike instance follow these steps: -. Update `application.properties` file with the required Aerospike settings (host, port, namespace). This will point spring-data to your Aerospike instance. -. Update with `bootstrap.properties` file with `embedded.containers.enabled=false`. This will disable setup of embedded Aerospike. +. Update `application.properties` file with the required Aerospike settings (hosts, namespace). This will point spring-data to your Aerospike instance. +. Update `bootstrap.properties` file with `embedded.containers.enabled=false`. This will disable setup of embedded Aerospike. 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 70% rename from spring-boot-autoconfigure-data-aerospike/pom.xml rename to spring-boot-autoconfigure-aerospike-common/pom.xml index d15d712..c115de0 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,11 +38,30 @@ spring-boot-configuration-processor true - org.springframework.boot spring-boot-starter-test test + + + + + org.apache.maven.plugins + maven-deploy-plugin + 3.1.3 + + + + deploy + + + false + + + + + + \ No newline at end of file diff --git a/spring-boot-autoconfigure-aerospike-common/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 new file mode 100644 index 0000000..6a36fb2 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/aerospike/AerospikeAutoConfiguration.java @@ -0,0 +1,48 @@ +/* + * 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.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.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.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. + * + * @author Anastasiia Smirnova + */ +@AutoConfiguration +@ConditionalOnClass(IAerospikeClient.class) +@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 96% 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 620f4ab..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 { /** @@ -157,7 +158,7 @@ public abstract static class PolicyDefault { public Duration sleepBetweenRetries; /** - * If the key is sent on a write, the key will be stored with the record on the server. + * If the key is sent in a write operation, it will be stored with the record on the server. */ public Boolean sendKey; } diff --git a/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/IsClientOnly.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/IsClientOnly.java new file mode 100644 index 0000000..2d155ce --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/IsClientOnly.java @@ -0,0 +1,20 @@ +package org.springframework.boot.autoconfigure.condition; + +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/condition/IsNotClientOnly.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/IsNotClientOnly.java new file mode 100644 index 0000000..db959d7 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/IsNotClientOnly.java @@ -0,0 +1,22 @@ +package org.springframework.boot.autoconfigure.condition; + +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/condition/ValidateHostsProperty.java b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/ValidateHostsProperty.java new file mode 100644 index 0000000..6092e68 --- /dev/null +++ b/spring-boot-autoconfigure-aerospike-common/src/main/java/org/springframework/boot/autoconfigure/condition/ValidateHostsProperty.java @@ -0,0 +1,24 @@ +package org.springframework.boot.autoconfigure.condition; + +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-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 94% 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 index a1974f0..7564e2d 100644 --- 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 @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.data.aerospike.config.AerospikeDataSettings; /** * Configuration properties for Spring Data Aerospike. @@ -38,12 +37,12 @@ public class AerospikeDataProperties { private String namespace; /** - * Bin name that will be used for storing entity's type. + * Bin name that will be used for storing entity's type. Default value is null *

* * @see org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor */ - private String typeKey = "@_class"; + private String classKey = "@_class"; /** * Gives ability to disable queries that will run scan on Aerospike server. 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/util/AerospikeConfigurationUtils.java similarity index 53% 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/util/AerospikeConfigurationUtils.java index 969d4c1..72d6357 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/util/AerospikeConfigurationUtils.java @@ -1,65 +1,34 @@ -/* - * 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.autoconfigure.aerospike; - -import com.aerospike.client.AerospikeClient; +package org.springframework.boot.autoconfigure.util; + import com.aerospike.client.Host; -import com.aerospike.client.IAerospikeClient; -import com.aerospike.client.async.EventLoops; -import com.aerospike.client.async.NioEventLoops; -import com.aerospike.client.policy.*; -import com.aerospike.client.reactor.AerospikeReactorClient; -import com.aerospike.client.reactor.IAerospikeReactorClient; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import reactor.core.publisher.Flux; - -import java.util.Optional; +import com.aerospike.client.policy.BatchDeletePolicy; +import com.aerospike.client.policy.BatchPolicy; +import com.aerospike.client.policy.BatchUDFPolicy; +import com.aerospike.client.policy.BatchWritePolicy; +import com.aerospike.client.policy.ClientPolicy; +import com.aerospike.client.policy.Policy; +import com.aerospike.client.policy.QueryPolicy; +import com.aerospike.client.policy.WritePolicy; +import org.springframework.boot.autoconfigure.aerospike.AerospikeProperties; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.data.aerospike.config.AerospikeDataSettings; + +import java.util.Arrays; +import java.util.Collection; import java.util.function.Consumer; -/** - * {@link EnableAutoConfiguration Auto-configuration} for Aerospike client. - * - * @author Anastasiia Smirnova - */ -@AutoConfiguration -@ConditionalOnClass(IAerospikeClient.class) -@ConditionalOnProperty("spring.aerospike.hosts") -@EnableConfigurationProperties(AerospikeProperties.class) -public class AerospikeAutoConfiguration { - - @Bean(name = "aerospikeClient", destroyMethod = "close") - @ConditionalOnMissingBean(IAerospikeClient.class) - public IAerospikeClient aerospikeClient(AerospikeProperties properties, - ClientPolicy aerospikeClientPolicy) { - Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort()); - return new AerospikeClient(aerospikeClientPolicy, hosts); +public class AerospikeConfigurationUtils { + + public static Collection getClientHosts(AerospikeProperties properties) { + if (properties.getHosts() != null) { + Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort()); + return Arrays.stream(hosts).toList(); + } else { + return null; + } } - @Bean(name = "aerospikeClientPolicy") - @ConditionalOnMissingBean - public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties, - Optional aerospikeEventLoops) { - ClientPolicy clientPolicy = new ClientPolicy(); + public static ClientPolicy getClientPolicyConfig(ClientPolicy clientPolicy, AerospikeProperties properties) { whenPresent(properties.getUser(), p -> clientPolicy.user = p); whenPresent(properties.getPassword(), p -> clientPolicy.password = p); whenPresent(properties.getClusterName(), p -> clientPolicy.clusterName = p); @@ -80,30 +49,10 @@ public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties, clientPolicy.batchWritePolicyDefault = setupBatchWritePolicy(properties); clientPolicy.batchDeletePolicyDefault = setupBatchDeletePolicy(properties); clientPolicy.batchUDFPolicyDefault = setupBatchUDFPolicy(properties); - aerospikeEventLoops.ifPresent(loops -> clientPolicy.eventLoops = loops); - return clientPolicy; } - @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, - EventLoops eventLoops) { - return new AerospikeReactorClient(aerospikeClient, eventLoops); - } - - @Bean(name = "aerospikeEventLoops", destroyMethod = "close") - @ConditionalOnMissingBean - public EventLoops aerospikeEventLoops() { - return new NioEventLoops(); - } - } - - private WritePolicy setupWritePolicy(AerospikeProperties properties) { + private static WritePolicy setupWritePolicy(AerospikeProperties properties) { AerospikeProperties.WritePolicyDefault writePolicyDefault = properties.getWrite(); WritePolicy policy = new WritePolicy(); setGeneralPolicyProperties(policy, writePolicyDefault); @@ -111,14 +60,14 @@ private WritePolicy setupWritePolicy(AerospikeProperties properties) { return policy; } - private Policy setupReadPolicy(AerospikeProperties properties) { + private static Policy setupReadPolicy(AerospikeProperties properties) { AerospikeProperties.ReadPolicyDefault readPolicyDefault = properties.getRead(); Policy policy = new Policy(); setGeneralPolicyProperties(policy, readPolicyDefault); return policy; } - private BatchPolicy setupBatchPolicy(AerospikeProperties properties) { + private static BatchPolicy setupBatchPolicy(AerospikeProperties properties) { AerospikeProperties.BatchPolicyDefault batchPolicyDefault = properties.getBatch(); BatchPolicy policy = new BatchPolicy(); setGeneralPolicyProperties(policy, batchPolicyDefault); @@ -128,28 +77,28 @@ private BatchPolicy setupBatchPolicy(AerospikeProperties properties) { return policy; } - private BatchWritePolicy setupBatchWritePolicy(AerospikeProperties properties) { + private static BatchWritePolicy setupBatchWritePolicy(AerospikeProperties properties) { AerospikeProperties.BatchWritePolicyDefault batchWritePolicyDefault = properties.getBatchWrite(); BatchWritePolicy policy = new BatchWritePolicy(); whenPresent(batchWritePolicyDefault.durableDelete, p -> policy.durableDelete = p); return policy; } - private BatchDeletePolicy setupBatchDeletePolicy(AerospikeProperties properties) { + private static BatchDeletePolicy setupBatchDeletePolicy(AerospikeProperties properties) { AerospikeProperties.BatchDeletePolicyDefault batchDeletePolicyDefault = properties.getBatchDelete(); BatchDeletePolicy policy = new BatchDeletePolicy(); whenPresent(batchDeletePolicyDefault.durableDelete, p -> policy.durableDelete = p); return policy; } - private BatchUDFPolicy setupBatchUDFPolicy(AerospikeProperties properties) { + private static BatchUDFPolicy setupBatchUDFPolicy(AerospikeProperties properties) { AerospikeProperties.BatchUDFPolicyDefault batchUDFPolicyDefault = properties.getBatchUdf(); BatchUDFPolicy policy = new BatchUDFPolicy(); whenPresent(batchUDFPolicyDefault.durableDelete, p -> policy.durableDelete = p); return policy; } - private QueryPolicy setupQueryPolicy(AerospikeProperties properties) { + private static QueryPolicy setupQueryPolicy(AerospikeProperties properties) { AerospikeProperties.QueryPolicyDefault queryPolicyDefault = properties.getQuery(); QueryPolicy policy = new QueryPolicy(); setGeneralPolicyProperties(policy, queryPolicyDefault); @@ -161,7 +110,7 @@ private QueryPolicy setupQueryPolicy(AerospikeProperties properties) { return policy; } - private void setGeneralPolicyProperties(Policy policy, AerospikeProperties.PolicyDefault policyDefault) { + private static void setGeneralPolicyProperties(Policy policy, AerospikeProperties.PolicyDefault policyDefault) { whenPresent(policyDefault.socketTimeout, p -> policy.socketTimeout = (int) p.toMillis()); whenPresent(policyDefault.totalTimeout, p -> policy.totalTimeout = (int) p.toMillis()); whenPresent(policyDefault.timeoutDelay, p -> policy.timeoutDelay = (int) p.toMillis()); @@ -170,8 +119,27 @@ private void setGeneralPolicyProperties(Policy policy, AerospikeProperties.Polic whenPresent(policyDefault.sendKey, p -> policy.sendKey = p); } - private void whenPresent(T param, Consumer consumer) { + private static void whenPresent(T param, Consumer consumer) { if (param != null) 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) { + whenPresent(dataProperties.isScansEnabled(), aerospikeDataSettings::setScansEnabled); + whenPresent(dataProperties.isCreateIndexesOnStartup(), aerospikeDataSettings::setCreateIndexesOnStartup); + whenPresent(dataProperties.getIndexCacheRefreshSeconds(), aerospikeDataSettings::setIndexCacheRefreshSeconds); + whenPresent(dataProperties.getServerVersionRefreshSeconds(), aerospikeDataSettings::setServerVersionRefreshSeconds); + whenPresent(dataProperties.getQueryMaxRecords(), aerospikeDataSettings::setQueryMaxRecords); + whenPresent(dataProperties.getBatchWriteSize(), aerospikeDataSettings::setBatchWriteSize); + whenPresent(dataProperties.isKeepOriginalKeyTypes(), aerospikeDataSettings::setKeepOriginalKeyTypes); + } } 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/data/aerospike/AerospikeCommonDataConfiguration.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java deleted file mode 100644 index a23bacf..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.springframework.boot.autoconfigure.data.aerospike; - -import com.aerospike.client.IAerospikeClient; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeanUtils; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.domain.EntityScanner; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.data.aerospike.config.AerospikeConnectionSettings; -import org.springframework.data.aerospike.config.AerospikeDataSettings; -import org.springframework.data.aerospike.config.AerospikeSettings; -import org.springframework.data.aerospike.convert.AerospikeCustomConversions; -import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; -import org.springframework.data.aerospike.convert.MappingAerospikeConverter; -import org.springframework.data.aerospike.core.AerospikeExceptionTranslator; -import org.springframework.data.aerospike.core.DefaultAerospikeExceptionTranslator; -import org.springframework.data.aerospike.index.AerospikeIndexResolver; -import org.springframework.data.aerospike.mapping.AerospikeMappingContext; -import org.springframework.data.aerospike.mapping.Document; -import org.springframework.data.aerospike.query.FilterExpressionsBuilder; -import org.springframework.data.aerospike.query.StatementBuilder; -import org.springframework.data.aerospike.query.cache.IndexesCache; -import org.springframework.data.aerospike.query.cache.IndexesCacheHolder; -import org.springframework.data.aerospike.server.version.ServerVersionSupport; -import org.springframework.data.annotation.Persistent; -import org.springframework.data.mapping.model.FieldNamingStrategy; - -import java.util.Collections; - -@Slf4j -@AutoConfiguration -class AerospikeCommonDataConfiguration { - - @Bean(name = "aerospikeServerVersionSupport") - @ConditionalOnMissingBean(ServerVersionSupport.class) - public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient, - AerospikeDataProperties properties) { - ServerVersionSupport serverVersionSupport = new ServerVersionSupport(aerospikeClient); - processServerVersionRefreshFrequency(properties.getServerVersionRefreshSeconds(), serverVersionSupport); - return serverVersionSupport; - } - - private void processServerVersionRefreshFrequency(int serverVersionRefreshSeconds, - ServerVersionSupport serverVersionSupport) { - if (serverVersionRefreshSeconds > 0) { - serverVersionSupport.scheduleServerVersionRefresh(serverVersionRefreshSeconds); - } - } - - @Bean(name = "aerospikeFilterExpressionsBuilder") - @ConditionalOnMissingBean(name = "aerospikeFilterExpressionsBuilder") - public FilterExpressionsBuilder aerospikeFilterExpressionsBuilder() { - return new FilterExpressionsBuilder(); - } - - @Bean(name = "aerospikeStatementBuilder") - @ConditionalOnMissingBean(name = "aerospikeStatementBuilder") - public StatementBuilder aerospikeStatementBuilder(IndexesCache indexesCache) { - return new StatementBuilder(indexesCache); - } - - @Bean(name = "aerospikeIndexResolver") - @ConditionalOnMissingBean(name = "aerospikeIndexResolver") - public AerospikeIndexResolver aerospikeIndexResolver() { - return new AerospikeIndexResolver(); - } - - @Bean(name = "aerospikeIndexCache") - @ConditionalOnMissingBean(name = "aerospikeIndexCache") - public IndexesCacheHolder aerospikeIndexCache() { - return new IndexesCacheHolder(); - } - - @Bean(name = "mappingAerospikeConverter") - @ConditionalOnMissingBean(name = "mappingAerospikeConverter") - public MappingAerospikeConverter mappingAerospikeConverter(AerospikeMappingContext aerospikeMappingContext, - AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor, - AerospikeCustomConversions aerospikeCustomConversions, - AerospikeDataProperties aerospikeDataProperties, - AerospikeDataSettings dataSettings) { - return new MappingAerospikeConverter(aerospikeMappingContext, aerospikeCustomConversions, - aerospikeTypeAliasAccessor, aerospikeDataSettings(aerospikeDataProperties, dataSettings)); - } - - @Bean(name = "aerospikeTypeAliasAccessor") - @ConditionalOnMissingBean(name = "aerospikeTypeAliasAccessor") - public AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor(AerospikeDataProperties aerospikeDataProperties) { - String typeKey = aerospikeDataProperties.getTypeKey(); - return new AerospikeTypeAliasAccessor(typeKey != null && typeKey.equals("") ? null : typeKey); - } - - @Bean(name = "aerospikeCustomConversions") - @ConditionalOnMissingBean(name = "aerospikeCustomConversions") - public AerospikeCustomConversions aerospikeCustomConversions() { - return new AerospikeCustomConversions(Collections.emptyList()); - } - - @Bean(name = "aerospikeMappingContext") - @ConditionalOnMissingBean(name = "aerospikeMappingContext") - public AerospikeMappingContext aerospikeMappingContext(ApplicationContext applicationContext, - AerospikeCustomConversions aerospikeCustomConversions, - AerospikeDataProperties aerospikeDataProperties) - throws Exception { - AerospikeMappingContext context = new AerospikeMappingContext(); - context.setInitialEntitySet(new EntityScanner(applicationContext).scan(Document.class, Persistent.class)); - context.setSimpleTypeHolder(aerospikeCustomConversions.getSimpleTypeHolder()); - Class fieldNamingStrategy = aerospikeDataProperties.getFieldNamingStrategy(); - if (fieldNamingStrategy != null) { - context.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils.instantiateClass(fieldNamingStrategy)); - } - return context; - } - - @Bean(name = "aerospikeExceptionTranslator") - @ConditionalOnMissingBean(name = "aerospikeExceptionTranslator") - public AerospikeExceptionTranslator aerospikeExceptionTranslator() { - return new DefaultAerospikeExceptionTranslator(); - } - - @Bean - public AerospikeDataSettings readAerospikeDataSettings() { - return new AerospikeDataSettings(); - } - - @Bean - public AerospikeConnectionSettings readAerospikeSettings() { - return new AerospikeConnectionSettings(); - } - - @Bean - public AerospikeSettings aerospikeSettings(AerospikeDataSettings dataSettings, - AerospikeConnectionSettings connectionSettings) { - return new AerospikeSettings(connectionSettings, dataSettings); - } - - private AerospikeDataSettings aerospikeDataSettings(AerospikeDataProperties aerospikeDataProperties, - AerospikeDataSettings dataSettings) { - return configureDataSettings(dataSettings, aerospikeDataProperties); - } - - private AerospikeDataSettings configureDataSettings(AerospikeDataSettings dataSettings, - AerospikeDataProperties aerospikeDataProperties) { - dataSettings.setScansEnabled(aerospikeDataProperties.isScansEnabled()); - dataSettings.setCreateIndexesOnStartup(aerospikeDataProperties.isCreateIndexesOnStartup()); - dataSettings.setWriteSortedMaps(aerospikeDataProperties.isWriteSortedMaps()); - return dataSettings; - } -} diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java deleted file mode 100644 index 6e32cd1..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataConfiguration.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.autoconfigure.data.aerospike; - -import com.aerospike.client.IAerospikeClient; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Lazy; -import org.springframework.data.aerospike.config.AerospikeDataSettings; -import org.springframework.data.aerospike.config.AerospikeSettings; -import org.springframework.data.aerospike.convert.MappingAerospikeConverter; -import org.springframework.data.aerospike.core.AerospikeExceptionTranslator; -import org.springframework.data.aerospike.core.AerospikeTemplate; -import org.springframework.data.aerospike.index.AerospikeIndexResolver; -import org.springframework.data.aerospike.index.AerospikePersistenceEntityIndexCreator; -import org.springframework.data.aerospike.mapping.AerospikeMappingContext; -import org.springframework.data.aerospike.query.FilterExpressionsBuilder; -import org.springframework.data.aerospike.query.QueryEngine; -import org.springframework.data.aerospike.query.StatementBuilder; -import org.springframework.data.aerospike.query.cache.IndexInfoParser; -import org.springframework.data.aerospike.query.cache.IndexRefresher; -import org.springframework.data.aerospike.query.cache.IndexesCacheUpdater; -import org.springframework.data.aerospike.query.cache.InternalIndexOperations; -import org.springframework.data.aerospike.server.version.ServerVersionSupport; - -/** - * Configure Spring Data's Aerospike support. - * - * @author Igor Ermolenko - * @author Anastasiia Smirnova - */ -@Slf4j -@AutoConfiguration -class AerospikeDataConfiguration { - - @Bean(name = "aerospikeTemplate") - @ConditionalOnMissingBean(name = "aerospikeTemplate") - public AerospikeTemplate aerospikeTemplate(IAerospikeClient aerospikeClient, - AerospikeDataProperties aerospikeDataProperties, - MappingAerospikeConverter mappingAerospikeConverter, - AerospikeMappingContext aerospikeMappingContext, - AerospikeExceptionTranslator aerospikeExceptionTranslator, - QueryEngine queryEngine, IndexRefresher indexRefresher, - ServerVersionSupport serverVersionSupport) { - return new AerospikeTemplate(aerospikeClient, - aerospikeDataProperties.getNamespace(), - mappingAerospikeConverter, - aerospikeMappingContext, - aerospikeExceptionTranslator, queryEngine, indexRefresher, - serverVersionSupport); - } - - @Bean(name = "aerospikeQueryEngine") - @ConditionalOnMissingBean(name = "aerospikeQueryEngine") - public QueryEngine aerospikeQueryEngine(IAerospikeClient aerospikeClient, - AerospikeDataProperties aerospikeDataProperties, - FilterExpressionsBuilder filterExpressionsBuilder, - StatementBuilder statementBuilder, AerospikeSettings settings) { - QueryEngine queryEngine = new QueryEngine(aerospikeClient, statementBuilder, filterExpressionsBuilder, - settings.getDataSettings()); - queryEngine.setScansEnabled(aerospikeDataProperties.isScansEnabled()); - queryEngine.setQueryMaxRecords(aerospikeDataProperties.getQueryMaxRecords()); - return queryEngine; - } - - @Bean(name = "aerospikeIndexRefresher") - @ConditionalOnMissingBean(name = "aerospikeIndexRefresher") - public IndexRefresher indexRefresher(IAerospikeClient aerospikeClient, IndexesCacheUpdater indexesCacheUpdater, - ServerVersionSupport serverVersionSupport, - AerospikeDataProperties aerospikeDataProperties, - AerospikeDataSettings dataSettings) { - IndexRefresher refresher = new IndexRefresher(aerospikeClient, aerospikeClient.getInfoPolicyDefault(), - new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionSupport); - refresher.refreshIndexes(); - int refreshFrequency = aerospikeDataSettings(aerospikeDataProperties, dataSettings).getIndexCacheRefreshSeconds(); - processCacheRefreshFrequency(refreshFrequency, refresher); - return refresher; - } - - private void processCacheRefreshFrequency(int indexCacheRefreshSeconds, IndexRefresher indexRefresher) { - if (indexCacheRefreshSeconds <= 0) { - log.info("Periodic index cache refreshing is not scheduled, interval ({}) is <= 0", - indexCacheRefreshSeconds); - } else { - indexRefresher.scheduleRefreshIndexes(indexCacheRefreshSeconds); - } - } - - @Bean - @ConditionalOnMissingBean(name = "aerospikePersistenceEntityIndexCreator") - public AerospikePersistenceEntityIndexCreator aerospikePersistenceEntityIndexCreator( - AerospikeDataProperties aerospikeDataProperties, - @Lazy ObjectProvider template, - ObjectProvider aerospikeMappingContext, - AerospikeIndexResolver aerospikeIndexResolver) { - return new AerospikePersistenceEntityIndexCreator(aerospikeMappingContext, - aerospikeDataProperties.isCreateIndexesOnStartup(), aerospikeIndexResolver, template); - } - - private AerospikeDataSettings aerospikeDataSettings(AerospikeDataProperties aerospikeDataProperties, - AerospikeDataSettings dataSettings) { - return configureDataSettings(dataSettings, aerospikeDataProperties); - } - - private AerospikeDataSettings configureDataSettings(AerospikeDataSettings dataSettings, - AerospikeDataProperties aerospikeDataProperties) { - dataSettings.setScansEnabled(aerospikeDataProperties.isScansEnabled()); - dataSettings.setCreateIndexesOnStartup(aerospikeDataProperties.isCreateIndexesOnStartup()); - dataSettings.setWriteSortedMaps(aerospikeDataProperties.isWriteSortedMaps()); - return dataSettings; - } -} diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java deleted file mode 100644 index 24872e6..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataConfiguration.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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.autoconfigure.data.aerospike; - -import com.aerospike.client.reactor.IAerospikeReactorClient; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Lazy; -import org.springframework.data.aerospike.config.AerospikeSettings; -import org.springframework.data.aerospike.convert.MappingAerospikeConverter; -import org.springframework.data.aerospike.core.AerospikeExceptionTranslator; -import org.springframework.data.aerospike.core.ReactiveAerospikeTemplate; -import org.springframework.data.aerospike.index.AerospikeIndexResolver; -import org.springframework.data.aerospike.index.ReactiveAerospikePersistenceEntityIndexCreator; -import org.springframework.data.aerospike.mapping.AerospikeMappingContext; -import org.springframework.data.aerospike.query.FilterExpressionsBuilder; -import org.springframework.data.aerospike.query.ReactorQueryEngine; -import org.springframework.data.aerospike.query.StatementBuilder; -import org.springframework.data.aerospike.query.cache.IndexInfoParser; -import org.springframework.data.aerospike.query.cache.IndexesCacheUpdater; -import org.springframework.data.aerospike.query.cache.InternalIndexOperations; -import org.springframework.data.aerospike.query.cache.ReactorIndexRefresher; -import org.springframework.data.aerospike.server.version.ServerVersionSupport; - -/** - * Configure Spring Data's Reactive Aerospike support. - * - * @author Igor Ermolenko - * @author Anastasiia Smirnova - */ -@AutoConfiguration -class AerospikeReactiveDataConfiguration { - - @Bean(name = "reactiveAerospikeTemplate") - @ConditionalOnMissingBean(name = "reactiveAerospikeTemplate") - public ReactiveAerospikeTemplate reactiveAerospikeTemplate(MappingAerospikeConverter mappingAerospikeConverter, - AerospikeDataProperties aerospikeDataProperties, - AerospikeMappingContext aerospikeMappingContext, - AerospikeExceptionTranslator aerospikeExceptionTranslator, - IAerospikeReactorClient aerospikeReactorClient, - ReactorQueryEngine reactorQueryEngine, - ReactorIndexRefresher reactorIndexRefresher, - ServerVersionSupport serverVersionSupport) { - return new ReactiveAerospikeTemplate(aerospikeReactorClient, aerospikeDataProperties.getNamespace(), - mappingAerospikeConverter, aerospikeMappingContext, - aerospikeExceptionTranslator, reactorQueryEngine, reactorIndexRefresher, serverVersionSupport); - } - - @Bean(name = "reactiveAerospikeQueryEngine") - @ConditionalOnMissingBean(name = "reactiveAerospikeQueryEngine") - public ReactorQueryEngine reactiveAerospikeQueryEngine(IAerospikeReactorClient aerospikeReactorClient, - AerospikeDataProperties aerospikeDataProperties, - FilterExpressionsBuilder filterExpressionsBuilder, - StatementBuilder statementBuilder, - AerospikeSettings settings) { - ReactorQueryEngine queryEngine = new ReactorQueryEngine(aerospikeReactorClient, statementBuilder, - filterExpressionsBuilder, settings.getDataSettings()); - queryEngine.setScansEnabled(aerospikeDataProperties.isScansEnabled()); - queryEngine.setQueryMaxRecords(aerospikeDataProperties.getQueryMaxRecords()); - return queryEngine; - } - - @Bean(name = "reactiveAerospikeIndexRefresher") - @ConditionalOnMissingBean(name = "reactiveAerospikeIndexRefresher") - public ReactorIndexRefresher reactiveAerospikeIndexRefresher(IAerospikeReactorClient aerospikeReactorClient, - IndexesCacheUpdater indexesCacheUpdater, - ServerVersionSupport serverVersionSupport) { - ReactorIndexRefresher refresher = new ReactorIndexRefresher(aerospikeReactorClient, aerospikeReactorClient.getInfoPolicyDefault(), - new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionSupport); - refresher.refreshIndexes().block(); - return refresher; - } - - @Bean - @ConditionalOnMissingBean(name = "reactiveAerospikePersistenceEntityIndexCreator") - public ReactiveAerospikePersistenceEntityIndexCreator reactiveAerospikePersistenceEntityIndexCreator( - AerospikeDataProperties aerospikeDataProperties, - @Lazy ObjectProvider template, - ObjectProvider aerospikeMappingContext, - AerospikeIndexResolver aerospikeIndexResolver) { - return new ReactiveAerospikePersistenceEntityIndexCreator(aerospikeMappingContext, - aerospikeDataProperties.isCreateIndexesOnStartup(), - aerospikeIndexResolver, - template); - } -} 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 e6b1e96..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,7 +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.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 31a3618..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,5 +0,0 @@ -org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration -org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataAutoConfiguration -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/AerospikeReactiveRepositoriesAutoConfigurationTest.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfigurationTest.java deleted file mode 100644 index c8b037f..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveRepositoriesAutoConfigurationTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.autoconfigure.data.aerospike; - -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -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; -import org.springframework.data.aerospike.core.ReactiveAerospikeTemplate; -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}. - * - * @author Igor Ermolenko - */ -public class AerospikeReactiveRepositoriesAutoConfigurationTest { - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .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); - }); - } - - @Test - public void repositoryIsNotCreatedWhenRepositoryInterfaceNotExists() { - contextRunner - .withUserConfiguration(NoRepositoryConfiguration.class) - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - @Test - public void repositoryIsNotCreatedForTypeImperative() { - contextRunner - .withUserConfiguration(DefaultConfiguration.class) - .withPropertyValues("spring.data.aerospike.repositories.type=imperative") - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - @Test - public void repositoryIsNotCreatedForTypeNone() { - contextRunner - .withUserConfiguration(DefaultConfiguration.class) - .withPropertyValues("spring.data.aerospike.repositories.type=none") - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - - @Configuration - @TestAutoConfigurationPackage(City.class) - static class DefaultConfiguration { - } - - @Configuration - @TestAutoConfigurationPackage(EmptyDataPackage.class) - static class NoRepositoryConfiguration { - } - - @Configuration - static class MockConfiguration { - - @Bean - public ReactiveAerospikeTemplate reactiveAerospikeTemplate() { - AerospikeMappingContext context = new AerospikeMappingContext(); - ReactiveAerospikeTemplate mock = Mockito.mock(ReactiveAerospikeTemplate.class); - when(mock.getMappingContext()).thenReturn((MappingContext) context); - return mock; - } - - - @Bean - public MappingContext aerospikeMappingContext() { - return mock(MappingContext.class); - } - } - -} diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java deleted file mode 100644 index 78e50b9..0000000 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeRepositoriesAutoConfigurationTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.autoconfigure.data.aerospike; - -import org.junit.jupiter.api.Test; -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; -import org.springframework.data.aerospike.core.AerospikeTemplate; -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}. - * - * @author Igor Ermolenko - */ -public class AerospikeRepositoriesAutoConfigurationTest { - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .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); - }); - } - - @Test - public void repositoryIsNotCreatedWhenRepositoryInterfaceDoesNotExists() { - contextRunner - .withUserConfiguration(NoRepositoryConfiguration.class) - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - @Test - public void repositoryIsNotCreatedForTypeReactive() { - contextRunner - .withUserConfiguration(DefaultConfiguration.class) - .withPropertyValues("spring.data.aerospike.repositories.type=reactive") - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - @Test - public void repositoryIsNotCreatedForTypeNone() { - contextRunner - .withUserConfiguration(DefaultConfiguration.class) - .withPropertyValues("spring.data.aerospike.repositories.type=none") - .run(context -> { - assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); - assertThat(context).doesNotHaveBean(CityRepository.class); - }); - } - - - @Configuration - @TestAutoConfigurationPackage(City.class) - static class DefaultConfiguration { - } - - @Configuration - @TestAutoConfigurationPackage(EmptyDataPackage.class) - static class NoRepositoryConfiguration { - } - - @Configuration - static class MockConfiguration { - @Bean - public AerospikeTemplate aerospikeTemplate() { - AerospikeMappingContext context = new AerospikeMappingContext(); - AerospikeTemplate mock = mock(AerospikeTemplate.class); - when(mock.getMappingContext()).thenReturn((MappingContext) context); - return mock; - } - - @Bean - public MappingContext aerospikeMappingContext() { - return mock(MappingContext.class); - } - } - -} 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 f771852..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.AerospikeCustomConversions; -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(name = "aerospikeCustomConversions") - AerospikeCustomConversions myCustomConversions() { - return new AerospikeCustomConversions(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..af1aa2a --- /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.condition.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-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java b/spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java new file mode 100644 index 0000000..4b620fd --- /dev/null +++ b/spring-boot-starter-aerospike/src/main/java/org/springframework/boot/client/autoconfigure/AerospikeClientConfiguration.java @@ -0,0 +1,58 @@ +package org.springframework.boot.client.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.AerospikeClient; +import com.aerospike.client.Host; +import com.aerospike.client.IAerospikeClient; +import com.aerospike.client.policy.ClientPolicy; +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.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.condition.IsClientOnly; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; + +/** + * {@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) +@AutoConfigureAfter({AerospikeAutoConfiguration.class}) +@Slf4j +public class AerospikeClientConfiguration { + + @Bean(name = "aerospikeClient", destroyMethod = "close") + @ConditionalOnMissingBean(IAerospikeClient.class) + public IAerospikeClient aerospikeClient(AerospikeProperties properties, + ClientPolicy aerospikeClientPolicy) { + log.info("Initializing Aerospike Java client"); + Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort()); + return new AerospikeClient(aerospikeClientPolicy, hosts); + } +} 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-example/reactive/src/main/resources/bootstrap.properties b/spring-boot-starter-data-aerospike-example/reactive/src/main/resources/bootstrap.properties deleted file mode 100644 index 7a55d9d..0000000 --- a/spring-boot-starter-data-aerospike-example/reactive/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,2 +0,0 @@ -#This property is optional, it is added for convenience to quickly disable embedded-aerospike -embedded.containers.enabled=true \ No newline at end of file diff --git a/spring-boot-starter-data-aerospike-example/sync/src/main/resources/bootstrap.properties b/spring-boot-starter-data-aerospike-example/sync/src/main/resources/bootstrap.properties deleted file mode 100644 index 7a55d9d..0000000 --- a/spring-boot-starter-data-aerospike-example/sync/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,2 +0,0 @@ -#This property is optional, it is added for convenience to quickly disable embedded-aerospike -embedded.containers.enabled=true \ 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 65% 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 fe9608e..adfcce2 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,7 +14,7 @@ * 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 org.springframework.boot.autoconfigure.AutoConfiguration; @@ -22,9 +22,12 @@ 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.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.condition.IsClientOnly; +import org.springframework.boot.autoconfigure.condition.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; import org.springframework.data.aerospike.repository.ReactiveAerospikeRepository; import reactor.core.publisher.Flux; @@ -37,11 +40,18 @@ */ @AutoConfiguration @ConditionalOnClass({IAerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class}) -@ConditionalOnSingleCandidate(IAerospikeReactorClient.class) -@ConditionalOnProperty("spring.data.aerospike.namespace") @AutoConfigureAfter(AerospikeAutoConfiguration.class) -@EnableConfigurationProperties(AerospikeDataProperties.class) -@Import({AerospikeReactiveDataConfiguration.class, AerospikeCommonDataConfiguration.class}) public class AerospikeReactiveDataAutoConfiguration { + @Conditional(IsNotClientOnly.class) + @EnableConfigurationProperties(AerospikeDataProperties.class) + @Import(AerospikeReactiveDataConfiguration.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-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java new file mode 100644 index 0000000..d8c4197 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/main/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveDataConfiguration.java @@ -0,0 +1,77 @@ +/* + * 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.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.util.AerospikeConfigurationUtils.*; + +/** + * Configure Spring Data's Aerospike support. + * Imported only when namespace property is given. + * + * @author Igor Ermolenko + * @author Anastasiia Smirnova + */ +@Slf4j +@Configuration +public class AerospikeReactiveDataConfiguration extends AbstractReactiveAerospikeDataConfiguration { + + @Autowired + private AerospikeProperties properties; + @Autowired + private AerospikeDataProperties dataProperties; + + @Override + protected Collection getHosts() { + return getClientHosts(properties); + } + + @Override + protected String nameSpace() { + return getNamespace(dataProperties); + } + + @Override + public EventLoops eventLoops() { + return new NioEventLoops(); + } + + @Override + protected ClientPolicy getClientPolicy() { + return getClientPolicyConfig(super.getClientPolicy(), properties); + } + + @Override + protected void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) { + getDataSettings(dataProperties, aerospikeDataSettings); + } +} 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 95% 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 c285d38..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,9 +14,10 @@ * 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; 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 57% 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 1f1d421..49346cf 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,17 @@ * 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.client.autoconfigure.AerospikeClientConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.data.aerospike.convert.AerospikeConverter; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; @@ -35,7 +35,10 @@ 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; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA; /** * Tests for {@link AerospikeReactiveDataAutoConfiguration}. @@ -46,28 +49,22 @@ public class AerospikeReactiveDataAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of( - AerospikeAutoConfiguration.class, AerospikeReactiveDataAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class, + AerospikeReactiveDataAutoConfiguration.class, AerospikeClientConfiguration.class)); @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 public void entityScanShouldSetInitialEntitySet() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeTestConfigurations.EntityScanConfiguration.class, - AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withUserConfiguration(AerospikeTestConfigurations.EntityScanConfiguration.class) .run(context -> { AerospikeMappingContext mappingContext = context.getBean(AerospikeMappingContext.class); assertThat(mappingContext.getManagedTypes()).containsOnly(TypeInformation.of(City.class)); @@ -77,26 +74,22 @@ public void entityScanShouldSetInitialEntitySet() { @Test public void classKeyDefault() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") .run(context -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); String typeKey = getField(aliasAccessor, "classKey"); - assertThat(typeKey).isEqualTo(AerospikeConverter.CLASS_KEY); + assertThat(typeKey).isEqualTo(AerospikeConverter.CLASS_KEY_DEFAULT); }); } @Test - public void typeKeyCanBeCustomized() { + public void classKeyCanBeCustomized() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class, - AerospikeServerVersionSupportMockConfiguration.class) - .withPropertyValues("spring.data.aerospike.type-key=++amazing++") + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withPropertyValues(CONFIG_PREFIX_DATA + ".class-key=++amazing++") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); String typeKey = getField(aliasAccessor, "classKey"); @@ -108,29 +101,41 @@ public void typeKeyCanBeCustomized() { @Test public void customConversions() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeTestConfigurations.CustomConversionsConfig.class, - AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withUserConfiguration(AerospikeTestConfigurations.CustomConversionsConfig.class) .run(context -> { MappingAerospikeConverter converter = context.getBean(MappingAerospikeConverter.class); assertThat(converter.getConversionService().canConvert(City.class, String.class)).isTrue(); }); } + @Test + public void runClientOnlyWhenNoNamespacePropertyGiven() { + contextRunner + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .run(context -> { + assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); + assertThat(context).doesNotHaveBean(AerospikeTemplate.class); + assertThat(context).doesNotHaveBean(AerospikeDataProperties.class); + assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); + assertThat(context).hasSingleBean(AerospikeProperties.class); + assertThat(context).hasSingleBean(IAerospikeClient.class); + }); + } + @Test public void configurationIsApplied() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") .run(context -> { assertThat(context).doesNotHaveBean(AerospikeTemplate.class); assertThat(context).hasSingleBean(ReactiveAerospikeTemplate.class); - assertThat(context).hasSingleBean(AerospikeDataProperties.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-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java new file mode 100644 index 0000000..ba750e0 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/AerospikeReactiveRepositoriesAutoConfigurationTest.java @@ -0,0 +1,97 @@ +/* + * 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.reactive.data; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +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.aerospike.AerospikeAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Configuration; + +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA; + +/** + * Tests for {@link AerospikeReactiveRepositoriesAutoConfiguration}. + * + * @author Igor Ermolenko + */ +public class AerospikeReactiveRepositoriesAutoConfigurationTest { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class, + AerospikeReactiveDataAutoConfiguration.class, AerospikeReactiveRepositoriesAutoConfiguration.class)) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST"); + + @Test + public void reactiveRepositoryIsCreated() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .run(context -> { + Assertions.assertThat(context).hasSingleBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedWhenRepositoryInterfaceNotExists() { + contextRunner + .withUserConfiguration(NoRepositoryConfiguration.class) + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedForTypeImperative() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_DATA + ".repositories.type=imperative") + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedForTypeNone() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_DATA + ".repositories.type=none") + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + + @Configuration + @TestAutoConfigurationPackage(City.class) + static class DefaultConfiguration { + } + + @Configuration + @TestAutoConfigurationPackage(EmptyDataPackage.class) + static class NoRepositoryConfiguration { + } +} 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..c0858fd --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackage.java @@ -0,0 +1,44 @@ +/* + * 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..7c8ddc0 --- /dev/null +++ b/spring-boot-starter-data-aerospike-reactive/src/test/java/org/springframework/boot/aerospike/reactive/data/TestAutoConfigurationPackageRegistrar.java @@ -0,0 +1,42 @@ +/* + * 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 66% 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 4239371..29b413b 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,7 +14,7 @@ * 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; @@ -22,10 +22,12 @@ 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.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.autoconfigure.condition.IsClientOnly; +import org.springframework.boot.autoconfigure.condition.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; import org.springframework.data.aerospike.repository.AerospikeRepository; @@ -36,15 +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}) -@ConditionalOnSingleCandidate(IAerospikeClient.class) -@ConditionalOnProperty("spring.data.aerospike.namespace") -@EnableConfigurationProperties(AerospikeDataProperties.class) @AutoConfigureAfter({AerospikeAutoConfiguration.class}) -@Import({AerospikeDataConfiguration.class, AerospikeCommonDataConfiguration.class}) public class AerospikeDataAutoConfiguration { + @Conditional(IsNotClientOnly.class) + @EnableConfigurationProperties(AerospikeDataProperties.class) + @Import(AerospikeDataConfiguration.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-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java new file mode 100644 index 0000000..14b79bf --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/main/java/org/springframework/boot/aerospike/data/AerospikeDataConfiguration.java @@ -0,0 +1,71 @@ +/* + * 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; + +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.util.AerospikeConfigurationUtils.*; + +/** + * Configure Spring Data's Aerospike support. + * Imported only when namespace property is given. + * + * @author Igor Ermolenko + * @author Anastasiia Smirnova + */ +@Slf4j +@Configuration +@AutoConfigureAfter({AerospikeDataAutoConfiguration.class}) +public class AerospikeDataConfiguration extends AbstractAerospikeDataConfiguration { + + @Autowired + private AerospikeProperties properties; + @Autowired + private AerospikeDataProperties dataProperties; + + @Override + protected Collection getHosts() { + return getClientHosts(properties); + } + + @Override + protected String nameSpace() { + return getNamespace(dataProperties); + } + + @Override + protected ClientPolicy getClientPolicy() { + return getClientPolicyConfig(super.getClientPolicy(), properties); + } + + @Override + protected void configureDataSettings(AerospikeDataSettings aerospikeDataSettings) { + getDataSettings(dataProperties, aerospikeDataSettings); + } +} 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 95% 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 268ec76..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,9 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.autoconfigure.data.aerospike; +package org.springframework.boot.aerospike.data; import com.aerospike.client.IAerospikeClient; +import jakarta.annotation.PostConstruct; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 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 53% 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 0b8505a..741a006 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,20 +14,18 @@ * 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; import com.aerospike.client.reactor.AerospikeReactorClient; -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.AerospikeServerVersionSupportMockConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.EntityScanConfiguration; -import org.springframework.boot.autoconfigure.data.aerospike.city.City; -import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties; +import org.springframework.boot.client.autoconfigure.AerospikeClientConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.data.aerospike.convert.AerospikeConverter; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; @@ -36,11 +34,10 @@ 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.AerospikeClientMockConfiguration; -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; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.*; /** * Tests for {@link AerospikeDataAutoConfiguration}. @@ -51,27 +48,23 @@ public class AerospikeDataAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withClassLoader(new FilteredClassLoader(IAerospikeReactorClient.class)) - .withConfiguration(AutoConfigurations.of( - AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class)); + .withConfiguration( + AutoConfigurations.of(AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class, + AerospikeClientConfiguration.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 public void entityScanShouldSetInitialEntitySet() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(EntityScanConfiguration.class, AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withUserConfiguration(AerospikeTestConfigurations.EntityScanConfiguration.class) .run(context -> { AerospikeMappingContext mappingContext = context.getBean(AerospikeMappingContext.class); assertThat(mappingContext.getManagedTypes()).containsOnly(TypeInformation.of(City.class)); @@ -81,26 +74,22 @@ public void entityScanShouldSetInitialEntitySet() { @Test public void classKeyDefault() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") .run(context -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); String classKey = getField(aliasAccessor, "classKey"); - assertThat(classKey).isEqualTo(AerospikeConverter.CLASS_KEY); + assertThat(classKey).isEqualTo(AerospikeConverter.CLASS_KEY_DEFAULT); }); } @Test public void typeKeyCanBeCustomized() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) - .withPropertyValues("spring.data.aerospike.type-key=++amazing++") + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withPropertyValues(CONFIG_PREFIX_DATA + ".class-key=++amazing++") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); String typeKey = getField(aliasAccessor, "classKey"); @@ -112,11 +101,9 @@ public void typeKeyCanBeCustomized() { @Test public void typeKeyCanBeNull() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) - .withPropertyValues("spring.data.aerospike.type-key=") + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withPropertyValues(CONFIG_PREFIX_DATA + ".class-key=") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); String typeKey = getField(aliasAccessor, "classKey"); @@ -128,24 +115,43 @@ public void typeKeyCanBeNull() { @Test public void customConversions() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(CustomConversionsConfig.class, AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withUserConfiguration(AerospikeTestConfigurations.CustomConversionsConfig.class) .run(context -> { MappingAerospikeConverter converter = context.getBean(MappingAerospikeConverter.class); assertThat(converter.getConversionService().canConvert(City.class, String.class)).isTrue(); }); } + @Test + public void sendKeyPropertyIsRead() { + contextRunner + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withPropertyValues(CONFIG_PREFIX + ".aerospike.write.sendKey=false") + .run(context -> { + IAerospikeClient client = context.getBean(IAerospikeClient.class); + assertThat(client.getWritePolicyDefault().sendKey).isFalse(); + }); + + contextRunner + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withPropertyValues(CONFIG_PREFIX + ".aerospike.write.sendKey=true") + .run(context -> { + IAerospikeClient client = context.getBean(IAerospikeClient.class); + assertThat(client.getWritePolicyDefault().sendKey).isTrue(); + }); + } + @Test public void configurationIsApplied() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".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); @@ -155,33 +161,41 @@ public void configurationIsApplied() { } @Test - public void dataConfigurationIsNotAppliedWithBothClients() { + public void runClientOnlyWhenNoNamespacePropertyGiven() { contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) - .withClassLoader(AerospikeReactorClient.class.getClassLoader()) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") .run(context -> { assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); assertThat(context).doesNotHaveBean(AerospikeTemplate.class); assertThat(context).doesNotHaveBean(AerospikeDataProperties.class); - assertThat(context).hasSingleBean(AerospikeProperties.class); assertThat(context).doesNotHaveBean(AerospikeMappingContext.class); + assertThat(context).hasSingleBean(AerospikeProperties.class); + assertThat(context).hasSingleBean(IAerospikeClient.class); + }); + } + + @Test + public void dataConfigurationIsAppliedWithDifferentClients() { + contextRunner + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") + .withClassLoader(AerospikeReactorClient.class.getClassLoader()) + .run(context -> { + assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); + assertThat(context).hasSingleBean(AerospikeTemplate.class); + assertThat(context).hasSingleBean(AerospikeProperties.class); + assertThat(context).hasSingleBean(AerospikeMappingContext.class); }); contextRunner - .withPropertyValues("spring.aerospike.hosts=localhost:3000") - .withPropertyValues("spring.data.aerospike.namespace=TEST") - .withUserConfiguration(AerospikeClientMockConfiguration.class, - AerospikeServerVersionSupportMockConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST") .withClassLoader(AerospikeReactorRetryClient.class.getClassLoader()) .run(context -> { assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeTemplate.class); - assertThat(context).doesNotHaveBean(AerospikeDataProperties.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-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java new file mode 100644 index 0000000..f80ad51 --- /dev/null +++ b/spring-boot-starter-data-aerospike/src/test/java/org/springframework/boot/aerospike/data/AerospikeRepositoriesAutoConfigurationTest.java @@ -0,0 +1,97 @@ +/* + * 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; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.aerospike.data.city.ReactiveCityRepository; +import org.springframework.boot.autoconfigure.AutoConfigurations; +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.autoconfigure.aerospike.AerospikeAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Configuration; + +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_CONNECTION; +import static org.springframework.data.aerospike.config.AerospikeDataConfigurationSupport.CONFIG_PREFIX_DATA; + +/** + * Tests for {@link AerospikeRepositoriesAutoConfiguration}. + * + * @author Igor Ermolenko + */ +public class AerospikeRepositoriesAutoConfigurationTest { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class, + AerospikeDataAutoConfiguration.class, AerospikeRepositoriesAutoConfiguration.class)) + .withPropertyValues(CONFIG_PREFIX_CONNECTION + ".hosts=localhost:3000") + .withPropertyValues(CONFIG_PREFIX_DATA + ".namespace=TEST"); + + @Test + public void repositoryIsCreated() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).hasSingleBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedWhenRepositoryInterfaceDoesNotExists() { + contextRunner + .withUserConfiguration(NoRepositoryConfiguration.class) + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedForTypeReactive() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_DATA + ".repositories.type=reactive") + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + @Test + public void repositoryIsNotCreatedForTypeNone() { + contextRunner + .withUserConfiguration(DefaultConfiguration.class) + .withPropertyValues(CONFIG_PREFIX_DATA + ".repositories.type=none") + .run(context -> { + Assertions.assertThat(context).doesNotHaveBean(ReactiveCityRepository.class); + Assertions.assertThat(context).doesNotHaveBean(CityRepository.class); + }); + } + + + @Configuration + @TestAutoConfigurationPackage(City.class) + static class DefaultConfiguration { + } + + @Configuration + @TestAutoConfigurationPackage(EmptyDataPackage.class) + static class NoRepositoryConfiguration { + } +} 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 88% 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..e5ee7c7 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.*; @@ -25,7 +26,7 @@ * value. * * @author Phillip Webb - * + *

* Copied from spring-boot project * https://github.com/spring-projects/spring-boot/issues/6718 */ @@ -35,6 +36,5 @@ @Import(TestAutoConfigurationPackageRegistrar.class) public @interface TestAutoConfigurationPackage { - Class value(); - + Class value(); } 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 69% 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..1528750 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; @@ -26,17 +27,16 @@ * {@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"))); - } - + @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-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 64% rename from spring-boot-starter-data-aerospike-example/pom.xml rename to spring-boot-starter-example-aerospike/pom.xml index aeed54c..7659f6b 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 @@ -52,4 +50,24 @@ test + + + + + org.apache.maven.plugins + maven-deploy-plugin + 3.1.3 + + + + deploy + + + false + + + + + + \ No newline at end of file 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/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/reactive-client/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..fd2bfee --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-client/src/main/resources/bootstrap.properties @@ -0,0 +1,3 @@ +#This property is optional, it is added for convenience to quickly disable embedded-aerospike +embedded.containers.enabled=true +embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 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-example-aerospike/reactive-data/src/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/reactive-data/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..fd2bfee --- /dev/null +++ b/spring-boot-starter-example-aerospike/reactive-data/src/main/resources/bootstrap.properties @@ -0,0 +1,3 @@ +#This property is optional, it is added for convenience to quickly disable embedded-aerospike +embedded.containers.enabled=true +embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 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/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/sync-client/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..fd2bfee --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-client/src/main/resources/bootstrap.properties @@ -0,0 +1,3 @@ +#This property is optional, it is added for convenience to quickly disable embedded-aerospike +embedded.containers.enabled=true +embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 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-example-aerospike/sync-data/src/main/resources/bootstrap.properties b/spring-boot-starter-example-aerospike/sync-data/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..fd2bfee --- /dev/null +++ b/spring-boot-starter-example-aerospike/sync-data/src/main/resources/bootstrap.properties @@ -0,0 +1,3 @@ +#This property is optional, it is added for convenience to quickly disable embedded-aerospike +embedded.containers.enabled=true +embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 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