DATAREDIS-647 - Correct SDIFF & SINTER behavior.

We now consider the last key in SDIFF command execution on Redis Cluster to correctly compute the set difference. 
For reactive connections we collect the result sets entirely before applying further computation. Previously, the zip function could return a previous view of the result that caused too many/too few results.

Original Pull Request: #250
This commit is contained in:
Mark Paluch
2017-05-11 14:15:47 +02:00
committed by Christoph Strobl
parent 95768983b6
commit 78e5b89d1b
6 changed files with 36 additions and 35 deletions

View File

@@ -15,30 +15,20 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.junit.After;
@@ -71,10 +61,6 @@ import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.test.annotation.IfProfileValue;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
/**
* @author Christoph Strobl
* @author Mark Paluch
@@ -1072,13 +1058,15 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES));
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-647
public void sDiffShouldWorkWhenKeysNotMapToSameSlot() {
nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES);
nativeConnection.sadd(KEY_3_BYTES, VALUE_1_BYTES, VALUE_3_BYTES);
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES));
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty()));
}
@Test // DATAREDIS-315

View File

@@ -15,11 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
@@ -1078,13 +1074,15 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
assertThat(clusterConnection.sDiff(SAME_SLOT_KEY_1_BYTES, SAME_SLOT_KEY_2_BYTES), hasItems(VALUE_1_BYTES));
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-647
public void sDiffShouldWorkWhenKeysNotMapToSameSlot() {
nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2);
nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3);
nativeConnection.sadd(KEY_3, VALUE_1, VALUE_3);
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES));
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty()));
}
@Test // DATAREDIS-315

View File

@@ -129,15 +129,19 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_3_BBUFFER).block(), is(false));
}
@Test // DATAREDIS-525
@Test // DATAREDIS-525, DATAREDIS-647
public void sInterShouldIntersectSetsCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_3, VALUE_1, VALUE_3);
StepVerifier.create(connection.setCommands().sInter(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) //
.expectNext(VALUE_2_BBUFFER) //
.verifyComplete();
StepVerifier.create(connection.setCommands().sInter(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER, KEY_3_BBUFFER))) //
.verifyComplete();
}
@Test // DATAREDIS-525
@@ -172,15 +176,19 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
is(3L));
}
@Test // DATAREDIS-525
@Test // DATAREDIS-525, DATAREDIS-647
public void sDiffShouldBeExcecutedCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_3, VALUE_2, VALUE_1);
StepVerifier.create(connection.setCommands().sDiff(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) //
.expectNext(VALUE_1_BBUFFER) //
.verifyComplete();
StepVerifier.create(connection.setCommands().sDiff(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER, KEY_3_BBUFFER))) //
.verifyComplete();
}
@Test // DATAREDIS-525