|
|
@ -88,6 +88,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("foo");
|
|
|
|
assertThat(cf.getDatabase()).isEqualTo(1);
|
|
|
|
assertThat(cf.getDatabase()).isEqualTo(1);
|
|
|
|
|
|
|
|
assertThat(getUserName(cf)).isNull();
|
|
|
|
assertThat(cf.getPassword()).isNull();
|
|
|
|
assertThat(cf.getPassword()).isNull();
|
|
|
|
assertThat(cf.isUseSsl()).isFalse();
|
|
|
|
assertThat(cf.isUseSsl()).isFalse();
|
|
|
|
assertThat(cf.getShutdownTimeout()).isEqualTo(500);
|
|
|
|
assertThat(cf.getShutdownTimeout()).isEqualTo(500);
|
|
|
@ -110,6 +111,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
|
|
|
|
assertThat(getUserName(cf)).isEqualTo("user");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(cf.isUseSsl()).isFalse();
|
|
|
|
assertThat(cf.isUseSsl()).isFalse();
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -124,6 +126,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
|
|
|
|
assertThat(getUserName(cf)).isEqualTo("user");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(cf.isUseSsl()).isTrue();
|
|
|
|
assertThat(cf.isUseSsl()).isTrue();
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -135,6 +138,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
|
|
|
|
assertThat(getUserName(cf)).isEqualTo("");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("pass:word");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo("pass:word");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,6 +149,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getHostName()).isEqualTo("example");
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
assertThat(cf.getPort()).isEqualTo(33);
|
|
|
|
|
|
|
|
assertThat(getUserName(cf)).isEqualTo("user");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo(":pass:word");
|
|
|
|
assertThat(cf.getPassword()).isEqualTo(":pass:word");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -237,10 +242,12 @@ class RedisAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testRedisConfigurationWithSentinelAndDataNodePassword() {
|
|
|
|
void testRedisConfigurationWithSentinelAndAuthentication() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.password=password", "spring.redis.sentinel.master:mymaster",
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.username=user", "spring.redis.password=password",
|
|
|
|
|
|
|
|
"spring.redis.sentinel.master:mymaster",
|
|
|
|
"spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
|
|
|
|
"spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
|
|
|
|
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(getUserName(connectionFactory)).isEqualTo("user");
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
|
|
|
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
|
|
|
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
|
|
|
assertThat(sentinelConfiguration.getSentinelPassword().isPresent()).isFalse();
|
|
|
|
assertThat(sentinelConfiguration.getSentinelPassword().isPresent()).isFalse();
|
|
|
@ -256,6 +263,7 @@ class RedisAutoConfigurationTests {
|
|
|
|
"spring.redis.sentinel.master:mymaster",
|
|
|
|
"spring.redis.sentinel.master:mymaster",
|
|
|
|
"spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
|
|
|
|
"spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
|
|
|
|
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(getUserName(connectionFactory)).isNull();
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
|
|
|
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
|
|
|
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
|
|
|
assertThat(new String(sentinelConfiguration.getSentinelPassword().get())).isEqualTo("secret");
|
|
|
|
assertThat(new String(sentinelConfiguration.getSentinelPassword().get())).isEqualTo("secret");
|
|
|
@ -292,14 +300,15 @@ class RedisAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testRedisConfigurationWithClusterAndPassword() {
|
|
|
|
void testRedisConfigurationWithClusterAndAuthentication() {
|
|
|
|
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
|
|
|
|
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withPropertyValues("spring.redis.username=user", "spring.redis.password=password",
|
|
|
|
.withPropertyValues("spring.redis.password=password",
|
|
|
|
|
|
|
|
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
|
|
|
|
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
|
|
|
|
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1))
|
|
|
|
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)).run((context) -> {
|
|
|
|
.run((context) -> assertThat(context.getBean(LettuceConnectionFactory.class).getPassword())
|
|
|
|
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
|
|
|
.isEqualTo("password")
|
|
|
|
assertThat(getUserName(connectionFactory)).isEqualTo("user");
|
|
|
|
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -393,6 +402,10 @@ class RedisAutoConfigurationTests {
|
|
|
|
return (LettucePoolingClientConfiguration) ReflectionTestUtils.getField(factory, "clientConfiguration");
|
|
|
|
return (LettucePoolingClientConfiguration) ReflectionTestUtils.getField(factory, "clientConfiguration");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getUserName(LettuceConnectionFactory factory) {
|
|
|
|
|
|
|
|
return ReflectionTestUtils.invokeMethod(factory, "getRedisUsername");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
static class CustomConfiguration {
|
|
|
|
static class CustomConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|