From e94fa9a35ac5a9af4d35cf5cc7a89b73aacda5fe Mon Sep 17 00:00:00 2001 From: Jennifer Hickey Date: Fri, 16 Aug 2013 15:19:02 -0700 Subject: [PATCH] Throw translated Exception on SRP conn failure DATAREDIS-234 --- .../data/redis/connection/srp/SrpConnection.java | 2 ++ .../connection/srp/SrpConnectionFactoryTests.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index 41bb5b475..14eb75db7 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -210,6 +210,8 @@ public class SrpConnection implements RedisConnection { this.queue = queue; } catch (IOException e) { throw new RedisConnectionFailureException("Could not connect", e); + } catch(RedisException e) { + throw new RedisConnectionFailureException("Could not connect", e); } } diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java index 38a73313e..9c5837f7f 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java @@ -17,8 +17,10 @@ package org.springframework.data.redis.connection.srp; import org.junit.Ignore; import org.junit.Test; +import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.SettingsUtils; import org.springframework.data.redis.connection.RedisConnection; +import static org.junit.Assert.fail; /** * Integration test of {@link SrpConnectionFactory} @@ -37,6 +39,18 @@ public class SrpConnectionFactoryTests { connection.ping(); } + @Test + public void testConnectInvalidHost() { + SrpConnectionFactory factory = new SrpConnectionFactory(); + factory.setHostName("fakeHost"); + factory.afterPropertiesSet(); + try { + factory.getConnection(); + fail("Expected a connection failure exception"); + } catch(RedisConnectionFailureException e) { + } + } + @Ignore("Redis must have requirepass set to run this test") @Test public void testConnectWithPassword() {