DATAREDIS-261 - Upgrade to commons-pool2.
'JRedisPool' and 'DefaultLettucePool' have been migrated to 'commons-pool2'. 'PoolConfig' has been deprecated, and will be removed in '1.4', as all required operations are available via 'GenericObjectPoolConfig'. Along the way a minor bug within 'LettuceConnection' has been resolved, which prevented 'RedisAsyncConnections' from being properly closed/returned to pool. Original Pull Request: #50
This commit is contained in:
committed by
Thomas Darimont
parent
d116d3825a
commit
408b52a449
@@ -23,7 +23,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.jredis.JRedis;
|
||||
import org.jredis.protocol.BulkResponse;
|
||||
@@ -112,9 +112,9 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
|
||||
@Test
|
||||
public void testConnectionNotReturnedOnException() {
|
||||
Config config = new Config();
|
||||
config.maxActive = 1;
|
||||
config.maxWait = 1;
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setMaxWaitMillis(1);
|
||||
JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
|
||||
SettingsUtils.getPort(), config));
|
||||
RedisConnection conn2 = factory2.getConnection();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.jredis;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.jredis.JRedis;
|
||||
import org.jredis.RedisException;
|
||||
import org.jredis.connector.ConnectionSpec;
|
||||
@@ -27,13 +29,12 @@ import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.PoolException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Integration test of {@link JredisPool}
|
||||
* Integration test of {@link JredisPool}.
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class JredisPoolTests {
|
||||
|
||||
@@ -63,9 +64,9 @@ public class JredisPoolTests {
|
||||
|
||||
@Test
|
||||
public void testGetResourcePoolExhausted() {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new JredisPool(connectionSpec, poolConfig);
|
||||
JRedis client = pool.getResource();
|
||||
assertNotNull(client);
|
||||
@@ -79,8 +80,8 @@ public class JredisPoolTests {
|
||||
|
||||
@Test
|
||||
public void testGetResourceValidate() {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.testOnBorrow = true;
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setTestOnBorrow(true);
|
||||
this.pool = new JredisPool(connectionSpec, poolConfig);
|
||||
JRedis client = pool.getResource();
|
||||
assertNotNull(client);
|
||||
@@ -96,9 +97,10 @@ public class JredisPoolTests {
|
||||
|
||||
@Test
|
||||
public void testReturnResource() throws RedisException {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new JredisPool(connectionSpec);
|
||||
JRedis client = pool.getResource();
|
||||
assertNotNull(client);
|
||||
@@ -108,9 +110,10 @@ public class JredisPoolTests {
|
||||
|
||||
@Test
|
||||
public void testReturnBrokenResource() throws RedisException {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new JredisPool(connectionSpec, poolConfig);
|
||||
JRedis client = pool.getResource();
|
||||
assertNotNull(client);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -25,13 +25,15 @@ import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.PoolConfig;
|
||||
import org.springframework.data.redis.connection.PoolException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultLettucePool}
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultLettucePoolTests {
|
||||
|
||||
@@ -61,9 +63,9 @@ public class DefaultLettucePoolTests {
|
||||
|
||||
@Test
|
||||
public void testGetResourcePoolExhausted() {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
@@ -96,9 +98,9 @@ public class DefaultLettucePoolTests {
|
||||
|
||||
@Test
|
||||
public void testReturnResource() {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
@@ -110,9 +112,9 @@ public class DefaultLettucePoolTests {
|
||||
|
||||
@Test
|
||||
public void testReturnBrokenResource() {
|
||||
Config poolConfig = new Config();
|
||||
poolConfig.maxActive = 1;
|
||||
poolConfig.maxWait = 1;
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
this.pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.afterPropertiesSet();
|
||||
RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
|
||||
|
||||
@@ -95,7 +95,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
|
||||
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
|
||||
|
||||
JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
|
||||
jedisConnFactory.getPoolConfig().setMaxTotal(defaultPoolConfig.maxActive);
|
||||
jedisConnFactory.getPoolConfig().setMaxTotal(defaultPoolConfig.getMaxTotal());
|
||||
jedisConnFactory.setUsePool(true);
|
||||
jedisConnFactory.setPort(SettingsUtils.getPort());
|
||||
jedisConnFactory.setHostName(SettingsUtils.getHost());
|
||||
|
||||
Reference in New Issue
Block a user