parent
cb3d14a305
commit
64e0899456
|
|
@ -49,12 +49,12 @@ public class CassandraAutoConfiguration {
|
||||||
|
|
||||||
private final CassandraProperties properties;
|
private final CassandraProperties properties;
|
||||||
|
|
||||||
private final List<ClusterCustomizer> customizers;
|
private final List<ClusterCustomizer> clusterCustomizers;
|
||||||
|
|
||||||
public CassandraAutoConfiguration(CassandraProperties properties,
|
public CassandraAutoConfiguration(CassandraProperties properties,
|
||||||
ObjectProvider<List<ClusterCustomizer>> customizers) {
|
ObjectProvider<List<ClusterCustomizer>> clusterCustomizersProvider) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.customizers = customizers.getIfAvailable();
|
this.clusterCustomizers = clusterCustomizersProvider.getIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -96,8 +96,8 @@ public class CassandraAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customize(Cluster cluster) {
|
private void customize(Cluster cluster) {
|
||||||
if (this.customizers != null) {
|
if (this.clusterCustomizers != null) {
|
||||||
for (ClusterCustomizer customizer : this.customizers) {
|
for (ClusterCustomizer customizer : this.clusterCustomizers) {
|
||||||
customizer.customize(cluster);
|
customizer.customize(cluster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,17 @@ package org.springframework.boot.autoconfigure.cassandra;
|
||||||
import com.datastax.driver.core.Cluster;
|
import com.datastax.driver.core.Cluster;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface that can be used to customize a {@link Cluster}.
|
* Callback interface that can be implemented by beans wishing to customize the
|
||||||
|
* {@link Cluster} before it is fully initialized, in particular to tune its
|
||||||
|
* configuration.
|
||||||
*
|
*
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
* @see CassandraAutoConfiguration
|
|
||||||
*/
|
*/
|
||||||
public interface ClusterCustomizer {
|
public interface ClusterCustomizer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customize the cluster.
|
* Customize the {@link Cluster}.
|
||||||
* @param cluster the cluster to customize
|
* @param cluster the cluster to customize
|
||||||
*/
|
*/
|
||||||
void customize(Cluster cluster);
|
void customize(Cluster cluster);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock;
|
||||||
* Tests for {@link CassandraAutoConfiguration}
|
* Tests for {@link CassandraAutoConfiguration}
|
||||||
*
|
*
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class CassandraAutoConfigurationTests {
|
public class CassandraAutoConfigurationTests {
|
||||||
|
|
||||||
|
|
@ -47,8 +48,7 @@ public class CassandraAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createClusterWithDefault() {
|
public void createClusterWithDefault() {
|
||||||
this.context = doLoad();
|
load();
|
||||||
this.context.refresh();
|
|
||||||
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
||||||
Cluster cluster = this.context.getBean(Cluster.class);
|
Cluster cluster = this.context.getBean(Cluster.class);
|
||||||
assertThat(cluster.getClusterName()).startsWith("cluster");
|
assertThat(cluster.getClusterName()).startsWith("cluster");
|
||||||
|
|
@ -56,8 +56,7 @@ public class CassandraAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createClusterWithOverrides() {
|
public void createClusterWithOverrides() {
|
||||||
this.context = doLoad("spring.data.cassandra.cluster-name=testcluster");
|
load("spring.data.cassandra.cluster-name=testcluster");
|
||||||
this.context.refresh();
|
|
||||||
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
||||||
Cluster cluster = this.context.getBean(Cluster.class);
|
Cluster cluster = this.context.getBean(Cluster.class);
|
||||||
assertThat(cluster.getClusterName()).isEqualTo("testcluster");
|
assertThat(cluster.getClusterName()).isEqualTo("testcluster");
|
||||||
|
|
@ -65,30 +64,27 @@ public class CassandraAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createCustomizeCluster() {
|
public void createCustomizeCluster() {
|
||||||
this.context = doLoad(ClusterConfig.class);
|
load(ClusterConfig.class);
|
||||||
this.context.refresh();
|
|
||||||
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
|
||||||
assertThat(this.context.getBeanNamesForType(ClusterCustomizer.class).length).isEqualTo(1);
|
assertThat(this.context.getBeanNamesForType(ClusterCustomizer.class).length).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext doLoad() {
|
private void load(String... environment) {
|
||||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
load(null, environment);
|
||||||
applicationContext.register(PropertyPlaceholderAutoConfiguration.class,
|
}
|
||||||
|
|
||||||
|
private void load(Class<?> config, String... environment) {
|
||||||
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||||
|
if (config != null) {
|
||||||
|
ctx.register(config);
|
||||||
|
}
|
||||||
|
ctx.register(PropertyPlaceholderAutoConfiguration.class,
|
||||||
CassandraAutoConfiguration.class);
|
CassandraAutoConfiguration.class);
|
||||||
return applicationContext;
|
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||||
|
ctx.refresh();
|
||||||
|
this.context = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext doLoad(Class<?> clazz) {
|
|
||||||
AnnotationConfigApplicationContext applicationContext = doLoad();
|
|
||||||
applicationContext.register(clazz);
|
|
||||||
return applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext doLoad(String... environment) {
|
|
||||||
AnnotationConfigApplicationContext applicationContext = doLoad();
|
|
||||||
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
|
|
||||||
return applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class ClusterConfig {
|
static class ClusterConfig {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue