You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ri...@apache.org on 2021/06/30 21:48:46 UTC
[geode] branch GEODE-9375-Implement-ZRANGE-Radish-command updated:
Integration tests, correct command param indexes
This is an automated email from the ASF dual-hosted git repository.
ringles pushed a commit to branch GEODE-9375-Implement-ZRANGE-Radish-command
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/GEODE-9375-Implement-ZRANGE-Radish-command by this push:
new 535d612 Integration tests, correct command param indexes
535d612 is described below
commit 535d6127ca502816ccd4f61fb7c35a125e33d930
Author: Ray Ingles <ri...@vmware.com>
AuthorDate: Wed Jun 30 17:47:40 2021 -0400
Integration tests, correct command param indexes
---
.../sortedset/AbstractZRangeIntegrationTest.java | 53 ++++++++++++++++++++++
.../executor/sortedset/ZRangeExecutor.java | 6 +--
2 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZRangeIntegrationTest.java b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZRangeIntegrationTest.java
index 196abd2..7f75d46 100755
--- a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZRangeIntegrationTest.java
+++ b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/sortedset/AbstractZRangeIntegrationTest.java
@@ -17,14 +17,24 @@ package org.apache.geode.redis.internal.executor.sortedset;
import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
import static org.apache.geode.redis.internal.RedisConstants.ERROR_SYNTAX;
import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Protocol;
+import redis.clients.jedis.Tuple;
import org.apache.geode.redis.RedisIntegrationTest;
import org.apache.geode.redis.internal.RedisConstants;
@@ -32,10 +42,15 @@ import org.apache.geode.redis.internal.RedisConstants;
public abstract class AbstractZRangeIntegrationTest implements RedisIntegrationTest {
private JedisCluster jedis;
private static final String SORTED_SET_KEY = "ss_key";
+ private List<String> members;
+ private List<Double> scores;
@Before
public void setUp() {
jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT);
+ members = new ArrayList<>(Arrays.asList("mem1", "mem2", "mem3", "mem4", "mem5"));
+ scores = new ArrayList<>(Arrays.asList(.5d, 1.0d, 1.7d, 2.002d, 3.14159d));
+ createRedisSortedSet(SORTED_SET_KEY, members, scores);
}
@After
@@ -75,5 +90,43 @@ public abstract class AbstractZRangeIntegrationTest implements RedisIntegrationT
.hasMessageContaining(ERROR_SYNTAX);
}
+ @Test
+ public void shouldReturnEmptyList_GivenInvalidRanges() {
+ assertThat(jedis.zrange(SORTED_SET_KEY, 5, 0)).isEmpty();
+ assertThat(jedis.zrange(SORTED_SET_KEY, 27, 30)).isEmpty();
+ assertThat(jedis.zrange(SORTED_SET_KEY, 8, -2)).isEmpty();
+ assertThat(jedis.zrange(SORTED_SET_KEY, -18, -10)).isEmpty();
+ }
+ @Test
+ public void shouldReturnSimpleRanges() {
+ assertThat(jedis.zrange(SORTED_SET_KEY, 0, 5)).containsAll(members);
+ assertThat(jedis.zrange(SORTED_SET_KEY, 0, 10)).containsAll(members);
+ assertThat(jedis.zrange(SORTED_SET_KEY, 3, 4)).containsAll(members.subList(3, 4));
+ assertThat(jedis.zrange(SORTED_SET_KEY, 0, 2)).containsAll(members.subList(0, 2));
+ }
+
+ @Test
+ public void shouldReturnRanges_SpecifiedWithNegativeOffsets() {
+ assertThat(jedis.zrange(SORTED_SET_KEY, -5, -1)).containsAll(members);
+ assertThat(jedis.zrange(SORTED_SET_KEY, -2, -1)).containsAll(members.subList(3, 4));
+ assertThat(jedis.zrange(SORTED_SET_KEY, -8, -3)).containsAll(members.subList(0, 2));
+ }
+
+ @Test
+ public void shouldAlsoReturnScores_whenWithScoresSpecified() {
+ Set<Tuple> expected = new LinkedHashSet<Tuple>();
+ for (int i = 0; i < members.size(); i++) {
+ expected.add(new Tuple(members.get(i), scores.get(i)));
+ }
+ assertThat(jedis.zrangeWithScores(SORTED_SET_KEY, 0, 5)).isEqualTo(expected);
+ }
+
+ private void createRedisSortedSet(String setName, List<String> members, List<Double> scores) {
+ Map<String, Double> scoreMembers = new HashMap<>();
+ for (int i = 0; i < members.size(); i++) {
+ scoreMembers.put(members.get(i), scores.get(i));
+ }
+ jedis.zadd(setName, scoreMembers);
+ }
}
diff --git a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZRangeExecutor.java b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZRangeExecutor.java
index ad75b7a..d03ae76 100644
--- a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZRangeExecutor.java
+++ b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/ZRangeExecutor.java
@@ -36,13 +36,13 @@ public class ZRangeExecutor extends AbstractExecutor {
List<byte[]> commandElements = command.getProcessedCommand();
try {
- min = bytesToInt(commandElements.get(1));
- max = bytesToInt(commandElements.get(2));
+ min = bytesToInt(commandElements.get(2));
+ max = bytesToInt(commandElements.get(3));
} catch (NumberFormatException nfe) {
return RedisResponse.error(ERROR_NOT_INTEGER);
}
if (commandElements.size() == 5) {
- if (equalsIgnoreCaseBytes(commandElements.get(3), "WITHSCORES".getBytes())) {
+ if (equalsIgnoreCaseBytes(commandElements.get(4), "WITHSCORES".getBytes())) {
withScores = true;
} else {
return RedisResponse.error(ERROR_SYNTAX);