Polishing.
Extend copy(…) command with replace argument. Add support for reactive copy(…). Fix connection unit tests. Reorder methods. Add since tags. See #2040 Original pull request: #2059.
This commit is contained in:
@@ -509,6 +509,18 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
.isThrownBy(() -> connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnCommand("COPY")
|
||||
public void testCopy() {
|
||||
|
||||
actual.add(connection.set("foo", "bar"));
|
||||
actual.add(connection.copy("foo", "baz", false));
|
||||
|
||||
verifyResults(Arrays.asList(true, true));
|
||||
assertThat(connection.get("baz")).isEqualTo("bar");
|
||||
assertThat(connection.exists("foo")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInfo() {
|
||||
|
||||
|
||||
@@ -100,6 +100,12 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
||||
super.testBrPopLPush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
doReturn(Collections.singletonList(Arrays.asList(Boolean.TRUE))).when(nativeConnection).closePipeline();
|
||||
super.testCopy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline();
|
||||
@@ -142,13 +148,6 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
||||
super.testDel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
doReturn(Collections.singletonList(Collections.singletonList(Boolean.TRUE))).when(nativeConnection).closePipeline();
|
||||
super.testCopy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEchoBytes() {
|
||||
doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection)
|
||||
|
||||
@@ -187,6 +187,13 @@ public class DefaultStringRedisConnectionTests {
|
||||
verifyResults(Collections.singletonList(bar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
doReturn(Boolean.TRUE).when(nativeConnection).copy(fooBytes, barBytes, false);
|
||||
actual.add(connection.copy(foo, bar, false));
|
||||
verifyResults(Collections.singletonList(Boolean.TRUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
doReturn(3L).when(nativeConnection).dbSize();
|
||||
@@ -236,13 +243,6 @@ public class DefaultStringRedisConnectionTests {
|
||||
verifyResults(Collections.singletonList(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
doReturn(Boolean.TRUE).when(nativeConnection).copy(fooBytes, barBytes);
|
||||
actual.add(connection.copy(foo, bar));
|
||||
verifyResults(Collections.singletonList(Boolean.TRUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoBytes() {
|
||||
doReturn(barBytes).when(nativeConnection).echo(fooBytes);
|
||||
|
||||
@@ -92,6 +92,12 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
||||
super.testBrPopLPush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
doReturn(Collections.singletonList(Boolean.TRUE)).when(nativeConnection).exec();
|
||||
super.testCopy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
doReturn(Collections.singletonList(3L)).when(nativeConnection).exec();
|
||||
|
||||
@@ -187,8 +187,8 @@ class RedisConnectionUnitTests {
|
||||
return delegate.del(keys);
|
||||
}
|
||||
|
||||
public Boolean copy(byte[] sourceKey, byte[] targetKey) {
|
||||
return delegate.copy(sourceKey, targetKey);
|
||||
public Boolean copy(byte[] sourceKey, byte[] targetKey, boolean replace) {
|
||||
return delegate.copy(sourceKey, targetKey, replace);
|
||||
}
|
||||
|
||||
public void close() throws DataAccessException {
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
|
||||
import org.springframework.data.redis.test.condition.EnabledOnCommand;
|
||||
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
|
||||
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
|
||||
|
||||
@@ -91,6 +92,34 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // GH-2040
|
||||
@EnabledOnCommand("COPY")
|
||||
void copy() {
|
||||
|
||||
ReactiveRedisClusterConnection connection = null;
|
||||
try {
|
||||
connection = redisTemplate.getConnectionFactory().getReactiveClusterConnection();
|
||||
assumeThat(connection == null).isTrue();
|
||||
} catch (InvalidDataAccessApiUsageException e) {} finally {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
K key = keyFactory.instance();
|
||||
K targetKey = keyFactory.instance();
|
||||
V value = valueFactory.instance();
|
||||
V nextValue = valueFactory.instance();
|
||||
|
||||
redisTemplate.opsForValue().set(key, value).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
redisTemplate.copy(key, targetKey, false).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
redisTemplate.opsForValue().get(targetKey).as(StepVerifier::create).expectNext(value).verifyComplete();
|
||||
|
||||
redisTemplate.opsForValue().set(key, nextValue).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
redisTemplate.copy(key, targetKey, true).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
redisTemplate.opsForValue().get(targetKey).as(StepVerifier::create).expectNext(nextValue).verifyComplete();
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-602
|
||||
void exists() {
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisClusterConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
@@ -393,16 +395,24 @@ public class RedisTemplateIntegrationTests<K, V> {
|
||||
|
||||
@ParameterizedRedisTest
|
||||
void testCopy() {
|
||||
|
||||
assumeThat(redisTemplate.execute((RedisCallback<RedisConnection>) it -> it))
|
||||
.isNotInstanceOf(RedisClusterConnection.class);
|
||||
|
||||
K key1 = keyFactory.instance();
|
||||
K key2 = keyFactory.instance();
|
||||
V value1 = valueFactory.instance();
|
||||
V value2 = valueFactory.instance();
|
||||
|
||||
redisTemplate.opsForValue().set(key1, value1);
|
||||
|
||||
assertThat(redisTemplate.hasKey(key2)).isFalse();
|
||||
redisTemplate.copy(key1, key2);
|
||||
assertThat(redisTemplate.hasKey(key2)).isTrue();
|
||||
redisTemplate.copy(key1, key2, false);
|
||||
assertThat(redisTemplate.opsForValue().get(key2)).isEqualTo(value1);
|
||||
|
||||
redisTemplate.opsForValue().set(key1, value2);
|
||||
|
||||
redisTemplate.copy(key1, key2, true);
|
||||
assertThat(redisTemplate.opsForValue().get(key2)).isEqualTo(value2);
|
||||
}
|
||||
|
||||
@ParameterizedRedisTest // DATAREDIS-688
|
||||
|
||||
Reference in New Issue
Block a user