DATAREDIS-315 - Remove timeout/password from RedisClusterConfiguration.

Removed duplicate configuration options for timeout and password from RedisClusterConfiguration and use the ones provided via the RedisConnectionFactory.

Original pull request: #158.
This commit is contained in:
Christoph Strobl
2016-02-05 10:49:38 +01:00
committed by Mark Paluch
parent 0ac118fcc0
commit 008836066f
6 changed files with 73 additions and 76 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -50,7 +50,6 @@ public class RedisClusterConfigurationUnitTests {
assertThat(config.getClusterNodes().size(), is(1));
assertThat(config.getClusterNodes(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getClusterTimeout(), nullValue());
assertThat(config.getMaxRedirects(), nullValue());
}
@@ -112,7 +111,6 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(new MockPropertySource());
assertThat(config.getMaxRedirects(), nullValue());
assertThat(config.getClusterTimeout(), nullValue());
assertThat(config.getClusterNodes().size(), is(0));
}
@@ -123,17 +121,13 @@ public class RedisClusterConfigurationUnitTests {
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithSingleHostPort() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.cluster.timeout", "10");
propertySource.setProperty("spring.redis.cluster.nodes", HOST_AND_PORT_1);
propertySource.setProperty("spring.redis.cluster.max-redirects", "5");
propertySource.setProperty("spring.redis.cluster.password", "foobar");
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
assertThat(config.getMaxRedirects(), is(5));
assertThat(config.getClusterTimeout(), is(10L));
assertThat(config.getClusterNodes(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getPassword(), is("foobar"));
}
/**
@@ -143,7 +137,6 @@ public class RedisClusterConfigurationUnitTests {
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMultipleHostPort() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.cluster.timeout", "10");
propertySource.setProperty("spring.redis.cluster.nodes",
StringUtils.collectionToCommaDelimitedString(Arrays.asList(HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
propertySource.setProperty("spring.redis.cluster.max-redirects", "5");
@@ -151,7 +144,6 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
assertThat(config.getMaxRedirects(), is(5));
assertThat(config.getClusterTimeout(), is(10L));
assertThat(config.getClusterNodes(),
hasItems(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456), new RedisNode("localhost", 789)));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@@ -15,13 +15,20 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.junit.Assert.*;
import static org.springframework.test.util.ReflectionTestUtils.*;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import com.lambdaworks.redis.AbstractRedisClient;
import com.lambdaworks.redis.RedisURI;
import com.lambdaworks.redis.cluster.RedisClusterClient;
/**
@@ -29,8 +36,12 @@ import com.lambdaworks.redis.cluster.RedisClusterClient;
*/
public class LettuceConnectionFactoryUnitTests {
private static final RedisClusterConfiguration CLUSTER_CONFIG = new RedisClusterConfiguration().clusterNode(
"127.0.0.1", 6379).clusterNode("127.0.0.1", 6380);
RedisClusterConfiguration clusterConfig;
@Before
public void setUp() {
clusterConfig = new RedisClusterConfiguration().clusterNode("127.0.0.1", 6379).clusterNode("127.0.0.1", 6380);
}
/**
* @see DATAREDIS-315
@@ -38,9 +49,52 @@ public class LettuceConnectionFactoryUnitTests {
@Test
public void shouldInitClientCorrectlyWhenClusterConfigPresent() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(CLUSTER_CONFIG);
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.afterPropertiesSet();
assertThat(getField(connectionFactory, "client"), instanceOf(RedisClusterClient.class));
}
/**
* @see DATAREDIS-315
*/
@Test
@SuppressWarnings("unchecked")
public void timeoutShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setTimeout(1000);
connectionFactory.afterPropertiesSet();
AbstractRedisClient client = (AbstractRedisClient) getField(connectionFactory, "client");
assertThat(client, instanceOf(RedisClusterClient.class));
Iterable<RedisURI> initialUris = (Iterable<RedisURI>) getField(client, "initialUris");
for (RedisURI uri : initialUris) {
assertThat(uri.getTimeout(), is(equalTo(connectionFactory.getTimeout())));
assertThat(uri.getUnit(), is(equalTo(TimeUnit.MILLISECONDS)));
}
}
/**
* @see DATAREDIS-315
*/
@Test
@SuppressWarnings("unchecked")
public void passwordShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setPassword("o_O");
connectionFactory.afterPropertiesSet();
AbstractRedisClient client = (AbstractRedisClient) getField(connectionFactory, "client");
assertThat(client, instanceOf(RedisClusterClient.class));
Iterable<RedisURI> initialUris = (Iterable<RedisURI>) getField(client, "initialUris");
for (RedisURI uri : initialUris) {
assertThat(uri.getPassword(), is(equalTo(connectionFactory.getPassword().toCharArray())));
}
}
}