Factor JredisPool to a common Pool interface

This commit is contained in:
Jennifer Hickey
2013-06-23 16:39:30 -07:00
parent 83b87b663e
commit bae8a579d5
12 changed files with 309 additions and 263 deletions

View File

@@ -92,7 +92,7 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
@Test
public void testConnectionStaysOpenWhenPooled() {
JredisConnectionFactory factory2 = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
RedisConnection conn2 = factory2.getConnection();
conn2.close();
@@ -104,7 +104,7 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
Config config = new Config();
config.maxActive = 1;
config.maxWait = 1;
JredisConnectionFactory factory2 = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort(), config));
RedisConnection conn2 = factory2.getConnection();
((JRedis) conn2.getNativeConnection()).quit();

View File

@@ -15,7 +15,11 @@
*/
package org.springframework.data.redis.connection.jredis;
import org.jredis.ClientRuntimeException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
import org.apache.commons.pool.impl.GenericObjectPool.Config;
import org.jredis.JRedis;
import org.jredis.RedisException;
import org.jredis.connector.ConnectionSpec;
@@ -25,19 +29,15 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.apache.commons.pool.impl.GenericObjectPool.Config;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNotNull;
import org.springframework.data.redis.connection.PoolException;
/**
* Integration test of {@link DefaultJredisPool}
* Integration test of {@link JredisPool}
*
* @author Jennifer Hickey
*
*/
public class DefaultJredisPoolTests {
public class JredisPoolTests {
private ConnectionSpec connectionSpec;
@@ -58,7 +58,7 @@ public class DefaultJredisPoolTests {
@Test
public void testGetResource() throws RedisException {
this.pool = new DefaultJredisPool(connectionSpec);
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
client.ping();
@@ -69,13 +69,13 @@ public class DefaultJredisPoolTests {
Config poolConfig = new Config();
poolConfig.maxActive = 1;
poolConfig.maxWait = 1;
this.pool = new DefaultJredisPool(connectionSpec, poolConfig);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
try {
pool.getResource();
fail("ClientRuntimeException should be thrown when pool exhausted");
} catch (ClientRuntimeException e) {
fail("PoolException should be thrown when pool exhausted");
} catch (PoolException e) {
}
}
@@ -84,16 +84,16 @@ public class DefaultJredisPoolTests {
public void testGetResourceValidate() {
Config poolConfig = new Config();
poolConfig.testOnBorrow = true;
this.pool = new DefaultJredisPool(connectionSpec, poolConfig);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
}
@Test(expected = ClientRuntimeException.class)
@Test(expected = PoolException.class)
public void testGetResourceCreationUnsuccessful() {
// Config poolConfig = new Config();
// poolConfig.testOnBorrow = true;
this.pool = new DefaultJredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0,
this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0,
null));
pool.getResource();
}
@@ -103,7 +103,7 @@ public class DefaultJredisPoolTests {
Config poolConfig = new Config();
poolConfig.maxActive = 1;
poolConfig.maxWait = 1;
this.pool = new DefaultJredisPool(connectionSpec);
this.pool = new JredisPool(connectionSpec);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnResource(client);
@@ -115,7 +115,7 @@ public class DefaultJredisPoolTests {
Config poolConfig = new Config();
poolConfig.maxActive = 1;
poolConfig.maxWait = 1;
this.pool = new DefaultJredisPool(connectionSpec, poolConfig);
this.pool = new JredisPool(connectionSpec, poolConfig);
JRedis client = pool.getResource();
assertNotNull(client);
pool.returnBrokenResource(client);
@@ -130,13 +130,13 @@ public class DefaultJredisPoolTests {
@Test
public void testCreateWithHostAndPort() {
this.pool = new DefaultJredisPool(SettingsUtils.getHost(), SettingsUtils.getPort());
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort());
assertNotNull(pool.getResource());
}
@Test
public void testCreateWithHostPortAndDbIndex() {
this.pool = new DefaultJredisPool(SettingsUtils.getHost(), SettingsUtils.getPort(), 1, null, 0);
this.pool = new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort(), 1, null, 0);
assertNotNull(pool.getResource());
}

View File

@@ -20,7 +20,7 @@ import java.util.Collection;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.DefaultJredisPool;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
@@ -40,7 +40,7 @@ public abstract class AtomicCountersParam {
jedisConnFactory.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();

View File

@@ -21,7 +21,7 @@ import java.util.Collection;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.DefaultJredisPool;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
@@ -81,7 +81,7 @@ public abstract class CollectionTestParams {
jsonPersonTemplate.afterPropertiesSet();
// jredis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();

View File

@@ -22,7 +22,7 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.DefaultJredisPool;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
@@ -93,7 +93,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
jsonPersonTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();

View File

@@ -38,7 +38,7 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.DefaultJredisPool;
import org.springframework.data.redis.connection.jredis.JredisPool;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
@@ -262,7 +262,7 @@ public class RedisPropertiesTests extends RedisMapTests {
jsonPersonTemplate.afterPropertiesSet();
// JRedis
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new DefaultJredisPool(
JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(
SettingsUtils.getHost(), SettingsUtils.getPort()));
jredisConnFactory.afterPropertiesSet();