|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
* Copyright 2012-2021 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.
|
|
|
|
@ -65,6 +65,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
* @author Alen Turkovic
|
|
|
|
|
* @author Scott Frederick
|
|
|
|
|
* @author Weix Sun
|
|
|
|
|
*/
|
|
|
|
|
class RedisAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
@ -155,10 +156,25 @@ class RedisAutoConfigurationTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationWithPool() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.min-idle:1",
|
|
|
|
|
"spring.redis.lettuce.pool.max-idle:4", "spring.redis.lettuce.pool.max-active:16",
|
|
|
|
|
"spring.redis.lettuce.pool.max-wait:2000", "spring.redis.lettuce.pool.time-between-eviction-runs:30000",
|
|
|
|
|
void testRedisConfigurationWithPoolUsingDefaultValue() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.enabled:true")
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
|
GenericObjectPoolConfig<?> poolConfig = getPoolingClientConfiguration(cf).getPoolConfig();
|
|
|
|
|
assertThat(poolConfig.getMinIdle()).isEqualTo(0);
|
|
|
|
|
assertThat(poolConfig.getMaxIdle()).isEqualTo(8);
|
|
|
|
|
assertThat(poolConfig.getMaxTotal()).isEqualTo(8);
|
|
|
|
|
assertThat(poolConfig.getMaxWaitMillis()).isEqualTo(-1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationWithPoolUsingCustomValue() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.enabled:true",
|
|
|
|
|
"spring.redis.lettuce.pool.min-idle:1", "spring.redis.lettuce.pool.max-idle:4",
|
|
|
|
|
"spring.redis.lettuce.pool.max-active:16", "spring.redis.lettuce.pool.max-wait:2000",
|
|
|
|
|
"spring.redis.lettuce.pool.time-between-eviction-runs:30000",
|
|
|
|
|
"spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
|
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
@ -172,6 +188,17 @@ class RedisAutoConfigurationTests {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationDisabledPool() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.enabled:false")
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
|
assertThat(ReflectionTestUtils.getField(cf, "clientConfiguration"))
|
|
|
|
|
.isNotInstanceOf(LettucePoolingClientConfiguration.class);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationWithTimeoutAndConnectTimeout() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.timeout:250",
|
|
|
|
|