|
|
|
@ -16,13 +16,14 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.data.redis;
|
|
|
|
|
|
|
|
|
|
import io.lettuce.core.RedisClient;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
|
@ -37,11 +38,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
* @author Mark Paluch
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
*/
|
|
|
|
|
@ClassPathExclusions("lettuce-core-*.jar")
|
|
|
|
|
class RedisAutoConfigurationJedisTests {
|
|
|
|
|
|
|
|
|
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class));
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
|
|
|
|
.withClassLoader(new FilteredClassLoader(RedisClient.class));
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void connectionFactoryDefaultsToJedis() {
|
|
|
|
@ -136,11 +137,23 @@ class RedisAutoConfigurationJedisTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationWithTimeout() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.timeout:100").run((context) -> {
|
|
|
|
|
void testRedisConfigurationWithTimeoutAndConnectionTimeout() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo", "spring.redis.timeout:250",
|
|
|
|
|
"spring.redis.connection-timeout:1000").run((context) -> {
|
|
|
|
|
JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class);
|
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
|
assertThat(cf.getTimeout()).isEqualTo(250);
|
|
|
|
|
assertThat(cf.getClientConfiguration().getConnectTimeout().toMillis()).isEqualTo(1000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRedisConfigurationWithDefaultTimeouts() {
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> {
|
|
|
|
|
JedisConnectionFactory cf = context.getBean(JedisConnectionFactory.class);
|
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
|
assertThat(cf.getTimeout()).isEqualTo(100);
|
|
|
|
|
assertThat(cf.getTimeout()).isEqualTo(2000);
|
|
|
|
|
assertThat(cf.getClientConfiguration().getConnectTimeout().toMillis()).isEqualTo(2000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|