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
fc3b43e8
Commit
fc3b43e8
authored
Jan 04, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wait for neo4j to start accepting connections
See gh-10516
parent
8001c6a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
DataNeo4jTestIntegrationTests.java
...toconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
+28
-5
DataNeo4jTestWithIncludeFilterIntegrationTests.java
...neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
+1
-1
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
View file @
fc3b43e8
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
neo4j
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
data
.
neo4j
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.junit.ClassRule
;
import
org.junit.ClassRule
;
...
@@ -23,7 +25,11 @@ import org.junit.Rule;
...
@@ -23,7 +25,11 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.neo4j.ogm.config.Configuration
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.Session
;
import
org.neo4j.ogm.session.SessionFactory
;
import
org.rnorth.ducttape.TimeoutException
;
import
org.rnorth.ducttape.unreliables.Unreliables
;
import
org.testcontainers.containers.FixedHostPortGenericContainer
;
import
org.testcontainers.containers.FixedHostPortGenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
import
org.testcontainers.containers.GenericContainer
;
import
org.testcontainers.containers.wait.HostPortWaitStrategy
;
import
org.testcontainers.containers.wait.HostPortWaitStrategy
;
...
@@ -49,7 +55,7 @@ public class DataNeo4jTestIntegrationTests {
...
@@ -49,7 +55,7 @@ public class DataNeo4jTestIntegrationTests {
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
GenericContainer
>
genericContainer
=
new
DockerTestContainer
<>((
Supplier
<
GenericContainer
>)
()
->
new
FixedHostPortGenericContainer
(
"neo4j:latest"
)
public
static
DockerTestContainer
<
GenericContainer
>
genericContainer
=
new
DockerTestContainer
<>((
Supplier
<
GenericContainer
>)
()
->
new
FixedHostPortGenericContainer
(
"neo4j:latest"
)
.
withFixedExposedPort
(
7687
,
7687
)
.
withFixedExposedPort
(
7687
,
7687
)
.
waitingFor
(
new
AdditionalSleep
WaitStrategy
()).
withEnv
(
"NEO4J_AUTH"
,
"none"
));
.
waitingFor
(
new
ConnectionVerifying
WaitStrategy
()).
withEnv
(
"NEO4J_AUTH"
,
"none"
));
@Rule
@Rule
...
@@ -80,18 +86,35 @@ public class DataNeo4jTestIntegrationTests {
...
@@ -80,18 +86,35 @@ public class DataNeo4jTestIntegrationTests {
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
this
.
applicationContext
.
getBean
(
ExampleService
.
class
);
}
}
static
class
AdditionalSleep
WaitStrategy
extends
HostPortWaitStrategy
{
static
class
ConnectionVerifying
WaitStrategy
extends
HostPortWaitStrategy
{
@Override
@Override
protected
void
waitUntilReady
()
{
protected
void
waitUntilReady
()
{
super
.
waitUntilReady
();
super
.
waitUntilReady
();
Configuration
configuration
=
new
Configuration
.
Builder
()
.
uri
(
"bolt://localhost:7687"
).
build
();
SessionFactory
sessionFactory
=
new
SessionFactory
(
configuration
,
"org.springframework.boot.test.autoconfigure.data.neo4j"
);
try
{
try
{
Thread
.
sleep
(
5000
);
Unreliables
.
retryUntilTrue
((
int
)
startupTimeout
.
getSeconds
(),
TimeUnit
.
SECONDS
,
checkConnection
(
sessionFactory
));
}
}
catch
(
Interrupted
Exception
e
)
{
catch
(
Timeout
Exception
e
)
{
Thread
.
currentThread
().
interrupt
();
throw
new
IllegalStateException
();
}
}
}
}
private
Callable
<
Boolean
>
checkConnection
(
SessionFactory
sessionFactory
)
{
return
()
->
{
try
{
sessionFactory
.
openSession
().
beginTransaction
().
close
();
return
true
;
}
catch
(
Exception
ex
)
{
return
false
;
}
};
}
}
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
View file @
fc3b43e8
...
@@ -44,7 +44,7 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
...
@@ -44,7 +44,7 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
@ClassRule
@ClassRule
public
static
DockerTestContainer
<
GenericContainer
>
genericContainer
=
new
DockerTestContainer
<>((
Supplier
<
GenericContainer
>)
()
->
new
FixedHostPortGenericContainer
(
"neo4j:latest"
)
public
static
DockerTestContainer
<
GenericContainer
>
genericContainer
=
new
DockerTestContainer
<>((
Supplier
<
GenericContainer
>)
()
->
new
FixedHostPortGenericContainer
(
"neo4j:latest"
)
.
withFixedExposedPort
(
7687
,
7687
)
.
withFixedExposedPort
(
7687
,
7687
)
.
waitingFor
(
new
DataNeo4jTestIntegrationTests
.
AdditionalSleep
WaitStrategy
()).
withEnv
(
"NEO4J_AUTH"
,
"none"
));
.
waitingFor
(
new
DataNeo4jTestIntegrationTests
.
ConnectionVerifying
WaitStrategy
()).
withEnv
(
"NEO4J_AUTH"
,
"none"
));
@Autowired
@Autowired
private
ExampleService
service
;
private
ExampleService
service
;
...
...
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