Skip to content

Commit

Permalink
Move some tests into subclasses
Browse files Browse the repository at this point in the history
The goal is to leave unchanged the top level test classes.
  • Loading branch information
gerzse committed Mar 13, 2024
1 parent aa7fe1d commit 4782b32
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.args.ListDirection;

import redis.clients.jedis.args.ListPosition;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.LPosParams;
import redis.clients.jedis.util.KeyValue;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void lrange() {
assertEquals(expected, range);

range = jedis.lrange("foo", 2, 1);
assertEquals(Collections.<String>emptyList(), range);
assertEquals(Collections.<String> emptyList(), range);

// Binary
jedis.rpush(bfoo, bA);
Expand All @@ -148,7 +149,7 @@ public void lrange() {
assertByteArrayListEquals(bexpected, brange);

brange = jedis.lrange(bfoo, 2, 1);
assertByteArrayListEquals(Collections.<byte[]>emptyList(), brange);
assertByteArrayListEquals(Collections.<byte[]> emptyList(), brange);
}

@Test
Expand Down Expand Up @@ -499,7 +500,7 @@ public void blpopDoubleWithSleep() {
new Thread(() -> {
try {
Thread.sleep(30);
} catch (InterruptedException e) {
} catch(InterruptedException e) {
logger.error("", e);
}
jedis.lpush("foo", "bar");
Expand Down Expand Up @@ -619,7 +620,7 @@ public void brpopDoubleWithSleep() {
new Thread(() -> {
try {
Thread.sleep(30);
} catch (InterruptedException e) {
} catch(InterruptedException e) {
logger.error("", e);
}
jedis.lpush("foo", "bar");
Expand Down Expand Up @@ -860,8 +861,8 @@ public void blmove() {

@Test
public void lmpop() {
String mylist1 = "mylist1{.}";
String mylist2 = "mylist2{.}";
String mylist1 = "mylist1";
String mylist2 = "mylist2";

// add elements to list
jedis.lpush(mylist1, "one", "two", "three", "four", "five");
Expand All @@ -885,8 +886,8 @@ public void lmpop() {

@Test
public void blmpopSimple() {
String mylist1 = "mylist1{.}";
String mylist2 = "mylist2{.}";
String mylist1 = "mylist1";
String mylist2 = "mylist2";

// add elements to list
jedis.lpush(mylist1, "one", "two", "three", "four", "five");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START;
import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START_BINARY;
import static redis.clients.jedis.util.AssertUtil.assertByteArrayCollectionContainsAll;
Expand All @@ -19,12 +20,12 @@
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.resps.ScanResult;

public abstract class SetCommandsTestBase extends UnifiedJedisCommandsTestBase {
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
final byte[] bfoo_same_hashslot = { 0x01, 0x02, 0x03, 0x04, 0x03, 0x00, 0x03, 0x1b };
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
final byte[] ba = { 0x0A };
Expand Down Expand Up @@ -356,29 +357,29 @@ public void sinterstore() {

@Test
public void sintercard() {
jedis.sadd("foo{.}", "a");
jedis.sadd("foo{.}", "b");
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");

jedis.sadd("bar{.}", "a");
jedis.sadd("bar{.}", "b");
jedis.sadd("bar{.}", "c");
jedis.sadd("bar", "a");
jedis.sadd("bar", "b");
jedis.sadd("bar", "c");

long card = jedis.sintercard("foo{.}", "bar{.}");
long card = jedis.sintercard("foo", "bar");
assertEquals(2, card);
long limitedCard = jedis.sintercard(1, "foo{.}", "bar{.}");
long limitedCard = jedis.sintercard(1, "foo", "bar");
assertEquals(1, limitedCard);

// Binary
jedis.sadd(bfoo, ba);
jedis.sadd(bfoo, bb);

jedis.sadd(bfoo_same_hashslot, ba);
jedis.sadd(bfoo_same_hashslot, bb);
jedis.sadd(bfoo_same_hashslot, bc);
jedis.sadd(bbar, ba);
jedis.sadd(bbar, bb);
jedis.sadd(bbar, bc);

long bcard = jedis.sintercard(bfoo, bfoo_same_hashslot);
long bcard = jedis.sintercard(bfoo, bbar);
assertEquals(2, bcard);
long blimitedCard = jedis.sintercard(1, bfoo, bfoo_same_hashslot);
long blimitedCard = jedis.sintercard(1, bfoo, bbar);
assertEquals(1, blimitedCard);
}

Expand Down Expand Up @@ -544,11 +545,11 @@ public void srandmember() {

List<String> members = jedis.srandmember("foo", 2);
members.sort(Comparator.naturalOrder());
assertEquals(Arrays.asList("a", "b"), members);
assertEquals( Arrays.asList("a", "b"), members);

member = jedis.srandmember("bar");
assertNull(member);

members = jedis.srandmember("bar", 2);
assertEquals(0, members.size());

Expand All @@ -560,13 +561,13 @@ public void srandmember() {

assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
assertEquals(2, jedis.smembers(bfoo).size());

List<byte[]> bmembers = jedis.srandmember(bfoo, 2);
assertEquals(2, bmembers.size());

bmember = jedis.srandmember(bbar);
assertNull(bmember);

members = jedis.srandmember("bbar", 2);
assertEquals(0, members.size());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package redis.clients.jedis.commands.unified;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START;
import static redis.clients.jedis.params.ScanParams.SCAN_POINTER_START_BINARY;
import static redis.clients.jedis.util.AssertUtil.assertByteArrayListEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import java.util.*;
import org.junit.Test;

import redis.clients.jedis.args.SortedSetOption;
import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.params.ZAddParams;
import redis.clients.jedis.params.ZIncrByParams;
import redis.clients.jedis.params.ZParams;
import redis.clients.jedis.params.ZRangeParams;
import redis.clients.jedis.params.*;
import redis.clients.jedis.resps.ScanResult;
import redis.clients.jedis.resps.Tuple;
import redis.clients.jedis.util.AssertUtil;
Expand All @@ -33,7 +19,6 @@

public abstract class SortedSetCommandsTestBase extends UnifiedJedisCommandsTestBase {
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
final byte[] bfoo_same_hashslot = { 0x01, 0x02, 0x03, 0x04, 0x03, 0x00, 0x03, 0x1b };
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
final byte[] ba = { 0x0A };
Expand Down Expand Up @@ -103,7 +88,7 @@ public void zaddWithParams() {
assertNull(jedis.zaddIncr("foo", 1d, "b", ZAddParams.zAddParams().nx()));
assertEquals(Double.valueOf(2d), jedis.zscore("foo", "b"));
// incr: update elements that already exist.
assertEquals(Double.valueOf(3d), jedis.zaddIncr("foo", 1d, "b", ZAddParams.zAddParams().xx()));
assertEquals(Double.valueOf(3d), jedis.zaddIncr("foo", 1d,"b", ZAddParams.zAddParams().xx()));
assertEquals(Double.valueOf(3d), jedis.zscore("foo", "b"));

// binary
Expand Down Expand Up @@ -327,14 +312,14 @@ public void zrangeParams() {

@Test
public void zrangestore() {
jedis.zadd("foo{.}", 1, "aa");
jedis.zadd("foo{.}", 2, "c");
jedis.zadd("foo{.}", 3, "bb");
jedis.zadd("foo", 1, "aa");
jedis.zadd("foo", 2, "c");
jedis.zadd("foo", 3, "bb");

long stored = jedis.zrangestore("bar{.}", "foo{.}", ZRangeParams.zrangeByScoreParams(1, 2));
long stored = jedis.zrangestore("bar", "foo", ZRangeParams.zrangeByScoreParams(1, 2));
assertEquals(2, stored);

List<String> range = jedis.zrange("bar{.}", 0, -1);
List<String> range = jedis.zrange("bar", 0, -1);
List<String> expected = new ArrayList<>();
expected.add("aa");
expected.add("c");
Expand All @@ -346,10 +331,10 @@ public void zrangestore() {
jedis.zadd(bfoo, 0.1d, bc);
jedis.zadd(bfoo, 2d, ba);

long bstored = jedis.zrangestore(bfoo_same_hashslot, bfoo, ZRangeParams.zrangeParams(0, 1).rev());
long bstored = jedis.zrangestore(bbar, bfoo, ZRangeParams.zrangeParams(0, 1).rev());
assertEquals(2, bstored);

List<byte[]> brange = jedis.zrevrange(bfoo_same_hashslot, 0, 1);
List<byte[]> brange = jedis.zrevrange(bbar, 0, 1);
List<byte[]> bexpected = new ArrayList<>();
bexpected.add(bb);
bexpected.add(ba);
Expand Down Expand Up @@ -649,7 +634,7 @@ public void zmscore() {
jedis.zadd(bfoo, 2d, ba);

assertEquals(Arrays.asList(10d, 0.1d, null),
jedis.zmscore(bfoo, bb, bc, SafeEncoder.encode("s")));
jedis.zmscore(bfoo, bb, bc, SafeEncoder.encode("s")));
}

@Test
Expand Down Expand Up @@ -905,7 +890,7 @@ public void zrangebyscore() {

brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1);
List<byte[]> brange2 = jedis.zrangeByScore(bfoo, SafeEncoder.encode("-inf"),
SafeEncoder.encode("(2"));
SafeEncoder.encode("(2"));
assertByteArrayListEquals(bexpected, brange2);

bexpected = new ArrayList<byte[]>();
Expand Down Expand Up @@ -985,7 +970,7 @@ public void zrevrangebyscore() {
assertByteArrayListEquals(bexpected, brange);

List<byte[]> brange2 = jedis.zrevrangeByScore(bfoo, SafeEncoder.encode("+inf"),
SafeEncoder.encode("(2"));
SafeEncoder.encode("(2"));

bexpected = new ArrayList<byte[]>();
bexpected.add(bb);
Expand Down Expand Up @@ -1343,7 +1328,7 @@ public void zinter() {
assertEquals(singletonList("a"), jedis.zinter(params, "foo", "bar"));

assertEquals(singletonList(new Tuple("a", new Double(7))),
jedis.zinterWithScores(params, "foo", "bar"));
jedis.zinterWithScores(params, "foo", "bar"));

// Binary
jedis.zadd(bfoo, 1, ba);
Expand All @@ -1356,7 +1341,7 @@ public void zinter() {
AssertUtil.assertByteArrayListEquals(singletonList(ba), jedis.zinter(params, bfoo, bbar));

assertEquals(singletonList(new Tuple(ba, new Double(7))),
jedis.zinterWithScores(bparams, bfoo, bbar));
jedis.zinterWithScores(bparams, bfoo, bbar));
}

@Test
Expand Down Expand Up @@ -1413,22 +1398,22 @@ public void zintertoreParams() {

@Test
public void zintercard() {
jedis.zadd("foo{.}", 1, "a");
jedis.zadd("foo{.}", 2, "b");
jedis.zadd("bar{.}", 2, "a");
jedis.zadd("bar{.}", 1, "b");
jedis.zadd("foo", 1, "a");
jedis.zadd("foo", 2, "b");
jedis.zadd("bar", 2, "a");
jedis.zadd("bar", 1, "b");

assertEquals(2, jedis.zintercard("foo{.}", "bar{.}"));
assertEquals(1, jedis.zintercard(1, "foo{.}", "bar{.}"));
assertEquals(2, jedis.zintercard("foo", "bar"));
assertEquals(1, jedis.zintercard(1, "foo", "bar"));

// Binary
jedis.zadd(bfoo, 1, ba);
jedis.zadd(bfoo, 2, bb);
jedis.zadd(bfoo_same_hashslot, 2, ba);
jedis.zadd(bfoo_same_hashslot, 2, bb);
jedis.zadd(bbar, 2, ba);
jedis.zadd(bbar, 2, bb);

assertEquals(2, jedis.zintercard(bfoo, bfoo_same_hashslot));
assertEquals(1, jedis.zintercard(1, bfoo, bfoo_same_hashslot));
assertEquals(2, jedis.zintercard(bfoo, bbar));
assertEquals(1, jedis.zintercard(1, bfoo, bbar));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package redis.clients.jedis.commands.unified;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.GetExParams;

import redis.clients.jedis.params.LCSParams;
import redis.clients.jedis.resps.LCSMatchResult;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.GetExParams;

public abstract class StringValuesCommandsTestBase extends UnifiedJedisCommandsTestBase {
@Test
Expand Down Expand Up @@ -239,19 +239,19 @@ public void psetex() {

@Test
public void lcs() {
jedis.mset("key1{.}", "ohmytext", "key2{.}", "mynewtext");
jedis.mset("key1", "ohmytext", "key2", "mynewtext");

LCSMatchResult stringMatchResult = jedis.lcs("key1{.}", "key2{.}",
LCSParams.LCSParams());
LCSMatchResult stringMatchResult = jedis.lcs("key1", "key2",
LCSParams.LCSParams());
assertEquals("mytext", stringMatchResult.getMatchString());

stringMatchResult = jedis.lcs("key1{.}", "key2{.}",
LCSParams.LCSParams().idx().withMatchLen());
stringMatchResult = jedis.lcs( "key1", "key2",
LCSParams.LCSParams().idx().withMatchLen());
assertEquals(stringMatchResult.getLen(), 6);
assertEquals(2, stringMatchResult.getMatches().size());

stringMatchResult = jedis.lcs("key1{.}", "key2{.}",
LCSParams.LCSParams().idx().minMatchLen(10));
stringMatchResult = jedis.lcs( "key1", "key2",
LCSParams.LCSParams().idx().minMatchLen(10));
assertEquals(0, stringMatchResult.getMatches().size());
}

Expand Down
Loading

0 comments on commit 4782b32

Please sign in to comment.