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
c9f04c39
Commit
c9f04c39
authored
Apr 24, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid race between container starting and getting mapped port
parent
f6cc1cbd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
CassandraContainer.java
...k/boot/testsupport/testcontainers/CassandraContainer.java
+9
-7
Neo4jContainer.java
...ework/boot/testsupport/testcontainers/Neo4jContainer.java
+8
-8
No files found.
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/CassandraContainer.java
View file @
c9f04c39
...
...
@@ -38,17 +38,18 @@ 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
.
getMappedPort
(
PORT
)))
.
withStartupAttempts
(
3
).
withStartupTimeout
(
Duration
.
ofSeconds
(
60
)));
super
(
"cassandra:3.11.1"
,
PORT
,
(
container
)
->
container
.
waitingFor
(
new
WaitStrategy
(
container
))
.
withStartupAttempts
(
3
)
.
withStartupTimeout
(
Duration
.
ofSeconds
(
60
)));
}
private
static
final
class
WaitStrategy
extends
HostPortWaitStrategy
{
private
final
int
port
;
private
final
GenericContainer
<?>
container
;
private
WaitStrategy
(
int
port
)
{
this
.
port
=
port
;
private
WaitStrategy
(
GenericContainer
<?>
container
)
{
this
.
container
=
container
;
}
@Override
...
...
@@ -66,7 +67,8 @@ public class CassandraContainer extends Container {
private
Callable
<
Boolean
>
checkConnection
()
{
return
()
->
{
try
(
Cluster
cluster
=
Cluster
.
builder
().
withPort
(
this
.
port
)
try
(
Cluster
cluster
=
Cluster
.
builder
()
.
withPort
(
this
.
container
.
getMappedPort
(
CassandraContainer
.
PORT
))
.
addContactPoint
(
"localhost"
).
build
())
{
cluster
.
connect
();
return
true
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/Neo4jContainer.java
View file @
c9f04c39
...
...
@@ -37,25 +37,25 @@ public class Neo4jContainer extends Container {
private
static
final
int
PORT
=
7687
;
public
Neo4jContainer
()
{
super
(
"neo4j:3.3.1"
,
PORT
,
(
container
)
->
container
.
waitingFor
(
new
WaitStrategy
(
container
.
getMappedPort
(
PORT
)))
.
withEnv
(
"NEO4J_AUTH"
,
"none"
));
super
(
"neo4j:3.3.1"
,
PORT
,
(
container
)
->
container
.
waitingFor
(
new
WaitStrategy
(
container
)).
withEnv
(
"NEO4J_AUTH"
,
"none"
));
}
private
static
final
class
WaitStrategy
extends
HostPortWaitStrategy
{
private
final
int
port
;
private
final
GenericContainer
<?>
container
;
private
WaitStrategy
(
int
port
)
{
this
.
port
=
port
;
private
WaitStrategy
(
GenericContainer
<?>
container
)
{
this
.
container
=
container
;
}
@Override
public
void
waitUntilReady
()
{
super
.
waitUntilReady
();
Configuration
configuration
=
new
Configuration
.
Builder
()
.
uri
(
"bolt://localhost:"
+
this
.
port
).
build
();
.
uri
(
"bolt://localhost:"
+
this
.
container
.
getMappedPort
(
Neo4jContainer
.
PORT
))
.
build
();
SessionFactory
sessionFactory
=
new
SessionFactory
(
configuration
,
"org.springframework.boot.test.autoconfigure.data.neo4j"
);
try
{
...
...
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