diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index 58007349c20..2c07082246f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -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 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 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 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 { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java index ead5c4c3173..9c2b04e3977 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java @@ -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 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 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 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); }