|
19 | 19 | import static org.mockito.Mockito.*;
|
20 | 20 |
|
21 | 21 | import redis.clients.jedis.DefaultJedisClientConfig;
|
| 22 | +import redis.clients.jedis.Jedis; |
22 | 23 | import redis.clients.jedis.JedisClientConfig;
|
23 | 24 | import redis.clients.jedis.JedisCluster;
|
24 | 25 | import redis.clients.jedis.JedisPoolConfig;
|
25 | 26 | import redis.clients.jedis.RedisProtocol;
|
| 27 | +import redis.clients.jedis.util.Pool; |
26 | 28 |
|
27 | 29 | import java.io.IOException;
|
28 | 30 | import java.security.NoSuchAlgorithmException;
|
@@ -265,6 +267,28 @@ void shouldApplyClientConfiguration() throws NoSuchAlgorithmException {
|
265 | 267 | assertThat(connectionFactory.getPoolConfig()).isSameAs(poolConfig);
|
266 | 268 | }
|
267 | 269 |
|
| 270 | + @Test // GH-3072 |
| 271 | + void shouldInitializePool() throws Exception { |
| 272 | + |
| 273 | + JedisPoolConfig poolConfig = new JedisPoolConfig(); |
| 274 | + Pool<Jedis> poolMock = mock(Pool.class); |
| 275 | + |
| 276 | + JedisClientConfiguration configuration = JedisClientConfiguration.builder() // |
| 277 | + .usePooling().poolConfig(poolConfig) // |
| 278 | + .build(); |
| 279 | + |
| 280 | + connectionFactory = new JedisConnectionFactory(new RedisStandaloneConfiguration(), configuration) { |
| 281 | + @Override |
| 282 | + protected Pool<Jedis> createRedisPool() { |
| 283 | + return poolMock; |
| 284 | + } |
| 285 | + }; |
| 286 | + |
| 287 | + connectionFactory.afterPropertiesSet(); |
| 288 | + |
| 289 | + verify(poolMock).preparePool(); |
| 290 | + } |
| 291 | + |
268 | 292 | @Test // DATAREDIS-574
|
269 | 293 | void shouldReturnStandaloneConfiguration() {
|
270 | 294 |
|
@@ -382,12 +406,12 @@ void earlyStartupDoesNotStartConnectionFactory() {
|
382 | 406 | private JedisConnectionFactory initSpyedConnectionFactory(RedisSentinelConfiguration sentinelConfiguration,
|
383 | 407 | @Nullable JedisPoolConfig poolConfig) {
|
384 | 408 |
|
| 409 | + Pool<Jedis> poolMock = mock(Pool.class); |
385 | 410 | // we have to use a spy here as jedis would start connecting to redis sentinels when the pool is created.
|
386 | 411 | JedisConnectionFactory connectionFactorySpy = spy(new JedisConnectionFactory(sentinelConfiguration, poolConfig));
|
387 | 412 |
|
388 |
| - doReturn(null).when(connectionFactorySpy).createRedisSentinelPool(any(RedisSentinelConfiguration.class)); |
389 |
| - |
390 |
| - doReturn(null).when(connectionFactorySpy).createRedisPool(); |
| 413 | + doReturn(poolMock).when(connectionFactorySpy).createRedisSentinelPool(any(RedisSentinelConfiguration.class)); |
| 414 | + doReturn(poolMock).when(connectionFactorySpy).createRedisPool(); |
391 | 415 |
|
392 | 416 | return connectionFactorySpy;
|
393 | 417 | }
|
|
0 commit comments