DATAREDIS-661 - Refactor RedisServerCommands.getConfig(…) output to Properties.
Use Properties instead of List of Strings arranged as sequence of key-value pairs to improve value lookup. Properties allows direct value lookup whereas the List previously required List scanning for an index and another index access to retrieve the actual value. Original Pull Request: #255
This commit is contained in:
committed by
Christoph Strobl
parent
50551fd182
commit
8f88b78eeb
@@ -27,18 +27,7 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
|
||||
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
@@ -89,7 +78,7 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
|
||||
/**
|
||||
* Base test class for AbstractConnection integration tests
|
||||
*
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
@@ -915,10 +904,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Test // DATAREDIS-661
|
||||
public void testGetConfig() {
|
||||
actual.add(connection.getConfig("*"));
|
||||
List<String> config = (List<String>) getResults().get(0);
|
||||
Properties config = (Properties) getResults().get(0);
|
||||
assertTrue(!config.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -29,7 +30,7 @@ import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline
|
||||
*
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
* @author Ninad Divadkar
|
||||
@@ -218,9 +219,9 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
|
||||
super.testGetBit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // DATAREDIS-661
|
||||
public void testGetConfig() {
|
||||
List<String> results = Collections.singletonList("bar");
|
||||
Properties results = MapUtils.toProperties(Collections.singletonMap("foo", "bar"));
|
||||
doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline();
|
||||
super.testGetConfig();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -224,7 +225,7 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
||||
|
||||
@Test
|
||||
public void testGetConfig() {
|
||||
List<String> results = Collections.singletonList("bar");
|
||||
Properties results = MapUtils.toProperties(Collections.singletonMap("foo", "bar"));
|
||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { results }) })).when(nativeConnection)
|
||||
.closePipeline();
|
||||
super.testGetConfig();
|
||||
|
||||
@@ -18,18 +18,10 @@ package org.springframework.data.redis.connection;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
@@ -53,10 +45,11 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultStringRedisConnection}
|
||||
*
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @auhtor Christoph Strobl
|
||||
* @author Ninad Divadkar
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class DefaultStringRedisConnectionTests {
|
||||
|
||||
@@ -302,9 +295,9 @@ public class DefaultStringRedisConnectionTests {
|
||||
verifyResults(Arrays.asList(new Object[] { true }));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // DATAREDIS-661
|
||||
public void testGetConfig() {
|
||||
List<String> results = Collections.singletonList("bar");
|
||||
Properties results = MapUtils.toProperties(Collections.singletonMap("foo", "bar"));
|
||||
doReturn(results).when(nativeConnection).getConfig("foo");
|
||||
actual.add(connection.getConfig("foo"));
|
||||
verifyResults(Arrays.asList(new Object[] { results }));
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.geo.Distance;
|
||||
@@ -205,7 +206,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
||||
|
||||
@Test
|
||||
public void testGetConfig() {
|
||||
List<String> results = Collections.singletonList("bar");
|
||||
Properties results = MapUtils.toProperties(Collections.singletonMap("foo", "bar"));
|
||||
doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).exec();
|
||||
super.testGetConfig();
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ public class RedisConnectionUnitTests {
|
||||
return delegate.expireAt(key, unixTime);
|
||||
}
|
||||
|
||||
public List<String> getConfig(String pattern) {
|
||||
public Properties getConfig(String pattern) {
|
||||
return delegate.getConfig(pattern);
|
||||
}
|
||||
|
||||
|
||||
@@ -1785,42 +1785,28 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(properties.getProperty("used_memory"), nullValue());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@Test // DATAREDIS-315, DATAREDIS-661
|
||||
public void getConfigShouldLoadCumulatedConfiguration() {
|
||||
|
||||
List<String> result = clusterConnection.getConfig("*max-*-entries*");
|
||||
Properties result = clusterConnection.getConfig("*max-*-entries*");
|
||||
|
||||
// config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6.
|
||||
// @link https://github.com/spring-projects/spring-data-redis/pull/187
|
||||
assertThat(result.size() % 6, is(0));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertThat(result.size() % 3, is(0));
|
||||
|
||||
if (i % 2 == 0) {
|
||||
assertThat(result.get(i), startsWith(CLUSTER_HOST));
|
||||
} else {
|
||||
assertThat(result.get(i), not(startsWith(CLUSTER_HOST)));
|
||||
}
|
||||
for (Object o : result.keySet()) {
|
||||
|
||||
assertThat(o.toString(), startsWith(CLUSTER_HOST));
|
||||
assertThat(result.getProperty(o.toString()), not(startsWith(CLUSTER_HOST)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@Test // DATAREDIS-315, DATAREDIS-661
|
||||
public void getConfigShouldLoadConfigurationOfSpecificNode() {
|
||||
|
||||
List<String> result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*");
|
||||
Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*");
|
||||
|
||||
ListIterator<String> it = result.listIterator();
|
||||
Integer valueIndex = null;
|
||||
while (it.hasNext()) {
|
||||
|
||||
String cur = it.next();
|
||||
if (cur.equals("slaveof")) {
|
||||
valueIndex = it.nextIndex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(valueIndex, notNullValue());
|
||||
assertThat(result.get(valueIndex), endsWith("7379"));
|
||||
assertThat(result.getProperty("slaveof"), endsWith("7379"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@@ -1799,42 +1798,28 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(properties.getProperty("used_memory"), nullValue());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@Test // DATAREDIS-315, DATAREDIS-661
|
||||
public void getConfigShouldLoadCumulatedConfiguration() {
|
||||
|
||||
List<String> result = clusterConnection.getConfig("*max-*-entries*");
|
||||
Properties result = clusterConnection.getConfig("*max-*-entries*");
|
||||
|
||||
// config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6.
|
||||
// @link https://github.com/spring-projects/spring-data-redis/pull/187
|
||||
assertThat(result.size() % 6, is(0));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertThat(result.size() % 3, is(0));
|
||||
|
||||
if (i % 2 == 0) {
|
||||
assertThat(result.get(i), startsWith(CLUSTER_HOST));
|
||||
} else {
|
||||
assertThat(result.get(i), not(startsWith(CLUSTER_HOST)));
|
||||
}
|
||||
for (Object o : result.keySet()) {
|
||||
|
||||
assertThat(o.toString(), startsWith(CLUSTER_HOST));
|
||||
assertThat(result.getProperty(o.toString()), not(startsWith(CLUSTER_HOST)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
@Test // DATAREDIS-315, DATAREDIS-661
|
||||
public void getConfigShouldLoadConfigurationOfSpecificNode() {
|
||||
|
||||
List<String> result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*");
|
||||
Properties result = clusterConnection.getConfig(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT), "*");
|
||||
|
||||
ListIterator<String> it = result.listIterator();
|
||||
Integer valueIndex = null;
|
||||
while (it.hasNext()) {
|
||||
|
||||
String cur = it.next();
|
||||
if (cur.equals("slaveof")) {
|
||||
valueIndex = it.nextIndex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(valueIndex, notNullValue());
|
||||
assertThat(result.get(valueIndex), endsWith("7379"));
|
||||
assertThat(result.getProperty("slaveof"), endsWith("7379"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.redis.core;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,6 +27,7 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -70,7 +72,7 @@ public class RedisKeyValueAdapterUnitTests {
|
||||
|
||||
when(jedisConnectionFactoryMock.getConnection()).thenReturn(redisConnectionMock);
|
||||
when(redisConnectionMock.getConfig("notify-keyspace-events"))
|
||||
.thenReturn(Arrays.asList("notify-keyspace-events", "KEA"));
|
||||
.thenReturn(MapUtils.toProperties(Collections.singletonMap("notify-keyspace-events", "KEA")));
|
||||
|
||||
context = new RedisMappingContext(new MappingConfiguration(new IndexConfiguration(), new KeyspaceConfiguration()));
|
||||
context.afterPropertiesSet();
|
||||
|
||||
Reference in New Issue
Block a user