forked from fppt/jedis-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* zrevrange support * fix ZRange and add REV support Co-authored-by: Ivan Ponomarev <iponomarev@mail.ru>
- Loading branch information
1 parent
a05a7ff
commit 8072b7e
Showing
4 changed files
with
176 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/github/fppt/jedismock/operations/sortedsets/ZRevRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.fppt.jedismock.operations.sortedsets; | ||
|
||
import com.github.fppt.jedismock.datastructures.Slice; | ||
import com.github.fppt.jedismock.operations.AbstractRedisOperation; | ||
import com.github.fppt.jedismock.operations.RedisCommand; | ||
import com.github.fppt.jedismock.storage.RedisBase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@RedisCommand("zrevrange") | ||
class ZRevRange extends AbstractRedisOperation { | ||
|
||
private static final String IS_REV = "REV"; | ||
private final ZRange zRange; | ||
|
||
|
||
ZRevRange(RedisBase base, List<Slice> params) { | ||
super(base, params); | ||
List<Slice> updatedParams = new ArrayList<>(params); | ||
updatedParams.add(Slice.create(IS_REV)); | ||
this.zRange = new ZRange(base, updatedParams); | ||
} | ||
|
||
@Override | ||
protected Slice response() { | ||
return zRange.response(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/com/github/fppt/jedismock/comparisontests/sortedsets/TestZRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.github.fppt.jedismock.comparisontests.sortedsets; | ||
|
||
import com.github.fppt.jedismock.comparisontests.ComparisonBase; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.params.ZRangeParams; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(ComparisonBase.class) | ||
public class TestZRange { | ||
|
||
private static final String ZSET_KEY = "myzset"; | ||
|
||
@BeforeEach | ||
public void setUp(Jedis jedis) { | ||
jedis.flushDB(); | ||
jedis.zadd(ZSET_KEY, 2, "aaaa"); | ||
jedis.zadd(ZSET_KEY, 3, "bbbb"); | ||
jedis.zadd(ZSET_KEY, 1, "cccc"); | ||
jedis.zadd(ZSET_KEY, 3, "bcbb"); | ||
jedis.zadd(ZSET_KEY, 3, "babb"); | ||
assertEquals(5L, jedis.zcount(ZSET_KEY, Integer.MIN_VALUE, Integer.MAX_VALUE)); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsEverythingInRightOrderWithPlusMinusMaxInteger(Jedis jedis) { | ||
assertEquals(Arrays.asList("cccc", "aaaa", "babb", "bbbb", "bcbb"), new ArrayList<>(jedis.zrange(ZSET_KEY, Integer.MIN_VALUE, Integer.MAX_VALUE))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsListInRightOrderWithPositiveRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("aaaa", "babb", "bbbb"), new ArrayList<>(jedis.zrange(ZSET_KEY, 1, 3))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsListInRightOrderWithNegativeRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("babb", "bbbb", "bcbb"), new ArrayList<>(jedis.zrange(ZSET_KEY, -3, -1))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsListInRightOrderWithNegativeStartAndPositiveEndRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("cccc", "aaaa", "babb"), new ArrayList<>(jedis.zrange(ZSET_KEY, -5, 2))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsListInRightOrderWithPositiveStartAndNegativeEndRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("aaaa", "babb", "bbbb", "bcbb"), new ArrayList<>(jedis.zrange(ZSET_KEY, 1, -1))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrange_EnsureItReturnsListInLexicographicOrderForSameScore(Jedis jedis) { | ||
jedis.zadd("foo", 42, "def"); | ||
jedis.zadd("foo", 42, "abc"); | ||
assertEquals(Arrays.asList("abc", "def"), jedis.zrange("foo", 0, -1)); | ||
assertEquals(Arrays.asList("def", "abc"), jedis.zrange("foo", ZRangeParams.zrangeParams(0, -1).rev())); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/github/fppt/jedismock/comparisontests/sortedsets/TestZRevRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.github.fppt.jedismock.comparisontests.sortedsets; | ||
|
||
import com.github.fppt.jedismock.comparisontests.ComparisonBase; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.exceptions.JedisDataException; | ||
|
||
import java.util.*; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@ExtendWith(ComparisonBase.class) | ||
public class TestZRevRange { | ||
|
||
private static final String ZSET_KEY = "myzset"; | ||
|
||
@BeforeEach | ||
public void setUp(Jedis jedis) { | ||
jedis.flushDB(); | ||
jedis.zadd(ZSET_KEY, 2, "aaaa"); | ||
jedis.zadd(ZSET_KEY, 3, "bbbb"); | ||
jedis.zadd(ZSET_KEY, 1, "cccc"); | ||
jedis.zadd(ZSET_KEY, 3, "bcbb"); | ||
jedis.zadd(ZSET_KEY, 3, "babb"); | ||
assertEquals(5L, jedis.zcount(ZSET_KEY, Integer.MIN_VALUE, Integer.MAX_VALUE)); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrevrange_EnsureItReturnsEverythingInRightOrderWithPlusMinusMaxInteger(Jedis jedis) { | ||
assertEquals(Arrays.asList("bcbb", "bbbb", "babb", "aaaa", "cccc"), new ArrayList<>(jedis.zrevrange(ZSET_KEY, Integer.MIN_VALUE, Integer.MAX_VALUE))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrevrange_EnsureItReturnsListInRightOrderWithPositiveRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("bbbb", "babb", "aaaa"), new ArrayList<>(jedis.zrevrange(ZSET_KEY, 1, 3))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrevrange_EnsureItReturnsListInRightOrderWithNegativeRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("babb", "aaaa", "cccc"), new ArrayList<>(jedis.zrevrange(ZSET_KEY, -3, -1))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrevrange_EnsureItReturnsListInRightOrderWithNegativeStartAndPositiveEndRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("bcbb", "bbbb", "babb"), new ArrayList<>(jedis.zrevrange(ZSET_KEY, -5, 2))); | ||
} | ||
|
||
@TestTemplate | ||
public void whenUsingZrevrange_EnsureItReturnsListInRightOrderWithPositiveStartAndNegativeEndRange(Jedis jedis) { | ||
assertEquals(Arrays.asList("bbbb", "babb", "aaaa", "cccc"), new ArrayList<>(jedis.zrevrange(ZSET_KEY, 1, -1))); | ||
} | ||
} |