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
47037d52
Commit
47037d52
authored
Apr 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add reactive support for Spring Data Cassandra"
Closes gh-8568
parent
abd35f04
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
86 deletions
+60
-86
ReactiveCassandraDataAutoConfiguration.java
...ata/cassandra/ReactiveCassandraDataAutoConfiguration.java
+11
-11
ReactiveCassandraRepositoriesAutoConfiguration.java
...andra/ReactiveCassandraRepositoriesAutoConfiguration.java
+3
-1
ReactiveCassandraRepositoriesAutoConfigureRegistrar.java
.../ReactiveCassandraRepositoriesAutoConfigureRegistrar.java
+1
-1
ReactiveCassandraDataAutoConfigurationTests.java
...assandra/ReactiveCassandraDataAutoConfigurationTests.java
+21
-39
ReactiveCassandraRepositoriesAutoConfigurationTests.java
.../ReactiveCassandraRepositoriesAutoConfigurationTests.java
+10
-13
ReactiveCityRepository.java
...configure/data/cassandra/city/ReactiveCityRepository.java
+2
-2
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-1
pom.xml
...rters/spring-boot-starter-data-cassandra-reactive/pom.xml
+11
-18
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/ReactiveCassandraDataAutoConfiguration.java
View file @
47037d52
...
...
@@ -18,11 +18,11 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
reactor.core.publisher.Flux
;
import
reactor.core.scheduler.Schedulers
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -43,29 +43,29 @@ import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass
({
Cluster
.
class
,
ReactiveCassandraTemplate
.
class
})
@ConditionalOnClass
({
Cluster
.
class
,
ReactiveCassandraTemplate
.
class
,
Flux
.
class
})
@ConditionalOnBean
(
Session
.
class
)
@AutoConfigureAfter
(
CassandraAutoConfiguration
.
class
)
@AutoConfigureAfter
(
Cassandra
Data
AutoConfiguration
.
class
)
public
class
ReactiveCassandraDataAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
(
ReactiveSession
.
class
)
public
ReactiveSession
rectiveSession
(
Session
session
)
throws
Exception
{
public
ReactiveSession
reactiveCassandraSession
(
Session
session
)
{
return
new
DefaultBridgedReactiveSession
(
session
,
Schedulers
.
elastic
());
}
@Bean
public
ReactiveSessionFactory
reactive
SessionFactory
(
ReactiveSession
reactiveSession
)
throws
Exception
{
return
new
DefaultReactiveSessionFactory
(
reactiveSession
);
public
ReactiveSessionFactory
reactive
CassandraSessionFactory
(
ReactiveSession
reactiveCassandraSession
)
{
return
new
DefaultReactiveSessionFactory
(
reactive
Cassandra
Session
);
}
@Bean
@ConditionalOnMissingBean
public
ReactiveCassandraTemplate
reactiveCassandraTemplate
(
ReactiveSession
session
,
CassandraConverter
converter
)
throws
Exception
{
return
new
ReactiveCassandraTemplate
(
session
,
converter
);
public
ReactiveCassandraTemplate
reactiveCassandraTemplate
(
ReactiveSession
reactiveCassandraSession
,
CassandraConverter
converter
)
{
return
new
ReactiveCassandraTemplate
(
reactiveCassandraSession
,
converter
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/ReactiveCassandraRepositoriesAutoConfiguration.java
View file @
47037d52
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
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
;
...
...
@@ -32,14 +33,15 @@ import org.springframework.data.cassandra.repository.support.ReactiveCassandraRe
* Reactive Repositories.
*
* @author Eddú Meléndez
* @see EnableReactiveCassandraRepositories
* @since 2.0.0
* @see EnableReactiveCassandraRepositories
*/
@Configuration
@ConditionalOnClass
({
ReactiveSession
.
class
,
ReactiveCassandraRepository
.
class
})
@ConditionalOnProperty
(
prefix
=
"spring.data.cassandra.reactive-repositories"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnMissingBean
(
ReactiveCassandraRepositoryFactoryBean
.
class
)
@Import
(
ReactiveCassandraRepositoriesAutoConfigureRegistrar
.
class
)
@AutoConfigureAfter
(
ReactiveCassandraDataAutoConfiguration
.
class
)
public
class
ReactiveCassandraRepositoriesAutoConfiguration
{
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/ReactiveCassandraRepositoriesAutoConfigureRegistrar.java
View file @
47037d52
...
...
@@ -31,7 +31,7 @@ import org.springframework.data.repository.config.RepositoryConfigurationExtensi
* @author Eddú Meléndez
* @since 2.0.0
*/
public
class
ReactiveCassandraRepositoriesAutoConfigureRegistrar
class
ReactiveCassandraRepositoriesAutoConfigureRegistrar
extends
AbstractRepositoryConfigurationSourceSupport
{
@Override
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/ReactiveCassandraDataAutoConfigurationTests.java
View file @
47037d52
...
...
@@ -20,21 +20,15 @@ import java.util.Set;
import
com.datastax.driver.core.Session
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cassandra.core.session.ReactiveSession
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
org.springframework.data.cassandra.core.ReactiveCassandraTemplate
;
import
org.springframework.data.cassandra.mapping.CassandraMappingContext
;
import
org.springframework.data.cassandra.mapping.SimpleUserTypeResolver
;
...
...
@@ -44,19 +38,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link ReactiveCassandraDataAutoConfiguration}
that require a Cassandra instance
.
* Tests for {@link ReactiveCassandraDataAutoConfiguration}.
*
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
ReactiveCassandraDataAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@Before
public
void
setup
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
}
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
...
...
@@ -66,27 +56,15 @@ public class ReactiveCassandraDataAutoConfigurationTests {
@Test
public
void
templateExists
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.cassandra.keyspaceName:boot_test"
);
this
.
context
.
register
(
TestExcludeConfiguration
.
class
,
TestConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
ReactiveCassandraDataAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBeanNamesForType
(
ReactiveCassandraTemplate
.
class
).
length
)
.
isEqualTo
(
1
);
load
(
"spring.data.cassandra.keyspaceName:boot_test"
);
assertThat
(
this
.
context
.
getBeanNamesForType
(
ReactiveCassandraTemplate
.
class
))
.
hasSize
(
1
);
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
entityScanShouldSetInitialEntitySet
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.cassandra.keyspaceName:boot_test"
);
this
.
context
.
register
(
TestConfiguration
.
class
,
EntityScanConfig
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
ReactiveCassandraDataAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
EntityScanConfig
.
class
,
"spring.data.cassandra.keyspaceName:boot_test"
);
CassandraMappingContext
mappingContext
=
this
.
context
.
getBean
(
CassandraMappingContext
.
class
);
Set
<
Class
<?>>
initialEntitySet
=
(
Set
<
Class
<?>>)
ReflectionTestUtils
...
...
@@ -96,24 +74,28 @@ public class ReactiveCassandraDataAutoConfigurationTests {
@Test
public
void
userTypeResolverShouldBeSet
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.data.cassandra.keyspaceName:boot_test"
);
this
.
context
.
register
(
TestConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
ReactiveCassandraDataAutoConfiguration
.
class
);
this
.
context
.
refresh
();
load
(
"spring.data.cassandra.keyspaceName:boot_test"
);
CassandraMappingContext
mappingContext
=
this
.
context
.
getBean
(
CassandraMappingContext
.
class
);
assertThat
(
ReflectionTestUtils
.
getField
(
mappingContext
,
"userTypeResolver"
))
.
isInstanceOf
(
SimpleUserTypeResolver
.
class
);
}
@Configuration
@ComponentScan
(
excludeFilters
=
@Filter
(
classes
=
{
ReactiveSession
.
class
},
type
=
FilterType
.
ASSIGNABLE_TYPE
))
static
class
TestExcludeConfiguration
{
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
ctx
,
environment
);
if
(
config
!=
null
)
{
ctx
.
register
(
config
);
}
ctx
.
register
(
TestConfiguration
.
class
,
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
ReactiveCassandraDataAutoConfiguration
.
class
);
ctx
.
refresh
();
this
.
context
=
ctx
;
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/ReactiveCassandraRepositoriesAutoConfigurationTests.java
View file @
47037d52
...
...
@@ -21,7 +21,6 @@ import java.util.Set;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
...
...
@@ -49,16 +48,12 @@ import static org.mockito.Mockito.mock;
* Tests for {@link ReactiveCassandraRepositoriesAutoConfiguration}.
*
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
ReactiveCassandraRepositoriesAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@Before
public
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
}
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
...
...
@@ -68,7 +63,7 @@ public class ReactiveCassandraRepositoriesAutoConfigurationTests {
@Test
public
void
testDefaultRepositoryConfiguration
()
{
addConfigurations
(
TestConfiguration
.
class
);
load
(
TestConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
ReactiveCityRepository
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
Cluster
.
class
)).
isNotNull
();
assertThat
(
getInitialEntitySet
()).
hasSize
(
1
);
...
...
@@ -76,14 +71,14 @@ public class ReactiveCassandraRepositoriesAutoConfigurationTests {
@Test
public
void
testNoRepositoryConfiguration
()
{
addConfigurations
(
TestExcludeConfiguration
.
class
,
EmptyConfiguration
.
class
);
load
(
TestExcludeConfiguration
.
class
,
EmptyConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
Cluster
.
class
)).
isNotNull
();
assertThat
(
getInitialEntitySet
()).
hasSize
(
1
).
containsOnly
(
City
.
class
);
}
@Test
public
void
doesNotTriggerDefaultRepositoryDetectionIfCustomized
()
{
addConfigurations
(
TestExcludeConfiguration
.
class
,
CustomizedConfiguration
.
class
);
load
(
TestExcludeConfiguration
.
class
,
CustomizedConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
ReactiveCityCassandraRepository
.
class
)).
isNotNull
();
assertThat
(
getInitialEntitySet
()).
hasSize
(
1
).
containsOnly
(
City
.
class
);
}
...
...
@@ -96,15 +91,17 @@ public class ReactiveCassandraRepositoriesAutoConfigurationTests {
"initialEntitySet"
);
}
private
void
addConfigurations
(
Class
<?>...
configurations
)
{
this
.
context
.
register
(
configurations
);
this
.
context
.
register
(
CassandraAutoConfiguration
.
class
,
private
void
load
(
Class
<?>...
configurations
)
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
configurations
);
ctx
.
register
(
CassandraAutoConfiguration
.
class
,
CassandraRepositoriesAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
ReactiveCassandraDataAutoConfiguration
.
class
,
ReactiveCassandraRepositoriesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
ctx
.
refresh
();
this
.
context
=
ctx
;
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/city/ReactiveCityRepository.java
View file @
47037d52
...
...
@@ -16,8 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
.
city
;
import
org.springframework.data.repository.Repository
;
import
org.springframework.data.repository.
reactive.ReactiveCrud
Repository
;
public
interface
ReactiveCityRepository
extends
Repository
<
City
,
Long
>
{
public
interface
ReactiveCityRepository
extends
Re
activeCrudRe
pository
<
City
,
Long
>
{
}
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
47037d52
...
...
@@ -573,7 +573,7 @@ content into your application; rather pick only the properties that you need.
spring.data.cassandra.load-balancing-policy= # Class name of the load balancing policy.
spring.data.cassandra.port= # Port of the Cassandra server.
spring.data.cassandra.password= # Login password of the server.
spring.data.cassandra.reactive-repositories.enabled= # Enable Cassandra reactive repositories.
spring.data.cassandra.reactive-repositories.enabled=
true
# Enable Cassandra reactive repositories.
spring.data.cassandra.read-timeout-millis= # Socket option: read time out.
spring.data.cassandra.reconnection-policy= # Reconnection policy class.
spring.data.cassandra.repositories.enabled= # Enable Cassandra repositories.
...
...
spring-boot-starters/spring-boot-starter-data-cassandra-reactive/pom.xml
View file @
47037d52
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2012-2017 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
~
~ http://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.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -25,7 +11,8 @@
<artifactId>
spring-boot-starter-data-cassandra-reactive
</artifactId>
<name>
Spring Boot Data Cassandra Reactive Starter
</name>
<description>
Starter for using Cassandra distributed database and Spring Data
Cassandra Reactive
</description>
Cassandra Reactive
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
...
...
@@ -46,6 +33,12 @@
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-cassandra
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
jcl-over-slf4j
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
...
...
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