Extend properties for RedisSentinelConfiguration.

Closes #2860
Original pull request: #2861

Co-authored-by: Samuel Klose <39386136+samKl99@users.noreply.github.com>
This commit is contained in:
Mustapha Zorgati
2024-02-29 20:32:20 +01:00
committed by Mark Paluch
parent 9543076752
commit f9a763e55a
3 changed files with 87 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import org.assertj.core.api.ThrowableAssert;
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockPropertySource;
@@ -32,6 +33,8 @@ import org.springframework.util.StringUtils;
* @author Christoph Strobl
* @author Mark Paluch
* @author Vikas Garg
* @author Samuel Klose
* @author Mustapha Zorgati
*/
class RedisSentinelConfigurationUnitTests {
@@ -186,4 +189,56 @@ class RedisSentinelConfigurationUnitTests {
assertThat(config.getSentinelPassword()).isEqualTo(RedisPassword.of("foo"));
assertThat(config.getSentinels()).hasSize(1).contains(new RedisNode("127.0.0.1", 123));
}
@Test // GH-2860
void readSentinelDataNodeUsernameFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.username", "datanode-user");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
assertThat(config.getDataNodeUsername()).isEqualTo("datanode-user");
}
@Test // GH-2860
void readSentinelDataNodePasswordFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.password", "datanode-password");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
assertThat(config.getDataNodePassword()).isEqualTo(RedisPassword.of("datanode-password"));
}
@Test // GH-2860
void readSentinelDataNodeDatabaseFromConfigProperty() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "5");
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
assertThat(config.getDatabase()).isEqualTo(5);
}
@Test // GH-2860
void shouldThrowErrorWhen() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "thisIsNotAnInteger");
ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource);
assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid DB index '%s'; integer required", "thisIsNotAnInteger");
}
@Test // GH-2860
void shouldThrowErrorWhen2() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.sentinel.dataNode.database", "null");
ThrowableAssert.ThrowingCallable call = () -> new RedisSentinelConfiguration(propertySource);
assertThatThrownBy(call).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid DB index '%s'; integer required", "null");
}
}