Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-566 Update configuration in the Starters project #257

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
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.autoconfigure.data.aerospike.AerospikeDataProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import reactor.core.publisher.Flux;

import java.util.Optional;
Expand All @@ -43,35 +42,19 @@
* @author Anastasiia Smirnova
*/
@AutoConfiguration
@ConditionalOnClass(AerospikeClient.class)
@ConditionalOnClass(IAerospikeClient.class)
@ConditionalOnProperty("spring.aerospike.hosts")
@EnableConfigurationProperties(AerospikeProperties.class)
public class AerospikeAutoConfiguration {

@Bean(name = "aerospikeClient", destroyMethod = "close")
@ConditionalOnMissingBean(IAerospikeClient.class)
public AerospikeClient aerospikeClient(AerospikeProperties properties,
ClientPolicy aerospikeClientPolicy) {
public IAerospikeClient aerospikeClient(AerospikeProperties properties,
ClientPolicy aerospikeClientPolicy) {
Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort());
return new AerospikeClient(aerospikeClientPolicy, hosts);
}

@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 = "aerospikeClientPolicy")
@ConditionalOnMissingBean
public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties,
Expand Down Expand Up @@ -102,14 +85,14 @@ public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties,
return clientPolicy;
}

@ConditionalOnClass({AerospikeReactorClient.class, Flux.class})
@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 AerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient,
EventLoops eventLoops) {
public IAerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient,
EventLoops eventLoops) {
return new AerospikeReactorClient(aerospikeClient, eventLoops);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ public class AerospikeProperties {
* <p>
* See {@link com.aerospike.client.Host#parseHosts} documentation for more details.
*
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.connection".
* will be used instead to read from application.properties
*/
@Deprecated(since = "0.14.0", forRemoval = true)
private String hosts;

/**
* Port is used if no port specified in AerospikeProperties#hosts.
* <p>
* See {@link com.aerospike.client.Host#parseHosts} documentation for more details.
*
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.connection".
* will be used instead to read from application.properties
*/
@Deprecated(since = "0.14.0", forRemoval = true)
private int defaultPort = 3000;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand All @@ -22,6 +23,7 @@
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;

Expand All @@ -31,6 +33,22 @@
@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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.IAerospikeClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -39,8 +38,8 @@
@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.AerospikeReactorClient")
@ConditionalOnClass({AerospikeClient.class, AerospikeRepository.class})
@ConditionalOnMissingClass("com.aerospike.client.reactor.IAerospikeReactorClient")
@ConditionalOnClass({IAerospikeClient.class, AerospikeRepository.class})
@ConditionalOnSingleCandidate(IAerospikeClient.class)
@ConditionalOnProperty("spring.data.aerospike.namespace")
@EnableConfigurationProperties(AerospikeDataProperties.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@

/**
* Configuration properties for Spring Data Aerospike.
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.data".
* will be used instead to read from application.properties.
*
* @author Igor Ermolenko
* @author Anastasiia Smirnova
*/
@Deprecated(since = "0.14.0", forRemoval = true)
@ConfigurationProperties(prefix = "spring.data.aerospike")
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.reactor.AerospikeReactorClient;
import com.aerospike.client.reactor.IAerospikeReactorClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand All @@ -36,8 +36,8 @@
* @author Anastasiia Smirnova
*/
@AutoConfiguration
@ConditionalOnClass({AerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class})
@ConditionalOnSingleCandidate(AerospikeReactorClient.class)
@ConditionalOnClass({IAerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class})
@ConditionalOnSingleCandidate(IAerospikeReactorClient.class)
@ConditionalOnProperty("spring.data.aerospike.namespace")
@AutoConfigureAfter(AerospikeAutoConfiguration.class)
@EnableConfigurationProperties(AerospikeDataProperties.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.reactor.AerospikeReactorClient;
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;
Expand Down Expand Up @@ -53,7 +53,7 @@ public ReactiveAerospikeTemplate reactiveAerospikeTemplate(MappingAerospikeConve
AerospikeDataProperties aerospikeDataProperties,
AerospikeMappingContext aerospikeMappingContext,
AerospikeExceptionTranslator aerospikeExceptionTranslator,
AerospikeReactorClient aerospikeReactorClient,
IAerospikeReactorClient aerospikeReactorClient,
ReactorQueryEngine reactorQueryEngine,
ReactorIndexRefresher reactorIndexRefresher,
ServerVersionSupport serverVersionSupport) {
Expand All @@ -64,7 +64,7 @@ public ReactiveAerospikeTemplate reactiveAerospikeTemplate(MappingAerospikeConve

@Bean(name = "reactiveAerospikeQueryEngine")
@ConditionalOnMissingBean(name = "reactiveAerospikeQueryEngine")
public ReactorQueryEngine reactiveAerospikeQueryEngine(AerospikeReactorClient aerospikeReactorClient,
public ReactorQueryEngine reactiveAerospikeQueryEngine(IAerospikeReactorClient aerospikeReactorClient,
AerospikeDataProperties aerospikeDataProperties,
FilterExpressionsBuilder filterExpressionsBuilder,
StatementBuilder statementBuilder,
Expand All @@ -78,7 +78,7 @@ public ReactorQueryEngine reactiveAerospikeQueryEngine(AerospikeReactorClient ae

@Bean(name = "reactiveAerospikeIndexRefresher")
@ConditionalOnMissingBean(name = "reactiveAerospikeIndexRefresher")
public ReactorIndexRefresher reactiveAerospikeIndexRefresher(AerospikeReactorClient aerospikeReactorClient,
public ReactorIndexRefresher reactiveAerospikeIndexRefresher(IAerospikeReactorClient aerospikeReactorClient,
IndexesCacheUpdater indexesCacheUpdater,
ServerVersionSupport serverVersionSupport) {
ReactorIndexRefresher refresher = new ReactorIndexRefresher(aerospikeReactorClient, aerospikeReactorClient.getInfoPolicyDefault(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.autoconfigure.data.aerospike;

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;
Expand All @@ -34,7 +34,7 @@
* @author Igor Ermolenko
*/
@AutoConfiguration
@ConditionalOnClass({AerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class})
@ConditionalOnClass({IAerospikeReactorClient.class, ReactiveAerospikeRepository.class, Flux.class})
@ConditionalOnRepositoryType(store = "aerospike", type = RepositoryType.REACTIVE)
@ConditionalOnMissingBean(ReactiveAerospikeRepositoryFactoryBean.class)
@Import(AerospikeReactiveRepositoriesRegistrar.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.IAerospikeClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -33,7 +33,7 @@
* @author Igor Ermolenko
*/
@AutoConfiguration
@ConditionalOnClass({AerospikeClient.class, ReactiveAerospikeRepository.class})
@ConditionalOnClass({IAerospikeClient.class, ReactiveAerospikeRepository.class})
@ConditionalOnRepositoryType(store = "aerospike", type = RepositoryType.IMPERATIVE)
@ConditionalOnMissingBean(AerospikeRepositoryFactoryBean.class)
@Import(AerospikeRepositoriesRegistrar.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.aerospike.client.AerospikeClient;
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.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration;
Expand Down Expand Up @@ -49,7 +51,7 @@
public class AerospikeDataAutoConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withClassLoader(new FilteredClassLoader(AerospikeReactorClient.class))
.withClassLoader(new FilteredClassLoader(IAerospikeReactorClient.class))
.withConfiguration(AutoConfigurations.of(
AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class));

Expand Down Expand Up @@ -151,4 +153,35 @@ public void configurationIsApplied() {
assertThat(context).hasSingleBean(AerospikeMappingContext.class);
});
}

@Test
public void dataConfigurationIsNotAppliedWithBothClients() {
contextRunner
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST")
.withUserConfiguration(AerospikeClientMockConfiguration.class,
AerospikeServerVersionSupportMockConfiguration.class)
.withClassLoader(AerospikeReactorClient.class.getClassLoader())
.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);
});

contextRunner
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST")
.withUserConfiguration(AerospikeClientMockConfiguration.class,
AerospikeServerVersionSupportMockConfiguration.class)
.withClassLoader(AerospikeReactorRetryClient.class.getClassLoader())
.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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.IAerospikeClient;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class AerospikeReactiveDataAutoConfigurationTest {
@Test
public void aerospikeTemplateAndClientAreNotSetupWhenNeitherClientNorDataPropertiesConfigured() {
contextRunner.run(context -> {
assertThat(context).doesNotHaveBean(AerospikeClient.class);
assertThat(context).doesNotHaveBean(IAerospikeClient.class);
assertThat(context).doesNotHaveBean(AerospikeTemplate.class);
assertThat(context).doesNotHaveBean(ReactiveAerospikeTemplate.class);
assertThat(context).doesNotHaveBean(AerospikeDataProperties.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ void savesAndGets() {
.assertThat()
.statusCode(200)
.body("id", equalTo("andrea"))
.body("age", equalTo(61))
;
.body("age", equalTo(61));
}

@Order(2)
Expand All @@ -82,7 +81,6 @@ void savesAndFindsByLastName() {
.assertThat()
.statusCode(200)
.body("[0].id", equalTo("andrea"))
.body("[0].age", equalTo(61))
;
.body("[0].age", equalTo(61));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

Expand Down Expand Up @@ -66,8 +61,7 @@ void savesAndGets() {
.assertThat()
.statusCode(200)
.body("id", equalTo("andrea"))
.body("age", equalTo(61))
;
.body("age", equalTo(61));
}

@Order(2)
Expand All @@ -87,8 +81,6 @@ void savesAndFindsByLastName() {
.assertThat()
.statusCode(200)
.body("[0].id", equalTo("andrea"))
.body("[0].age", equalTo(61))
;
.body("[0].age", equalTo(61));
}

}
Loading