Support srandmember with negative count
DATAREDIS-116
This commit is contained in:
@@ -27,6 +27,7 @@ import static org.springframework.data.redis.SpinBarrier.waitFor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -1202,7 +1203,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("myset", "baz"));
|
||||
actual.add(connection.sRandMember("myset", 2));
|
||||
assertTrue(((Set)convertResults().get(3)).size() == 2);
|
||||
assertTrue(((Collection)convertResults().get(3)).size() == 2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -1211,8 +1212,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
public void testSRandMemberCountNegative() {
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sRandMember("myset", -2));
|
||||
// APIs filter out duplicates so the negative has no effect
|
||||
assertTrue(((Set)convertResults().get(1)).size() == 1);
|
||||
assertEquals(Arrays.asList(new String[] {"foo", "foo"}), (List)convertResults().get(1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -1220,7 +1220,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCountKeyNotExists() {
|
||||
actual.add(connection.sRandMember("notexist", 2));
|
||||
assertTrue(((Set)convertResults().get(0)).isEmpty());
|
||||
assertTrue(((Collection)convertResults().get(0)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -225,6 +225,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2"));
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCountNegative() {
|
||||
super.testSRandMemberCountNegative();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "runLongTests", value = "true")
|
||||
public void testScriptKill() throws Exception{
|
||||
|
||||
@@ -382,6 +382,12 @@ public class LettuceConnectionPipelineIntegrationTests extends
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCountNegative() {
|
||||
super.testSRandMemberCountNegative();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalReturnFalse() {
|
||||
|
||||
@@ -157,27 +157,6 @@ public class SrpConnectionPipelineIntegrationTests extends
|
||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCount() {
|
||||
convertResultToSet = true;
|
||||
super.testSRandMemberCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCountKeyNotExists() {
|
||||
convertResultToSet = true;
|
||||
super.testSRandMemberCountKeyNotExists();
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testSRandMemberCountNegative() {
|
||||
convertResultToSet = true;
|
||||
super.testSRandMemberCountNegative();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZIncrBy() {
|
||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.redis.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -24,7 +25,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -36,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("RedisTemplateTests-context.xml")
|
||||
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
|
||||
public class DefaultSetOperationsTests {
|
||||
|
||||
@Autowired
|
||||
@@ -55,12 +59,32 @@ public class DefaultSetOperationsTests {
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testRandomMembers() {
|
||||
public void testDistinctRandomMembers() {
|
||||
setOps.add("test", "foo");
|
||||
setOps.add("test", "bar");
|
||||
setOps.add("test", "baz");
|
||||
Set<String> members = setOps.randomMembers("test", 2);
|
||||
Set<String> members = setOps.distinctRandomMembers("test", 2);
|
||||
assertEquals(2, members.size());
|
||||
assertTrue(Arrays.asList(new String[] {"foo", "bar", "baz"}).containsAll(members));
|
||||
}
|
||||
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testRandomMembersWithDuplicates() {
|
||||
setOps.add("test", "foo");
|
||||
List<String> members = setOps.randomMembers("test", 2);
|
||||
assertEquals(Arrays.asList(new String[] {"foo", "foo"}), members);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testRandomMembersNegative() {
|
||||
setOps.randomMembers("test", -1);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testDistinctRandomMembersNegative() {
|
||||
setOps.distinctRandomMembers("test", -2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user