Polishing.
Prepare pool for Jedis as well. Introduce generics for Add ticket references to tests. See #3072
This commit is contained in:
@@ -730,6 +730,12 @@ public class JedisConnectionFactory
|
||||
|
||||
if (getUsePool() && !isRedisClusterAware()) {
|
||||
this.pool = createPool();
|
||||
|
||||
try {
|
||||
this.pool.preparePool();
|
||||
} catch (Exception ex) {
|
||||
throw new PoolException("Could not prepare the pool", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (isRedisClusterAware()) {
|
||||
|
||||
@@ -97,7 +97,6 @@ class LettucePoolingConnectionProvider implements LettuceConnectionProvider, Red
|
||||
|
||||
try {
|
||||
newPool.preparePool();
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PoolException("Could not prepare the pool", ex);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import redis.clients.jedis.DefaultJedisClientConfig;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisClientConfig;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.RedisProtocol;
|
||||
import redis.clients.jedis.util.Pool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -265,6 +267,28 @@ class JedisConnectionFactoryUnitTests {
|
||||
assertThat(connectionFactory.getPoolConfig()).isSameAs(poolConfig);
|
||||
}
|
||||
|
||||
@Test // GH-3072
|
||||
void shouldInitializePool() throws Exception {
|
||||
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
Pool<Jedis> poolMock = mock(Pool.class);
|
||||
|
||||
JedisClientConfiguration configuration = JedisClientConfiguration.builder() //
|
||||
.usePooling().poolConfig(poolConfig) //
|
||||
.build();
|
||||
|
||||
connectionFactory = new JedisConnectionFactory(new RedisStandaloneConfiguration(), configuration) {
|
||||
@Override
|
||||
protected Pool<Jedis> createRedisPool() {
|
||||
return poolMock;
|
||||
}
|
||||
};
|
||||
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
verify(poolMock).preparePool();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-574
|
||||
void shouldReturnStandaloneConfiguration() {
|
||||
|
||||
@@ -382,12 +406,12 @@ class JedisConnectionFactoryUnitTests {
|
||||
private JedisConnectionFactory initSpyedConnectionFactory(RedisSentinelConfiguration sentinelConfiguration,
|
||||
@Nullable JedisPoolConfig poolConfig) {
|
||||
|
||||
Pool<Jedis> poolMock = mock(Pool.class);
|
||||
// we have to use a spy here as jedis would start connecting to redis sentinels when the pool is created.
|
||||
JedisConnectionFactory connectionFactorySpy = spy(new JedisConnectionFactory(sentinelConfiguration, poolConfig));
|
||||
|
||||
doReturn(null).when(connectionFactorySpy).createRedisSentinelPool(any(RedisSentinelConfiguration.class));
|
||||
|
||||
doReturn(null).when(connectionFactorySpy).createRedisPool();
|
||||
doReturn(poolMock).when(connectionFactorySpy).createRedisSentinelPool(any(RedisSentinelConfiguration.class));
|
||||
doReturn(poolMock).when(connectionFactorySpy).createRedisPool();
|
||||
|
||||
return connectionFactorySpy;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import io.lettuce.core.api.StatefulConnection;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.api.async.RedisAsyncCommands;
|
||||
|
||||
@@ -74,10 +75,10 @@ class LettucePoolingConnectionProviderUnitTests {
|
||||
verify(commandsMock).discard();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // GH-3072
|
||||
void shouldPrepareThePool() {
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
GenericObjectPoolConfig<StatefulConnection<?, ?>> poolConfig = new GenericObjectPoolConfig<>();
|
||||
poolConfig.setMinIdle(5);
|
||||
poolConfig.setMaxIdle(8);
|
||||
poolConfig.setMaxTotal(10);
|
||||
|
||||
Reference in New Issue
Block a user