Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
64e08994
Commit
64e08994
authored
Nov 23, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish customize Cassandra's Cluster
Closes gh-7320
parent
cb3d14a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
28 deletions
+25
-28
CassandraAutoConfiguration.java
...t/autoconfigure/cassandra/CassandraAutoConfiguration.java
+5
-5
ClusterCustomizer.java
...ework/boot/autoconfigure/cassandra/ClusterCustomizer.java
+4
-3
CassandraAutoConfigurationTests.java
...oconfigure/cassandra/CassandraAutoConfigurationTests.java
+16
-20
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java
View file @
64e08994
...
@@ -49,12 +49,12 @@ public class CassandraAutoConfiguration {
...
@@ -49,12 +49,12 @@ public class CassandraAutoConfiguration {
private
final
CassandraProperties
properties
;
private
final
CassandraProperties
properties
;
private
final
List
<
ClusterCustomizer
>
customizers
;
private
final
List
<
ClusterCustomizer
>
c
lusterC
ustomizers
;
public
CassandraAutoConfiguration
(
CassandraProperties
properties
,
public
CassandraAutoConfiguration
(
CassandraProperties
properties
,
ObjectProvider
<
List
<
ClusterCustomizer
>>
c
ustomizers
)
{
ObjectProvider
<
List
<
ClusterCustomizer
>>
c
lusterCustomizersProvider
)
{
this
.
properties
=
properties
;
this
.
properties
=
properties
;
this
.
c
ustomizers
=
customizers
.
getIfAvailable
();
this
.
c
lusterCustomizers
=
clusterCustomizersProvider
.
getIfAvailable
();
}
}
@Bean
@Bean
...
@@ -96,8 +96,8 @@ public class CassandraAutoConfiguration {
...
@@ -96,8 +96,8 @@ public class CassandraAutoConfiguration {
}
}
private
void
customize
(
Cluster
cluster
)
{
private
void
customize
(
Cluster
cluster
)
{
if
(
this
.
customizers
!=
null
)
{
if
(
this
.
c
lusterC
ustomizers
!=
null
)
{
for
(
ClusterCustomizer
customizer
:
this
.
customizers
)
{
for
(
ClusterCustomizer
customizer
:
this
.
c
lusterC
ustomizers
)
{
customizer
.
customize
(
cluster
);
customizer
.
customize
(
cluster
);
}
}
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/ClusterCustomizer.java
View file @
64e08994
...
@@ -19,16 +19,17 @@ package org.springframework.boot.autoconfigure.cassandra;
...
@@ -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
);
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java
View file @
64e08994
...
@@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock;
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
,
CassandraAutoConfiguration
.
class
);
return
applicationContext
;
}
}
private
AnnotationConfigApplicationContext
doLoad
(
Class
<?>
clazz
)
{
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
applicationContext
=
doLoad
();
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
applicationContext
.
register
(
clazz
);
if
(
config
!=
null
)
{
return
applicationContext
;
ctx
.
register
(
config
);
}
ctx
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
ctx
,
environment
);
ctx
.
refresh
();
this
.
context
=
ctx
;
}
}
private
AnnotationConfigApplicationContext
doLoad
(
String
...
environment
)
{
AnnotationConfigApplicationContext
applicationContext
=
doLoad
();
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
return
applicationContext
;
}
@Configuration
@Configuration
static
class
ClusterConfig
{
static
class
ClusterConfig
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment