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
ca1710ee
Commit
ca1710ee
authored
Jan 13, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to Apache Cassandra 4.3.1
See gh-19588
parent
d282eb61
Changes
30
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
406 additions
and
550 deletions
+406
-550
CassandraHealthContributorAutoConfiguration.java
...assandra/CassandraHealthContributorAutoConfiguration.java
+3
-3
CassandraReactiveHealthContributorAutoConfiguration.java
.../CassandraReactiveHealthContributorAutoConfiguration.java
+3
-3
CassandraHealthIndicator.java
...work/boot/actuate/cassandra/CassandraHealthIndicator.java
+5
-6
CassandraReactiveHealthIndicator.java
...t/actuate/cassandra/CassandraReactiveHealthIndicator.java
+3
-4
CassandraHealthIndicatorTests.java
...boot/actuate/cassandra/CassandraHealthIndicatorTests.java
+8
-8
CassandraReactiveHealthIndicatorTests.java
...uate/cassandra/CassandraReactiveHealthIndicatorTests.java
+4
-3
CassandraAutoConfiguration.java
...t/autoconfigure/cassandra/CassandraAutoConfiguration.java
+123
-44
CassandraProperties.java
...ork/boot/autoconfigure/cassandra/CassandraProperties.java
+63
-61
CqlSessionBuilderCustomizer.java
.../autoconfigure/cassandra/CqlSessionBuilderCustomizer.java
+10
-10
DriverConfigLoaderBuilderCustomizer.java
...figure/cassandra/DriverConfigLoaderBuilderCustomizer.java
+39
-0
CassandraDataAutoConfiguration.java
...figure/data/cassandra/CassandraDataAutoConfiguration.java
+16
-29
CassandraReactiveDataAutoConfiguration.java
...ata/cassandra/CassandraReactiveDataAutoConfiguration.java
+5
-6
CassandraRepositoriesAutoConfiguration.java
...ata/cassandra/CassandraRepositoriesAutoConfiguration.java
+3
-3
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+27
-0
CassandraAutoConfigurationTests.java
...oconfigure/cassandra/CassandraAutoConfigurationTests.java
+40
-82
CassandraDataAutoConfigurationIntegrationTests.java
...andra/CassandraDataAutoConfigurationIntegrationTests.java
+27
-12
CassandraDataAutoConfigurationTests.java
...e/data/cassandra/CassandraDataAutoConfigurationTests.java
+4
-4
CassandraReactiveDataAutoConfigurationTests.java
...assandra/CassandraReactiveDataAutoConfigurationTests.java
+4
-4
CassandraReactiveRepositoriesAutoConfigurationTests.java
.../CassandraReactiveRepositoriesAutoConfigurationTests.java
+6
-6
CassandraRepositoriesAutoConfigurationTests.java
...assandra/CassandraRepositoriesAutoConfigurationTests.java
+6
-6
City.java
...ramework/boot/autoconfigure/data/cassandra/city/City.java
+2
-3
build.gradle
spring-boot-project/spring-boot-dependencies/build.gradle
+4
-4
build.gradle
...t/spring-boot-tools/spring-boot-test-support/build.gradle
+1
-1
Customer.java
...ndra/src/main/java/smoketest/data/cassandra/Customer.java
+0
-48
CustomerRepository.java
...ain/java/smoketest/data/cassandra/CustomerRepository.java
+0
-32
SampleCassandraApplication.java
.../smoketest/data/cassandra/SampleCassandraApplication.java
+0
-64
application.properties
...-data-cassandra/src/main/resources/application.properties
+0
-1
OrderedCassandraTestExecutionListener.java
...data/cassandra/OrderedCassandraTestExecutionListener.java
+0
-44
SampleCassandraApplicationTests.java
...etest/data/cassandra/SampleCassandraApplicationTests.java
+0
-56
setup.cql
...ot-smoke-test-data-cassandra/src/test/resources/setup.cql
+0
-3
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cassandra;
import
java.util.Map
;
import
com.datastax.
driver.core.Cluster
;
import
com.datastax.
oss.driver.api.core.CqlSession
;
import
org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator
;
...
...
@@ -44,7 +44,7 @@ import org.springframework.data.cassandra.core.CassandraOperations;
* @since 2.1.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
C
luster
.
class
,
CassandraOperations
.
class
})
@ConditionalOnClass
({
C
qlSession
.
class
,
CassandraOperations
.
class
})
@ConditionalOnBean
(
CassandraOperations
.
class
)
@ConditionalOnEnabledHealthIndicator
(
"cassandra"
)
@AutoConfigureAfter
({
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
,
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -17,7 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.cassandra;
import
java.util.Map
;
import
com.datastax.
driver.core.Cluster
;
import
com.datastax.
oss.driver.api.core.CqlSession
;
import
reactor.core.publisher.Flux
;
import
org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration
;
...
...
@@ -43,7 +43,7 @@ import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
* @since 2.1.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
C
luster
.
class
,
ReactiveCassandraOperations
.
class
,
Flux
.
class
})
@ConditionalOnClass
({
C
qlSession
.
class
,
ReactiveCassandraOperations
.
class
,
Flux
.
class
})
@ConditionalOnBean
(
ReactiveCassandraOperations
.
class
)
@ConditionalOnEnabledHealthIndicator
(
"cassandra"
)
@AutoConfigureAfter
(
CassandraReactiveDataAutoConfiguration
.
class
)
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraHealthIndicator.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,9 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
cassandra
;
import
com.datastax.driver.core.ResultSet
;
import
com.datastax.driver.core.querybuilder.QueryBuilder
;
import
com.datastax.driver.core.querybuilder.Select
;
import
com.datastax.oss.driver.api.core.cql.ResultSet
;
import
com.datastax.oss.driver.api.core.cql.SimpleStatement
;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.Health
;
...
...
@@ -53,9 +52,9 @@ public class CassandraHealthIndicator extends AbstractHealthIndicator {
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
S
elect
select
=
QueryBuilder
.
select
(
"release_version"
).
from
(
"system"
,
"
local"
);
S
impleStatement
select
=
SimpleStatement
.
newInstance
(
"SELECT release_version FROM system.
local"
);
ResultSet
results
=
this
.
cassandraOperations
.
getCqlOperations
().
queryForResultSet
(
select
);
if
(
results
.
is
Exhaust
ed
())
{
if
(
results
.
is
FullyFetch
ed
())
{
builder
.
up
();
return
;
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraReactiveHealthIndicator.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -15,8 +15,7 @@
*/
package
org
.
springframework
.
boot
.
actuate
.
cassandra
;
import
com.datastax.driver.core.querybuilder.QueryBuilder
;
import
com.datastax.driver.core.querybuilder.Select
;
import
com.datastax.oss.driver.api.core.cql.SimpleStatement
;
import
reactor.core.publisher.Mono
;
import
org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator
;
...
...
@@ -47,7 +46,7 @@ public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndi
@Override
protected
Mono
<
Health
>
doHealthCheck
(
Health
.
Builder
builder
)
{
S
elect
select
=
QueryBuilder
.
select
(
"release_version"
).
from
(
"system"
,
"
local"
);
S
impleStatement
select
=
SimpleStatement
.
newInstance
(
"SELECT release_version FROM system.
local"
);
return
this
.
reactiveCassandraOperations
.
getReactiveCqlOperations
().
queryForObject
(
select
,
String
.
class
)
.
map
((
version
)
->
builder
.
up
().
withDetail
(
"version"
,
version
).
build
()).
single
();
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraHealthIndicatorTests.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,9 +16,9 @@
package
org
.
springframework
.
boot
.
actuate
.
cassandra
;
import
com.datastax.
driver.core
.ResultSet
;
import
com.datastax.
driver.core
.Row
;
import
com.datastax.
driver.core.querybuilder.Selec
t
;
import
com.datastax.
oss.driver.api.core.cql
.ResultSet
;
import
com.datastax.
oss.driver.api.core.cql
.Row
;
import
com.datastax.
oss.driver.api.core.cql.SimpleStatemen
t
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.health.Health
;
...
...
@@ -51,8 +51,8 @@ class CassandraHealthIndicatorTests {
ResultSet
resultSet
=
mock
(
ResultSet
.
class
);
CassandraHealthIndicator
healthIndicator
=
new
CassandraHealthIndicator
(
cassandraOperations
);
given
(
cassandraOperations
.
getCqlOperations
()).
willReturn
(
cqlOperations
);
given
(
cqlOperations
.
queryForResultSet
(
any
(
S
elec
t
.
class
))).
willReturn
(
resultSet
);
given
(
resultSet
.
is
Exhaust
ed
()).
willReturn
(
true
);
given
(
cqlOperations
.
queryForResultSet
(
any
(
S
impleStatemen
t
.
class
))).
willReturn
(
resultSet
);
given
(
resultSet
.
is
FullyFetch
ed
()).
willReturn
(
true
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
}
...
...
@@ -65,8 +65,8 @@ class CassandraHealthIndicatorTests {
Row
row
=
mock
(
Row
.
class
);
CassandraHealthIndicator
healthIndicator
=
new
CassandraHealthIndicator
(
cassandraOperations
);
given
(
cassandraOperations
.
getCqlOperations
()).
willReturn
(
cqlOperations
);
given
(
cqlOperations
.
queryForResultSet
(
any
(
S
elec
t
.
class
))).
willReturn
(
resultSet
);
given
(
resultSet
.
is
Exhaust
ed
()).
willReturn
(
false
);
given
(
cqlOperations
.
queryForResultSet
(
any
(
S
impleStatemen
t
.
class
))).
willReturn
(
resultSet
);
given
(
resultSet
.
is
FullyFetch
ed
()).
willReturn
(
false
);
given
(
resultSet
.
one
()).
willReturn
(
row
);
String
expectedVersion
=
"1.0.0"
;
given
(
row
.
getString
(
0
)).
willReturn
(
expectedVersion
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraReactiveHealthIndicatorTests.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -15,7 +15,7 @@
*/
package
org
.
springframework
.
boot
.
actuate
.
cassandra
;
import
com.datastax.
driver.core.querybuilder.Selec
t
;
import
com.datastax.
oss.driver.api.core.cql.SimpleStatemen
t
;
import
org.junit.jupiter.api.Test
;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
...
...
@@ -42,7 +42,8 @@ class CassandraReactiveHealthIndicatorTests {
@Test
void
testCassandraIsUp
()
{
ReactiveCqlOperations
reactiveCqlOperations
=
mock
(
ReactiveCqlOperations
.
class
);
given
(
reactiveCqlOperations
.
queryForObject
(
any
(
Select
.
class
),
eq
(
String
.
class
))).
willReturn
(
Mono
.
just
(
"6.0.0"
));
given
(
reactiveCqlOperations
.
queryForObject
(
any
(
SimpleStatement
.
class
),
eq
(
String
.
class
)))
.
willReturn
(
Mono
.
just
(
"6.0.0"
));
ReactiveCassandraOperations
reactiveCassandraOperations
=
mock
(
ReactiveCassandraOperations
.
class
);
given
(
reactiveCassandraOperations
.
getReactiveCqlOperations
()).
willReturn
(
reactiveCqlOperations
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java
View file @
ca1710ee
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -22,12 +22,10 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.List
;
import
com.datastax.driver.core.ConsistencyLevel
;
import
com.datastax.driver.core.ProtocolOptions
;
import
com.datastax.driver.core.ProtocolOptions.Compression
;
import
com.datastax.driver.core.QueryOptions
;
import
com.datastax.oss.driver.api.core.DefaultConsistencyLevel
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.DeprecatedConfigurationProperty
;
import
org.springframework.boot.convert.DurationUnit
;
/**
...
...
@@ -48,19 +46,14 @@ public class CassandraProperties {
private
String
keyspaceName
;
/**
* Name of the Cassandra
cluster
.
* Name of the Cassandra
session
.
*/
private
String
cluster
Name
;
private
String
session
Name
;
/**
* Cluster node addresses.
* Cluster node addresses
in the form 'host:port'
.
*/
private
final
List
<
String
>
contactPoints
=
new
ArrayList
<>(
Collections
.
singleton
(
"localhost"
));
/**
* Port of the Cassandra server.
*/
private
int
port
=
ProtocolOptions
.
DEFAULT_PORT
;
private
final
List
<
String
>
contactPoints
=
new
ArrayList
<>(
Collections
.
singleton
(
"127.0.0.1:9042"
));
/**
* Login user of the server.
...
...
@@ -80,17 +73,17 @@ public class CassandraProperties {
/**
* Queries consistency level.
*/
private
ConsistencyLevel
consistencyLevel
;
private
Default
ConsistencyLevel
consistencyLevel
;
/**
* Queries serial consistency level.
*/
private
ConsistencyLevel
serialConsistencyLevel
;
private
Default
ConsistencyLevel
serialConsistencyLevel
;
/**
* Queries default
fetch
size.
* Queries default
page
size.
*/
private
int
fetchSize
=
QueryOptions
.
DEFAULT_FETCH_SIZE
;
private
int
pageSize
=
5000
;
/**
* Socket option: connection time out.
...
...
@@ -112,12 +105,6 @@ public class CassandraProperties {
*/
private
boolean
ssl
=
false
;
/**
* Whether to enable JMX reporting. Default to false as Cassandra JMX reporting is not
* compatible with Dropwizard Metrics.
*/
private
boolean
jmxEnabled
;
/**
* Pool configuration.
*/
...
...
@@ -131,24 +118,27 @@ public class CassandraProperties {
this
.
keyspaceName
=
keyspaceName
;
}
public
String
get
Cluster
Name
()
{
return
this
.
cluster
Name
;
public
String
get
Session
Name
()
{
return
this
.
session
Name
;
}
public
void
set
ClusterName
(
String
cluster
Name
)
{
this
.
clusterName
=
cluster
Name
;
public
void
set
SessionName
(
String
session
Name
)
{
this
.
sessionName
=
session
Name
;
}
public
List
<
String
>
getContactPoints
()
{
return
this
.
contactPoints
;
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.data.cassandra.session-name"
)
public
String
getClusterName
()
{
return
getSessionName
();
}
public
int
getPort
()
{
return
this
.
port
;
@Deprecated
public
void
setClusterName
(
String
clusterName
)
{
setSessionName
(
clusterName
);
}
public
void
setPort
(
int
port
)
{
this
.
port
=
port
;
public
List
<
String
>
getContactPoints
(
)
{
return
this
.
contactPoints
;
}
public
String
getUsername
()
{
...
...
@@ -175,28 +165,39 @@ public class CassandraProperties {
this
.
compression
=
compression
;
}
public
ConsistencyLevel
getConsistencyLevel
()
{
public
Default
ConsistencyLevel
getConsistencyLevel
()
{
return
this
.
consistencyLevel
;
}
public
void
setConsistencyLevel
(
ConsistencyLevel
consistency
)
{
public
void
setConsistencyLevel
(
Default
ConsistencyLevel
consistency
)
{
this
.
consistencyLevel
=
consistency
;
}
public
ConsistencyLevel
getSerialConsistencyLevel
()
{
public
Default
ConsistencyLevel
getSerialConsistencyLevel
()
{
return
this
.
serialConsistencyLevel
;
}
public
void
setSerialConsistencyLevel
(
ConsistencyLevel
serialConsistency
)
{
public
void
setSerialConsistencyLevel
(
Default
ConsistencyLevel
serialConsistency
)
{
this
.
serialConsistencyLevel
=
serialConsistency
;
}
public
int
getPageSize
()
{
return
this
.
pageSize
;
}
public
void
setPageSize
(
int
pageSize
)
{
this
.
pageSize
=
pageSize
;
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.data.cassandra.page-size"
)
public
int
getFetchSize
()
{
return
this
.
fetchSize
;
return
getPageSize
()
;
}
@Deprecated
public
void
setFetchSize
(
int
fetchSize
)
{
this
.
fetchSize
=
fetchSize
;
setPageSize
(
fetchSize
)
;
}
public
Duration
getConnectTimeout
()
{
...
...
@@ -223,14 +224,6 @@ public class CassandraProperties {
this
.
ssl
=
ssl
;
}
public
boolean
isJmxEnabled
()
{
return
this
.
jmxEnabled
;
}
public
void
setJmxEnabled
(
boolean
jmxEnabled
)
{
this
.
jmxEnabled
=
jmxEnabled
;
}
public
String
getSchemaAction
()
{
return
this
.
schemaAction
;
}
...
...
@@ -255,11 +248,6 @@ public class CassandraProperties {
@DurationUnit
(
ChronoUnit
.
SECONDS
)
private
Duration
idleTimeout
=
Duration
.
ofSeconds
(
120
);
/**
* Pool timeout when trying to acquire a connection from a host's pool.
*/
private
Duration
poolTimeout
=
Duration
.
ofMillis
(
5000
);
/**
* Heartbeat interval after which a message is sent on an idle connection to make
* sure it's still alive. If a duration suffix is not specified, seconds will be
...
...
@@ -281,14 +269,6 @@ public class CassandraProperties {
this
.
idleTimeout
=
idleTimeout
;
}
public
Duration
getPoolTimeout
()
{
return
this
.
poolTimeout
;
}
public
void
setPoolTimeout
(
Duration
poolTimeout
)
{
this
.
poolTimeout
=
poolTimeout
;
}
public
Duration
getHeartbeatInterval
()
{
return
this
.
heartbeatInterval
;
}
...
...
@@ -307,4 +287,26 @@ public class CassandraProperties {
}
/**
* Name of the algorithm used to compress protocol frames.
*/
public
enum
Compression
{
/**
* Requires 'net.jpountz.lz4:lz4'.
*/
LZ4
,
/**
* Requires org.xerial.snappy:snappy-java.
*/
SNAPPY
,
/**
* No compression.
*/
NONE
;
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/C
luster
BuilderCustomizer.java
→
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/C
qlSession
BuilderCustomizer.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,24 +16,24 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
cassandra
;
import
com.datastax.
driver.core.Cluster
;
import
com.datastax.
driver.core.Cluster.
Builder
;
import
com.datastax.
oss.driver.api.core.CqlSession
;
import
com.datastax.
oss.driver.api.core.CqlSession
Builder
;
/**
* Callback interface that can be implemented by beans wishing to customize the
* {@link C
luster} via a {@link Builder Cluster.
Builder} whilst retaining default
* {@link C
qlSession} via a {@link CqlSession
Builder} whilst retaining default
* auto-configuration.
*
* @author
Eddú Meléndez
* @since
1.5
.0
* @author
Stephane Nicoll
* @since
2.3
.0
*/
@FunctionalInterface
public
interface
C
luster
BuilderCustomizer
{
public
interface
C
qlSession
BuilderCustomizer
{
/**
* Customize the {@link Builder}.
* @param c
luster
Builder the builder to customize
* Customize the {@link
CqlSession
Builder}.
* @param c
qlSession
Builder the builder to customize
*/
void
customize
(
Builder
cluster
Builder
);
void
customize
(
CqlSessionBuilder
cqlSession
Builder
);
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/
ClusterFactory
.java
→
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/
DriverConfigLoaderBuilderCustomizer
.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,24 +16,24 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
cassandra
;
import
com.datastax.
driver.core.Clust
er
;
import
com.datastax.
driver.core.Cluster.Initializ
er
;
import
com.datastax.
oss.driver.api.core.config.DriverConfigLoad
er
;
import
com.datastax.
oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuild
er
;
/**
* {@code ClusterFactory} provides control over the creation of a {@link Cluster} from an
* {@link Initializer}.
* Callback interface that can be implemented by beans wishing to customize the
* {@link DriverConfigLoader} via a {@link DriverConfigLoaderBuilderCustomizer} whilst
* retaining default auto-configuration.
*
* @author Ste
ffen F. Qvistgaard
* @since 2.
2
.0
* @author Ste
phane Nicoll
* @since 2.
3
.0
*/
@FunctionalInterface
public
interface
ClusterFactory
{
public
interface
DriverConfigLoaderBuilderCustomizer
{
/**
* C
reates a {@link Cluster} from the given {@link Initializer}.
*
@param initializer the {@code Initializer}
* @
return the {@code Cluster}
* C
ustomize the {@linkplain ProgrammaticDriverConfigLoaderBuilder DriverConfigLoader
*
builder}.
* @
param builder the builder to customize
*/
Cluster
create
(
Initializer
initializ
er
);
void
customizer
(
ProgrammaticDriverConfigLoaderBuilder
build
er
);
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -19,28 +19,25 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
java.util.Collections
;
import
java.util.List
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
com.datastax.oss.driver.api.core.CqlSession
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraProperties
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.domain.EntityScanPackages
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
import
org.springframework.data.cassandra.SessionFactory
;
import
org.springframework.data.cassandra.config.CassandraEntityClassScanner
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.SchemaAction
;
import
org.springframework.data.cassandra.config.SessionFactoryFactoryBean
;
import
org.springframework.data.cassandra.core.CassandraAdminOperations
;
import
org.springframework.data.cassandra.core.CassandraOperations
;
import
org.springframework.data.cassandra.core.CassandraTemplate
;
...
...
@@ -60,19 +57,15 @@ import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
* @since 1.3.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
Cluster
.
class
,
CassandraAdminOperations
.
class
})
@ConditionalOnBean
(
Cluster
.
class
)
@EnableConfigurationProperties
(
CassandraProperties
.
class
)
@ConditionalOnClass
({
CqlSession
.
class
,
CassandraAdminOperations
.
class
})
@ConditionalOnBean
(
CqlSession
.
class
)
@AutoConfigureAfter
(
CassandraAutoConfiguration
.
class
)
public
class
CassandraDataAutoConfiguration
{
private
final
C
assandraProperties
properties
;
private
final
C
qlSession
session
;
private
final
Cluster
cluster
;
public
CassandraDataAutoConfiguration
(
CassandraProperties
properties
,
Cluster
cluster
)
{
this
.
properties
=
properties
;
this
.
cluster
=
cluster
;
public
CassandraDataAutoConfiguration
(
CqlSession
session
)
{
this
.
session
=
session
;
}
@Bean
...
...
@@ -87,16 +80,11 @@ public class CassandraDataAutoConfiguration {
if
(!
packages
.
isEmpty
())
{
context
.
setInitialEntitySet
(
CassandraEntityClassScanner
.
scan
(
packages
));
}
PropertyMapper
.
get
().
from
(
this
.
properties
::
getKeyspaceName
).
whenHasText
().
as
(
this
::
createSimpleUserTypeResolver
)
.
to
(
context:
:
setUserTypeResolver
);
context
.
setUserTypeResolver
(
new
SimpleUserTypeResolver
(
this
.
session
));
context
.
setCustomConversions
(
conversions
);
return
context
;
}
private
SimpleUserTypeResolver
createSimpleUserTypeResolver
(
String
keyspaceName
)
{
return
new
SimpleUserTypeResolver
(
this
.
cluster
,
keyspaceName
);
}
@Bean
@ConditionalOnMissingBean
public
CassandraConverter
cassandraConverter
(
CassandraMappingContext
mapping
,
...
...
@@ -107,12 +95,11 @@ public class CassandraDataAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
(
Session
.
class
)
public
CassandraSession
FactoryBean
cassandraSession
(
Environment
environment
,
CassandraConverter
converter
)
{
CassandraSessionFactoryBean
session
=
new
CassandraSession
FactoryBean
();
session
.
set
Cluster
(
this
.
cluster
);
@ConditionalOnMissingBean
(
Session
Factory
.
class
)
public
SessionFactory
FactoryBean
cassandraSession
(
Environment
environment
,
CassandraConverter
converter
)
{
SessionFactoryFactoryBean
session
=
new
SessionFactory
FactoryBean
();
session
.
set
Session
(
this
.
session
);
session
.
setConverter
(
converter
);
session
.
setKeyspaceName
(
this
.
properties
.
getKeyspaceName
());
Binder
binder
=
Binder
.
get
(
environment
);
binder
.
bind
(
"spring.data.cassandra.schema-action"
,
SchemaAction
.
class
).
ifBound
(
session:
:
setSchemaAction
);
return
session
;
...
...
@@ -120,8 +107,8 @@ public class CassandraDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
CassandraOperations
.
class
)
public
CassandraTemplate
cassandraTemplate
(
Session
session
,
CassandraConverter
converter
)
{
return
new
CassandraTemplate
(
session
,
converter
);
public
CassandraTemplate
cassandraTemplate
(
Session
Factory
sessionFactory
,
CassandraConverter
converter
)
{
return
new
CassandraTemplate
(
session
Factory
,
converter
);
}
@Bean
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,8 +16,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
com.datastax.oss.driver.api.core.CqlSession
;
import
reactor.core.publisher.Flux
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
...
...
@@ -44,14 +43,14 @@ import org.springframework.data.cassandra.core.cql.session.DefaultReactiveSessio
* @since 2.0.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
C
luster
.
class
,
ReactiveCassandraTemplate
.
class
,
Flux
.
class
})
@ConditionalOnBean
(
Session
.
class
)
@ConditionalOnClass
({
C
qlSession
.
class
,
ReactiveCassandraTemplate
.
class
,
Flux
.
class
})
@ConditionalOnBean
(
Cql
Session
.
class
)
@AutoConfigureAfter
(
CassandraDataAutoConfiguration
.
class
)
public
class
CassandraReactiveDataAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
public
ReactiveSession
reactiveCassandraSession
(
Session
session
)
{
public
ReactiveSession
reactiveCassandraSession
(
Cql
Session
session
)
{
return
new
DefaultBridgedReactiveSession
(
session
);
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfiguration.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,7 +16,7 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
import
com.datastax.
driver.core.
Session
;
import
com.datastax.
oss.driver.api.core.Cql
Session
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
...
@@ -38,7 +38,7 @@ import org.springframework.data.cassandra.repository.support.CassandraRepository
* @since 1.3.0
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnClass
({
Session
.
class
,
CassandraRepository
.
class
})
@ConditionalOnClass
({
Cql
Session
.
class
,
CassandraRepository
.
class
})
@ConditionalOnRepositoryType
(
store
=
"cassandra"
,
type
=
RepositoryType
.
IMPERATIVE
)
@ConditionalOnMissingBean
(
CassandraRepositoryFactoryBean
.
class
)
@Import
(
CassandraRepositoriesRegistrar
.
class
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
ca1710ee
...
...
@@ -1557,6 +1557,33 @@
"level"
:
"error"
}
},
{
"name"
:
"spring.data.cassandra.jmx-enabled"
,
"type"
:
"java.lang.Boolean"
,
"description"
:
"Whether to enable JMX reporting. Default to false as Cassandra JMX reporting is not compatible with Dropwizard Metrics."
,
"deprecation"
:
{
"reason"
:
"Cassandra no longer providers JMX metrics."
,
"level"
:
"error"
}
},
{
"name"
:
"spring.data.cassandra.pool.pool-timeout"
,
"type"
:
"java.time.Duration"
,
"description"
:
"Pool timeout when trying to acquire a connection from a host's pool."
,
"deprecation"
:
{
"reason"
:
"No longer available."
,
"level"
:
"error"
}
},
{
"name"
:
"spring.data.cassandra.port"
,
"type"
:
"java.lang.Integer"
,
"description"
:
"Port of the Cassandra server."
,
"deprecation"
:
{
"reason"
:
"each contact point must be of the form 'host:port'."
,
"level"
:
"error"
}
},
{
"name"
:
"spring.data.cassandra.read-timeout-millis"
,
"type"
:
"java.lang.Integer"
,
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,9 +16,12 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
cassandra
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Cluster.Initializer
;
import
com.datastax.driver.core.PoolingOptions
;
import
com.datastax.oss.driver.api.core.config.DefaultDriverOption
;
import
com.datastax.oss.driver.api.core.config.DriverConfigLoader
;
import
com.datastax.oss.driver.api.core.config.DriverExecutionProfile
;
import
com.typesafe.config.Config
;
import
com.typesafe.config.ConfigParseOptions
;
import
com.typesafe.config.impl.Parseable
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -27,7 +30,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link CassandraAutoConfiguration}
...
...
@@ -41,110 +43,66 @@ class CassandraAutoConfigurationTests {
.
withConfiguration
(
AutoConfigurations
.
of
(
CassandraAutoConfiguration
.
class
));
@Test
void
createClusterWithDefault
()
{
void
driverConfigLoaderWithDefaultConfiguration
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
()).
startsWith
(
"cluster"
);
assertThat
(
context
).
hasSingleBean
(
DriverConfigLoader
.
class
);
assertThat
(
context
.
getBean
(
DriverConfigLoader
.
class
).
getInitialConfig
().
getDefaultProfile
()
.
isDefined
(
DefaultDriverOption
.
SESSION_NAME
)).
isFalse
();
});
}
@Test
void
createClusterWithOverrides
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
()).
isEqualTo
(
"testcluster"
);
void
driverConfigLoaderWithCustomSessionName
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.session-name=testcluster"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
DriverConfigLoader
.
class
);
assertThat
(
context
.
getBean
(
DriverConfigLoader
.
class
).
getInitialConfig
().
getDefaultProfile
()
.
getString
(
DefaultDriverOption
.
SESSION_NAME
)).
isEqualTo
(
"testcluster"
);
});
}
@Test
void
createCustomizeCluster
()
{
this
.
contextRunner
.
withUserConfiguration
(
MockCustomizerConfig
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
).
hasSingleBean
(
ClusterBuilderCustomizer
.
class
);
});
}
@Test
void
customizerOverridesAutoConfig
()
{
this
.
contextRunner
.
withUserConfiguration
(
SimpleCustomizerConfig
.
class
)
.
withPropertyValues
(
"spring.data.cassandra.cluster-name=testcluster"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
assertThat
(
context
.
getBean
(
Cluster
.
class
).
getClusterName
()).
isEqualTo
(
"overridden-name"
);
void
driverConfigLoaderWithCustomSessionNameAndCustomizer
()
{
this
.
contextRunner
.
withUserConfiguration
(
SimpleDriverConfigLoaderBuilderCustomizerConfig
.
class
)
.
withPropertyValues
(
"spring.data.cassandra.session-name=testcluster"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
DriverConfigLoader
.
class
);
assertThat
(
context
.
getBean
(
DriverConfigLoader
.
class
).
getInitialConfig
().
getDefaultProfile
()
.
getString
(
DefaultDriverOption
.
SESSION_NAME
)).
isEqualTo
(
"overridden-name"
);
});
}
@Test
void
d
efaultPoolOption
s
()
{
void
d
riverConfigLoaderApplyConsistentDefault
s
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
PoolingOptions
poolingOptions
=
context
.
getBean
(
Cluster
.
class
).
getConfiguration
().
getPoolingOptions
();
assertThat
(
poolingOptions
.
getIdleTimeoutSeconds
()).
isEqualTo
(
PoolingOptions
.
DEFAULT_IDLE_TIMEOUT_SECONDS
);
assertThat
(
poolingOptions
.
getPoolTimeoutMillis
()).
isEqualTo
(
PoolingOptions
.
DEFAULT_POOL_TIMEOUT_MILLIS
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
())
.
isEqualTo
(
PoolingOptions
.
DEFAULT_HEARTBEAT_INTERVAL_SECONDS
);
assertThat
(
poolingOptions
.
getMaxQueueSize
()).
isEqualTo
(
PoolingOptions
.
DEFAULT_MAX_QUEUE_SIZE
);
Config
defaultConfig
=
defaultConfig
();
DriverExecutionProfile
config
=
context
.
getBean
(
DriverConfigLoader
.
class
).
getInitialConfig
()
.
getDefaultProfile
();
// TODO
});
}
@Test
void
c
ustomizePoolOptions
()
{
void
driverConfigLoaderC
ustomizePoolOptions
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.data.cassandra.pool.idle-timeout=42"
,
"spring.data.cassandra.pool.pool-timeout=52"
,
"spring.data.cassandra.pool.heartbeat-interval=62"
,
"spring.data.cassandra.pool.max-queue-size=72"
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
);
PoolingOptions
poolingOptions
=
context
.
getBean
(
Cluster
.
class
).
getConfiguration
()
.
getPoolingOptions
();
assertThat
(
poolingOptions
.
getIdleTimeoutSeconds
()).
isEqualTo
(
42
);
assertThat
(
poolingOptions
.
getPoolTimeoutMillis
()).
isEqualTo
(
52
);
assertThat
(
poolingOptions
.
getHeartbeatIntervalSeconds
()).
isEqualTo
(
62
);
assertThat
(
poolingOptions
.
getMaxQueueSize
()).
isEqualTo
(
72
);
"spring.data.cassandra.pool.heartbeat-interval=62"
,
"spring.data.cassandra.pool.max-queue-size=72"
)
.
run
((
context
)
->
{
DriverExecutionProfile
config
=
context
.
getBean
(
DriverConfigLoader
.
class
).
getInitialConfig
()
.
getDefaultProfile
();
assertThat
(
config
.
getInt
(
DefaultDriverOption
.
HEARTBEAT_TIMEOUT
)).
isEqualTo
(
42
);
assertThat
(
config
.
getInt
(
DefaultDriverOption
.
HEARTBEAT_INTERVAL
)).
isEqualTo
(
62
);
assertThat
(
config
.
getInt
(
DefaultDriverOption
.
REQUEST_THROTTLER_MAX_QUEUE_SIZE
)).
isEqualTo
(
72
);
});
}
@Test
void
clusterFactoryIsCalledToCreateCluster
()
{
this
.
contextRunner
.
withUserConfiguration
(
ClusterFactoryConfig
.
class
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
TestClusterFactory
.
class
).
initializer
).
isNotNull
());
private
static
Config
defaultConfig
()
{
return
Parseable
.
newResources
(
"reference.conf"
,
ConfigParseOptions
.
defaults
()).
parse
().
toConfig
();
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
Mock
CustomizerConfig
{
static
class
SimpleDriverConfigLoaderBuilder
CustomizerConfig
{
@Bean
ClusterBuilderCustomizer
customizer
()
{
return
mock
(
ClusterBuilderCustomizer
.
class
);
}
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
SimpleCustomizerConfig
{
@Bean
ClusterBuilderCustomizer
customizer
()
{
return
(
clusterBuilder
)
->
clusterBuilder
.
withClusterName
(
"overridden-name"
);
}
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
ClusterFactoryConfig
{
@Bean
TestClusterFactory
clusterFactory
()
{
return
new
TestClusterFactory
();
}
}
static
class
TestClusterFactory
implements
ClusterFactory
{
private
Initializer
initializer
=
null
;
@Override
public
Cluster
create
(
Initializer
initializer
)
{
this
.
initializer
=
initializer
;
return
Cluster
.
buildFrom
(
initializer
);
DriverConfigLoaderBuilderCustomizer
customizer
()
{
return
(
builder
)
->
builder
.
withString
(
DefaultDriverOption
.
SESSION_NAME
,
"overridden-name"
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,10 +16,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
;
import
java.net.InetSocketAddress
;
import
java.time.Duration
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
com.datastax.oss.driver.api.core.CqlSession
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -29,11 +29,14 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CqlSessionBuilderCustomizer
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.cassandra.config.SchemaAction
;
import
org.springframework.data.cassandra.config.SessionFactoryFactoryBean
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -55,8 +58,9 @@ class CassandraDataAutoConfigurationIntegrationTests {
@BeforeEach
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
TestConfiguration
.
class
);
TestPropertyValues
.
of
(
"spring.data.cassandra.
port=
"
+
cassandra
.
getFirstMappedPort
(),
.
of
(
"spring.data.cassandra.
contact-points:localhost:
"
+
cassandra
.
getFirstMappedPort
(),
"spring.data.cassandra.read-timeout=24000"
,
"spring.data.cassandra.connect-timeout=10000"
)
.
applyTo
(
this
.
context
.
getEnvironment
());
}
...
...
@@ -74,8 +78,8 @@ class CassandraDataAutoConfigurationIntegrationTests {
AutoConfigurationPackages
.
register
(
this
.
context
,
cityPackage
);
this
.
context
.
register
(
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
);
this
.
context
.
refresh
();
CassandraSessionFactoryBean
bean
=
this
.
context
.
getBean
(
CassandraSessionFactoryBean
.
class
);
assertThat
(
bean
.
getSchemaAction
()).
isEqualTo
(
SchemaAction
.
NONE
);
assertThat
(
this
.
context
.
getBean
(
SessionFactoryFactoryBean
.
class
)).
hasFieldOrPropertyWithValue
(
"schemaAction"
,
SchemaAction
.
NONE
);
}
@Test
...
...
@@ -87,17 +91,28 @@ class CassandraDataAutoConfigurationIntegrationTests {
"spring.data.cassandra.keyspaceName=boot_test"
).
applyTo
(
this
.
context
);
this
.
context
.
register
(
CassandraAutoConfiguration
.
class
,
CassandraDataAutoConfiguration
.
class
);
this
.
context
.
refresh
();
CassandraSessionFactoryBean
bean
=
this
.
context
.
getBean
(
CassandraSessionFactoryBean
.
class
);
assertThat
(
bean
.
getSchemaAction
()).
isEqualTo
(
SchemaAction
.
RECREATE_DROP_UNUSED
);
assertThat
(
this
.
context
.
getBean
(
SessionFactoryFactoryBean
.
class
)).
hasFieldOrPropertyWithValue
(
"schemaAction"
,
SchemaAction
.
RECREATE_DROP_UNUSED
);
}
private
void
createTestKeyspaceIfNotExists
()
{
Cluster
cluster
=
Cluster
.
builder
().
withoutJMXReporting
().
withPort
(
cassandra
.
getFirstMappedPort
())
.
addContactPoint
(
cassandra
.
getContainerIpAddress
()).
build
();
try
(
Session
session
=
cluster
.
connect
())
{
try
(
CqlSession
session
=
CqlSession
.
builder
()
.
addContactPoint
(
new
InetSocketAddress
(
cassandra
.
getContainerIpAddress
(),
cassandra
.
getFirstMappedPort
()))
.
withLocalDatacenter
(
"datacenter1"
).
build
())
{
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
+
" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
);
}
}
@Configuration
static
class
TestConfiguration
{
@Bean
CqlSessionBuilderCustomizer
sessionCustomizer
()
{
return
(
builder
)
->
builder
.
withLocalDatacenter
(
"datacenter1"
);
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java
View file @
ca1710ee
...
...
@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
java.util.Collections
;
import
java.util.Set
;
import
com.datastax.
driver.core.
Session
;
import
com.datastax.
oss.driver.api.core.Cql
Session
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -101,7 +101,7 @@ class CassandraDataAutoConfigurationTests {
@Test
void
clusterDoesNotExist
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
(
CassandraDataAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
Session
.
class
)).
isEmpty
();
assertThat
(
this
.
context
.
getBeansOfType
(
Cql
Session
.
class
)).
isEmpty
();
}
void
load
(
Class
<?>...
config
)
{
...
...
@@ -119,8 +119,8 @@ class CassandraDataAutoConfigurationTests {
static
class
TestConfiguration
{
@Bean
Session
getObject
()
{
return
mock
(
Session
.
class
);
CqlSession
cqlSession
()
{
return
mock
(
Cql
Session
.
class
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
java.util.Set
;
import
com.datastax.
driver.core.
Session
;
import
com.datastax.
oss.driver.api.core.Cql
Session
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -99,8 +99,8 @@ class CassandraReactiveDataAutoConfigurationTests {
static
class
TestConfiguration
{
@Bean
Session
s
ession
()
{
return
mock
(
Session
.
class
);
CqlSession
cqlS
ession
()
{
return
mock
(
Cql
Session
.
class
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java
View file @
ca1710ee
...
...
@@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
java.util.Set
;
import
com.datastax.
driver.core.Cluster
;
import
com.datastax.
driver.core.Session
;
import
com.datastax.
oss.driver.api.core.CqlSession
;
import
com.datastax.
oss.driver.api.core.CqlSessionBuilder
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -61,7 +61,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
void
testDefaultRepositoryConfiguration
()
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ReactiveCityRepository
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
lust
er
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
qlSessionBuild
er
.
class
);
assertThat
(
getInitialEntitySet
(
context
)).
hasSize
(
1
);
});
}
...
...
@@ -69,7 +69,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test
void
testNoRepositoryConfiguration
()
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
C
lust
er
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
qlSessionBuild
er
.
class
);
assertThat
(
getInitialEntitySet
(
context
)).
isEmpty
();
});
}
...
...
@@ -106,8 +106,8 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
static
class
TestConfiguration
{
@Bean
Session
s
ession
()
{
return
mock
(
Session
.
class
);
CqlSession
cqlS
ession
()
{
return
mock
(
Cql
Session
.
class
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java
View file @
ca1710ee
...
...
@@ -18,8 +18,8 @@ package org.springframework.boot.autoconfigure.data.cassandra;
import
java.util.Set
;
import
com.datastax.
driver.core.Cluster
;
import
com.datastax.
driver.core.Session
;
import
com.datastax.
oss.driver.api.core.CqlSession
;
import
com.datastax.
oss.driver.api.core.CqlSessionBuilder
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
...
...
@@ -59,7 +59,7 @@ class CassandraRepositoriesAutoConfigurationTests {
void
testDefaultRepositoryConfiguration
()
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
CityRepository
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
lust
er
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
qlSessionBuild
er
.
class
);
assertThat
(
getInitialEntitySet
(
context
)).
hasSize
(
1
);
});
}
...
...
@@ -67,7 +67,7 @@ class CassandraRepositoriesAutoConfigurationTests {
@Test
void
testNoRepositoryConfiguration
()
{
this
.
contextRunner
.
withUserConfiguration
(
EmptyConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
C
lust
er
.
class
);
assertThat
(
context
).
hasSingleBean
(
C
qlSessionBuild
er
.
class
);
assertThat
(
getInitialEntitySet
(
context
)).
isEmpty
();
});
}
...
...
@@ -104,8 +104,8 @@ class CassandraRepositoriesAutoConfigurationTests {
static
class
TestConfiguration
{
@Bean
Session
s
ession
()
{
return
mock
(
Session
.
class
);
CqlSession
cqlS
ession
()
{
return
mock
(
Cql
Session
.
class
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/city/City.java
View file @
ca1710ee
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -16,9 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
cassandra
.
city
;
import
com.datastax.driver.core.DataType.Name
;
import
org.springframework.data.cassandra.core.mapping.CassandraType
;
import
org.springframework.data.cassandra.core.mapping.CassandraType.Name
;
import
org.springframework.data.cassandra.core.mapping.Column
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.Table
;
...
...
spring-boot-project/spring-boot-dependencies/build.gradle
View file @
ca1710ee
...
...
@@ -159,11 +159,11 @@ bom {
]
}
}
library
(
'Cassandra Driver'
,
'
3.7.2
'
)
{
group
(
'com.datastax.
cassandra
'
)
{
library
(
'Cassandra Driver'
,
'
4.3.1
'
)
{
group
(
'com.datastax.
oss
'
)
{
modules
=
[
'
cassandr
a-driver-core'
,
'
cassandra-driver-mapping
'
'
jav
a-driver-core'
,
'
java-driver-query-builder
'
]
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle
View file @
ca1710ee
...
...
@@ -6,7 +6,7 @@ plugins {
description
=
'Spring Boot Testing Support'
dependencies
{
compileOnly
"com.datastax.
cassandra:cassandr
a-driver-core"
compileOnly
"com.datastax.
oss:jav
a-driver-core"
compileOnly
"javax.servlet:javax.servlet-api"
compileOnly
"junit:junit"
compileOnly
"org.junit.jupiter:junit-jupiter"
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/Customer.java
deleted
100644 → 0
View file @
d282eb61
/*
* 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
smoketest
.
data
.
cassandra
;
import
java.util.UUID
;
import
org.springframework.data.cassandra.core.mapping.PrimaryKey
;
import
org.springframework.data.cassandra.core.mapping.Table
;
@Table
public
class
Customer
{
@PrimaryKey
private
UUID
id
;
private
String
firstName
;
private
String
lastName
;
public
Customer
()
{
}
public
Customer
(
UUID
id
,
String
firstName
,
String
lastName
)
{
this
.
id
=
id
;
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
this
.
id
,
this
.
firstName
,
this
.
lastName
);
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/CustomerRepository.java
deleted
100644 → 0
View file @
d282eb61
/*
* 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
smoketest
.
data
.
cassandra
;
import
java.util.List
;
import
org.springframework.data.cassandra.repository.Query
;
import
org.springframework.data.repository.CrudRepository
;
public
interface
CustomerRepository
extends
CrudRepository
<
Customer
,
String
>
{
@Query
(
"Select * from customer where firstname=?0"
)
Customer
findByFirstName
(
String
firstName
);
@Query
(
"Select * from customer where lastname=?0"
)
List
<
Customer
>
findByLastName
(
String
lastName
);
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/SampleCassandraApplication.java
deleted
100644 → 0
View file @
d282eb61
/*
* 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
smoketest
.
data
.
cassandra
;
import
com.datastax.driver.core.utils.UUIDs
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
SampleCassandraApplication
implements
CommandLineRunner
{
@Autowired
private
CustomerRepository
repository
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
this
.
repository
.
deleteAll
();
// save a couple of customers
this
.
repository
.
save
(
new
Customer
(
UUIDs
.
timeBased
(),
"Alice"
,
"Smith"
));
this
.
repository
.
save
(
new
Customer
(
UUIDs
.
timeBased
(),
"Bob"
,
"Smith"
));
// fetch all customers
System
.
out
.
println
(
"Customers found with findAll():"
);
System
.
out
.
println
(
"-------------------------------"
);
for
(
Customer
customer
:
this
.
repository
.
findAll
())
{
System
.
out
.
println
(
customer
);
}
System
.
out
.
println
();
// fetch an individual customer
System
.
out
.
println
(
"Customer found with findByFirstName('Alice'):"
);
System
.
out
.
println
(
"--------------------------------"
);
System
.
out
.
println
(
this
.
repository
.
findByFirstName
(
"Alice"
));
System
.
out
.
println
(
"Customers found with findByLastName('Smith'):"
);
System
.
out
.
println
(
"--------------------------------"
);
for
(
Customer
customer
:
this
.
repository
.
findByLastName
(
"Smith"
))
{
System
.
out
.
println
(
customer
);
}
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleCassandraApplication
.
class
,
args
);
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/resources/application.properties
deleted
100644 → 0
View file @
d282eb61
spring.data.cassandra.keyspace-name
=
mykeyspace
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/OrderedCassandraTestExecutionListener.java
deleted
100644 → 0
View file @
d282eb61
/*
* 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
smoketest
.
data
.
cassandra
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener
;
import
org.springframework.core.Ordered
;
public
class
OrderedCassandraTestExecutionListener
extends
CassandraUnitDependencyInjectionTestExecutionListener
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
OrderedCassandraTestExecutionListener
.
class
);
@Override
public
int
getOrder
()
{
return
Ordered
.
HIGHEST_PRECEDENCE
;
}
@Override
protected
void
cleanServer
()
{
try
{
super
.
cleanServer
();
}
catch
(
Exception
ex
)
{
logger
.
warn
(
"Failure during server cleanup"
,
ex
);
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationTests.java
deleted
100644 → 0
View file @
d282eb61
/*
* 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
smoketest
.
data
.
cassandra
;
import
java.io.File
;
import
org.cassandraunit.spring.CassandraDataSet
;
import
org.cassandraunit.spring.EmbeddedCassandra
;
import
org.junit.jupiter.api.Assumptions
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.system.CapturedOutput
;
import
org.springframework.boot.test.system.OutputCaptureExtension
;
import
org.springframework.test.context.TestExecutionListeners
;
import
org.springframework.test.context.TestExecutionListeners.MergeMode
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleCassandraApplication}.
*/
@TestExecutionListeners
(
mergeMode
=
MergeMode
.
MERGE_WITH_DEFAULTS
,
listeners
=
{
OrderedCassandraTestExecutionListener
.
class
})
@ExtendWith
(
OutputCaptureExtension
.
class
)
@SpringBootTest
@CassandraDataSet
(
keyspace
=
"mykeyspace"
,
value
=
"setup.cql"
)
@EmbeddedCassandra
(
timeout
=
60000
)
class
SampleCassandraApplicationTests
{
@Test
void
testDefaultSettings
(
CapturedOutput
output
)
{
Assumptions
.
assumeFalse
(
this
::
runningOnWindows
);
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
private
boolean
runningOnWindows
()
{
return
File
.
separatorChar
==
'\\'
;
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/resources/setup.cql
deleted
100644 → 0
View file @
d282eb61
CREATE TABLE customer (id TimeUUID PRIMARY KEY, firstname text, lastname text);
CREATE INDEX customerfistnameindex ON customer (firstname);
CREATE INDEX customersecondnameindex ON customer (lastname);
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