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
a975c0ad
Commit
a975c0ad
authored
Feb 12, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Testcontainers’ CassandraContainer rather than our own
Closes gh-15901
parent
8426d885
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
89 deletions
+11
-89
pom.xml
spring-boot-project/spring-boot-autoconfigure/pom.xml
+5
-0
CassandraDataAutoConfigurationIntegrationTests.java
...andra/CassandraDataAutoConfigurationIntegrationTests.java
+6
-5
CassandraContainer.java
...k/boot/testsupport/testcontainers/CassandraContainer.java
+0
-84
No files found.
spring-boot-project/spring-boot-autoconfigure/pom.xml
View file @
a975c0ad
...
@@ -810,6 +810,11 @@
...
@@ -810,6 +810,11 @@
<artifactId>
spring-security-test
</artifactId>
<artifactId>
spring-security-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.testcontainers
</groupId>
<artifactId>
cassandra
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.testcontainers
</groupId>
<groupId>
org.testcontainers
</groupId>
<artifactId>
testcontainers
</artifactId>
<artifactId>
testcontainers
</artifactId>
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java
View file @
a975c0ad
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -22,12 +22,12 @@ import org.junit.After;
...
@@ -22,12 +22,12 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.testcontainers.containers.CassandraContainer
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.CassandraContainer
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.SchemaAction
;
import
org.springframework.data.cassandra.config.SchemaAction
;
...
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
CassandraDataAutoConfigurationIntegrationTests
{
public
class
CassandraDataAutoConfigurationIntegrationTests
{
@ClassRule
@ClassRule
public
static
CassandraContainer
cassandra
=
new
CassandraContainer
();
public
static
CassandraContainer
<?>
cassandra
=
new
CassandraContainer
<>
();
private
AnnotationConfigApplicationContext
context
;
private
AnnotationConfigApplicationContext
context
;
...
@@ -51,7 +51,7 @@ public class CassandraDataAutoConfigurationIntegrationTests {
...
@@ -51,7 +51,7 @@ public class CassandraDataAutoConfigurationIntegrationTests {
public
void
setUp
()
{
public
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
TestPropertyValues
.
of
(
"spring.data.cassandra.port="
+
cassandra
.
getMappedPort
(),
.
of
(
"spring.data.cassandra.port="
+
cassandra
.
get
First
MappedPort
(),
"spring.data.cassandra.read-timeout=24000"
,
"spring.data.cassandra.read-timeout=24000"
,
"spring.data.cassandra.connect-timeout=10000"
)
"spring.data.cassandra.connect-timeout=10000"
)
.
applyTo
(
this
.
context
.
getEnvironment
());
.
applyTo
(
this
.
context
.
getEnvironment
());
...
@@ -96,7 +96,8 @@ public class CassandraDataAutoConfigurationIntegrationTests {
...
@@ -96,7 +96,8 @@ public class CassandraDataAutoConfigurationIntegrationTests {
private
void
createTestKeyspaceIfNotExists
()
{
private
void
createTestKeyspaceIfNotExists
()
{
Cluster
cluster
=
Cluster
.
builder
().
withoutJMXReporting
()
Cluster
cluster
=
Cluster
.
builder
().
withoutJMXReporting
()
.
withPort
(
cassandra
.
getMappedPort
()).
addContactPoint
(
"localhost"
).
build
();
.
withPort
(
cassandra
.
getFirstMappedPort
()).
addContactPoint
(
"localhost"
)
.
build
();
try
(
Session
session
=
cluster
.
connect
())
{
try
(
Session
session
=
cluster
.
connect
())
{
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
+
" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
);
+
" WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java
deleted
100644 → 0
View file @
8426d885
/*
* Copyright 2012-2018 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.
*/
package
org
.
springframework
.
boot
.
testsupport
.
testcontainers
;
import
java.time.Duration
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.TimeUnit
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.exceptions.NoHostAvailableException
;
import
org.rnorth.ducttape.TimeoutException
;
import
org.rnorth.ducttape.unreliables.Unreliables
;
import
org.testcontainers.containers.GenericContainer
;
import
org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
;
/**
* A {@link GenericContainer} for Cassandra.
*
* @author Andy Wilkinson
* @author Madhura Bhave
*/
public
class
CassandraContainer
extends
Container
{
private
static
final
int
PORT
=
9042
;
public
CassandraContainer
()
{
super
(
"cassandra:3.11.1"
,
PORT
,
(
container
)
->
container
.
waitingFor
(
new
WaitStrategy
(
container
))
.
withStartupAttempts
(
5
)
.
withStartupTimeout
(
Duration
.
ofSeconds
(
120
)));
}
private
static
final
class
WaitStrategy
extends
HostPortWaitStrategy
{
private
final
GenericContainer
<?>
container
;
private
WaitStrategy
(
GenericContainer
<?>
container
)
{
this
.
container
=
container
;
}
@Override
public
void
waitUntilReady
()
{
super
.
waitUntilReady
();
try
{
Unreliables
.
retryUntilTrue
((
int
)
this
.
startupTimeout
.
getSeconds
(),
TimeUnit
.
SECONDS
,
checkConnection
());
}
catch
(
TimeoutException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
private
Callable
<
Boolean
>
checkConnection
()
{
return
()
->
{
try
(
Cluster
cluster
=
Cluster
.
builder
().
withoutJMXReporting
()
.
withPort
(
this
.
container
.
getMappedPort
(
CassandraContainer
.
PORT
))
.
addContactPoint
(
"localhost"
).
build
())
{
cluster
.
connect
();
return
true
;
}
catch
(
IllegalArgumentException
|
NoHostAvailableException
ex
)
{
return
false
;
}
};
}
}
}
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