From c6a2a4f7daf3aa00638fdc21bcb62542a11357b8 Mon Sep 17 00:00:00 2001 From: Jennifer Hickey Date: Mon, 19 Aug 2013 12:14:43 -0700 Subject: [PATCH] Temp revert "Lazily instantiate shared Lettuce connection" This reverts commit f9cdad751c15cf1dd70f4dd66c0d170cd049e612. --- .../lettuce/LettuceConnectionFactory.java | 4 ++++ .../LettuceConnectionFactoryTests.java | 22 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index e0e5be050..096c11e05 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -95,6 +95,10 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea public void afterPropertiesSet() { this.client = createRedisClient(); + resetConnection(); + if (shareNativeConnection) { + initConnection(); + } } public void destroy() { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index 4459f7ba5..e7f2601ff 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -174,21 +174,18 @@ public class LettuceConnectionFactoryTests { assertNotSame(nativeConn, factory.getConnection().getNativeConnection()); } - public void testGetConnectionException() { + @Test(expected=RedisConnectionFailureException.class) + public void testInitConnectionException() { factory.setHostName("fakeHost"); factory.afterPropertiesSet(); - try { - factory.getConnection(); - fail("Expected connection failure exception"); - } catch(RedisConnectionFailureException e) { - } } - @Test - public void testGetConnectionNotSharedBadHostname() { + @Test(expected=RedisConnectionFailureException.class) + public void testGetConnectionSharedException() { factory.setShareNativeConnection(false); factory.setHostName("fakeHost"); factory.afterPropertiesSet(); + factory.setShareNativeConnection(true); factory.getConnection(); } @@ -200,6 +197,15 @@ public class LettuceConnectionFactoryTests { assertNull(factory.getSharedConnection()); } + @Test(expected=RedisConnectionFailureException.class) + public void testGetSharedConnectionSharedException() { + factory.setShareNativeConnection(false); + factory.setHostName("fakeHost"); + factory.afterPropertiesSet(); + factory.setShareNativeConnection(true); + factory.getSharedConnection(); + } + @Test public void testCreateFactoryWithPool() { DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(),