Merge pull request #43774 from hezean

* pr/43774:
  Polish "Prevent redis pool to initialize in unit test"
  Prevent redis pool to initialize in unit test

Closes gh-43774
This commit is contained in:
Stéphane Nicoll 2025-01-11 12:52:53 +01:00
commit 9a10c1a671
1 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -152,18 +152,20 @@ class RedisAutoConfigurationJedisTests {
@Test @Test
void testRedisConfigurationWithPool() { void testRedisConfigurationWithPool() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.data.redis.host:foo", "spring.data.redis.jedis.pool.min-idle:1", .withPropertyValues("spring.data.redis.host:foo", "spring.data.redis.jedis.pool.min-idle:0",
"spring.data.redis.jedis.pool.max-idle:4", "spring.data.redis.jedis.pool.max-active:16", "spring.data.redis.jedis.pool.max-idle:4", "spring.data.redis.jedis.pool.max-active:16",
"spring.data.redis.jedis.pool.max-wait:2000", "spring.data.redis.jedis.pool.max-wait:2000",
"spring.data.redis.jedis.pool.time-between-eviction-runs:30000") "spring.data.redis.jedis.pool.time-between-eviction-runs:30000")
.run((context) -> { .run((context) -> {
JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class); JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo"); assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(cf.getPoolConfig().getMinIdle()).isOne(); assertThat(cf.getPoolConfig()).satisfies((poolConfig) -> {
assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4); assertThat(poolConfig.getMinIdle()).isEqualTo(0);
assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16); assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
assertThat(cf.getPoolConfig().getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2)); assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
assertThat(cf.getPoolConfig().getDurationBetweenEvictionRuns()).isEqualTo(Duration.ofSeconds(30)); assertThat(poolConfig.getMaxWaitDuration()).isEqualTo(Duration.ofSeconds(2));
assertThat(poolConfig.getDurationBetweenEvictionRuns()).isEqualTo(Duration.ofSeconds(30));
});
}); });
} }