Wrap native Exceptions in LettuceConnectionFactory

DATAREDIS-191

- Wrap native Exceptions in RedisConnectionFailureExceptions 

- Support switching from shared to non-shared connection
by resetting shared connection in afterPropertiesSet
This commit is contained in:
Jennifer Hickey
2013-06-04 11:54:21 -07:00
parent 931f0ff44c
commit 66139f9fae
2 changed files with 53 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotSame;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
@@ -169,4 +170,44 @@ public class LettuceConnectionFactoryTests {
factory.initConnection();
assertNotSame(nativeConn, factory.getConnection().getNativeConnection());
}
@Test(expected=RedisConnectionFailureException.class)
public void testInitConnectionException() {
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
}
@Test(expected=RedisConnectionFailureException.class)
public void testGetConnectionNotSharedException() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
factory.getConnection();
}
@Test(expected=RedisConnectionFailureException.class)
public void testGetConnectionSharedException() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
factory.setShareNativeConnection(true);
factory.getConnection();
}
@Test(expected=RedisConnectionFailureException.class)
public void testGetNativeConnectionNotSharedException() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
factory.getNativeConnection();
}
@Test(expected=RedisConnectionFailureException.class)
public void testGetNativeConnectionSharedException() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
factory.setShareNativeConnection(true);
factory.getNativeConnection();
}
}