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
1a839d66
Commit
1a839d66
authored
Jun 27, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove useless cluster check
parent
1b181b2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
94 deletions
+12
-94
RedisAutoConfigurationJedisTests.java
...onfigure/data/redis/RedisAutoConfigurationJedisTests.java
+8
-48
RedisAutoConfigurationTests.java
...autoconfigure/data/redis/RedisAutoConfigurationTests.java
+4
-46
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java
View file @
1a839d66
...
...
@@ -22,7 +22,6 @@ import java.util.List;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
redis.clients.jedis.Jedis
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
...
...
@@ -120,23 +119,19 @@ public class RedisAutoConfigurationJedisTests {
@Test
public
void
testRedisConfigurationWithSentinel
()
throws
Exception
{
List
<
String
>
sentinels
=
Arrays
.
asList
(
"127.0.0.1:26379"
,
"127.0.0.1:26380"
);
if
(
isAtLeastOneNodeAvailable
(
sentinels
))
{
load
(
"spring.redis.sentinel.master:mymaster"
,
"spring.redis.sentinel.nodes:"
+
StringUtils
.
collectionToCommaDelimitedString
(
sentinels
));
assertThat
(
this
.
context
.
getBean
(
JedisConnectionFactory
.
class
)
.
isRedisSentinelAware
()).
isTrue
();
}
load
(
"spring.redis.sentinel.master:mymaster"
,
"spring.redis.sentinel.nodes:"
+
StringUtils
.
collectionToCommaDelimitedString
(
sentinels
));
assertThat
(
this
.
context
.
getBean
(
JedisConnectionFactory
.
class
)
.
isRedisSentinelAware
()).
isTrue
();
}
@Test
public
void
testRedisConfigurationWithCluster
()
throws
Exception
{
List
<
String
>
clusterNodes
=
Arrays
.
asList
(
"127.0.0.1:27379"
,
"127.0.0.1:27380"
);
if
(
isAtLeastOneNodeAvailable
(
clusterNodes
))
{
load
(
"spring.redis.cluster.nodes[0]:"
+
clusterNodes
.
get
(
0
),
"spring.redis.cluster.nodes[1]:"
+
clusterNodes
.
get
(
1
));
assertThat
(
this
.
context
.
getBean
(
JedisConnectionFactory
.
class
)
.
getClusterConnection
()).
isNotNull
();
}
load
(
"spring.redis.cluster.nodes[0]:"
+
clusterNodes
.
get
(
0
),
"spring.redis.cluster.nodes[1]:"
+
clusterNodes
.
get
(
1
));
assertThat
(
this
.
context
.
getBean
(
JedisConnectionFactory
.
class
)
.
getClusterConnection
()).
isNotNull
();
}
private
void
load
(
String
...
environment
)
{
...
...
@@ -154,41 +149,6 @@ public class RedisAutoConfigurationJedisTests {
this
.
context
=
ctx
;
}
private
boolean
isAtLeastOneNodeAvailable
(
List
<
String
>
nodes
)
{
for
(
String
node
:
nodes
)
{
if
(
isAvailable
(
node
))
{
return
true
;
}
}
return
false
;
}
private
boolean
isAvailable
(
String
node
)
{
Jedis
jedis
=
null
;
try
{
String
[]
hostAndPort
=
node
.
split
(
":"
);
jedis
=
new
Jedis
(
hostAndPort
[
0
],
Integer
.
valueOf
(
hostAndPort
[
1
]));
jedis
.
connect
();
jedis
.
ping
();
return
true
;
}
catch
(
Exception
ex
)
{
return
false
;
}
finally
{
if
(
jedis
!=
null
)
{
try
{
jedis
.
disconnect
();
jedis
.
close
();
}
catch
(
Exception
ex
)
{
// Continue
}
}
}
}
@Configuration
static
class
CustomConfiguration
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java
View file @
1a839d66
...
...
@@ -18,11 +18,7 @@ package org.springframework.boot.autoconfigure.data.redis;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
io.lettuce.core.RedisClient
;
import
io.lettuce.core.RedisURI
;
import
io.lettuce.core.api.StatefulRedisConnection
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -146,12 +142,10 @@ public class RedisAutoConfigurationTests {
@Test
public
void
testRedisConfigurationWithSentinel
()
throws
Exception
{
List
<
String
>
sentinels
=
Arrays
.
asList
(
"127.0.0.1:26379"
,
"127.0.0.1:26380"
);
if
(
isAtLeastOneNodeAvailable
(
sentinels
))
{
load
(
"spring.redis.sentinel.master:mymaster"
,
"spring.redis.sentinel.nodes:"
+
StringUtils
.
collectionToCommaDelimitedString
(
sentinels
));
assertThat
(
this
.
context
.
getBean
(
LettuceConnectionFactory
.
class
)
.
isRedisSentinelAware
()).
isTrue
();
}
load
(
"spring.redis.sentinel.master:mymaster"
,
"spring.redis.sentinel.nodes:"
+
StringUtils
.
collectionToCommaDelimitedString
(
sentinels
));
assertThat
(
this
.
context
.
getBean
(
LettuceConnectionFactory
.
class
)
.
isRedisSentinelAware
()).
isTrue
();
}
@Test
...
...
@@ -167,42 +161,6 @@ public class RedisAutoConfigurationTests {
return
(
DefaultLettucePool
)
ReflectionTestUtils
.
getField
(
factory
,
"pool"
);
}
private
boolean
isAtLeastOneNodeAvailable
(
List
<
String
>
nodes
)
{
for
(
String
node
:
nodes
)
{
if
(
isAvailable
(
node
))
{
return
true
;
}
}
return
false
;
}
private
boolean
isAvailable
(
String
node
)
{
RedisClient
redisClient
=
null
;
try
{
String
[]
hostAndPort
=
node
.
split
(
":"
);
redisClient
=
RedisClient
.
create
(
new
RedisURI
(
hostAndPort
[
0
],
Integer
.
valueOf
(
hostAndPort
[
1
]),
10
,
TimeUnit
.
SECONDS
));
StatefulRedisConnection
<
String
,
String
>
connection
=
redisClient
.
connect
();
connection
.
sync
().
ping
();
connection
.
close
();
return
true
;
}
catch
(
Exception
ex
)
{
return
false
;
}
finally
{
if
(
redisClient
!=
null
)
{
try
{
redisClient
.
shutdown
(
0
,
0
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
ex
)
{
// Continue
}
}
}
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
...
...
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