You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2021/04/19 23:12:53 UTC

[geode] branch support/1.14 updated: GEODE-8931: Support Redis GETRANGE command (#6015)

This is an automated email from the ASF dual-hosted git repository.

nnag pushed a commit to branch support/1.14
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.14 by this push:
     new 61a548c  GEODE-8931: Support Redis GETRANGE command (#6015)
61a548c is described below

commit 61a548c5ee61e338af0a24fcb072c9b1e6e91f36
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Tue Feb 16 06:49:51 2021 -0800

    GEODE-8931: Support Redis GETRANGE command (#6015)
    
    
    (cherry picked from commit f8413bc6c0220007af0237592c7c23f571cd6fbc)
---
 .../string/AbstractGetRangeIntegrationTest.java    | 38 ++++++++++++++++++++++
 .../geode/redis/internal/RedisCommandType.java     |  2 +-
 .../redis/internal/SupportedCommandsJUnitTest.java |  2 +-
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
index 873b617..530b974 100755
--- a/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
+++ b/geode-apis-compatible-with-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractGetRangeIntegrationTest.java
@@ -16,10 +16,12 @@ package org.apache.geode.redis.internal.executor.string;
 
 import static org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertExactNumberOfArgs;
 import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.nio.charset.StandardCharsets;
+import java.util.Random;
 
 import org.junit.After;
 import org.junit.Before;
@@ -27,11 +29,13 @@ import org.junit.Test;
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.Protocol;
 
+import org.apache.geode.redis.ConcurrentLoopingThreads;
 import org.apache.geode.test.awaitility.GeodeAwaitility;
 import org.apache.geode.test.dunit.rules.RedisPortSupplier;
 
 public abstract class AbstractGetRangeIntegrationTest implements RedisPortSupplier {
 
+  private Random random = new Random();
   private Jedis jedis;
   private static final int REDIS_CLIENT_TIMEOUT =
       Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
@@ -67,6 +71,28 @@ public abstract class AbstractGetRangeIntegrationTest implements RedisPortSuppli
   }
 
   @Test
+  public void givenRangeIsBiggerThanMinOrMax_returnsNotIntegerError() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.GETRANGE, "key", "0", "9223372036854775808"))
+            .hasMessage("ERR " + ERROR_NOT_INTEGER);
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.GETRANGE, "key", "0", "-9223372036854775809"))
+            .hasMessage("ERR " + ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void givenWrongType_returnsWrongTypeError() {
+    jedis.sadd("set", "value");
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.GETRANGE, "set", "0", "1"))
+        .hasMessage("WRONGTYPE " + ERROR_WRONG_TYPE);
+
+    jedis.hset("hash", "field", "value");
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.GETRANGE, "hash", "0", "1"))
+        .hasMessage("WRONGTYPE " + ERROR_WRONG_TYPE);
+  }
+
+  @Test
   public void testGetRange_whenWholeRangeSpecified_returnsEntireValue() {
     String key = "key";
     String valueWith19Characters = "abc123babyyouknowme";
@@ -229,4 +255,16 @@ public abstract class AbstractGetRangeIntegrationTest implements RedisPortSuppli
     String range = jedis.getrange(key, 7, 14);
     assertThat(range).isEqualTo("");
   }
+
+  @Test
+  public void testConcurrentGetrange_whileUpdating() {
+    Jedis jedis2 = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+    jedis.set("key", "1");
+
+    new ConcurrentLoopingThreads(10000,
+        (i) -> jedis.set("key", Integer.toString(random.nextInt(10000))),
+        (i) -> Integer.parseInt(jedis2.getrange("key", 0, 5)))
+            .run();
+  }
+
 }
diff --git a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
index e023f90..7a9b83a 100755
--- a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
+++ b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/RedisCommandType.java
@@ -152,6 +152,7 @@ public enum RedisCommandType {
   DECR(new DecrExecutor(), SUPPORTED, new ExactParameterRequirements(2)),
   DECRBY(new DecrByExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
   GET(new GetExecutor(), SUPPORTED, new ExactParameterRequirements(2)),
+  GETRANGE(new GetRangeExecutor(), SUPPORTED, new ExactParameterRequirements(4)),
   INCRBYFLOAT(new IncrByFloatExecutor(), SUPPORTED, new ExactParameterRequirements(3)),
   MGET(new MGetExecutor(), SUPPORTED, new MinimumParameterRequirements(2)),
   SET(new SetExecutor(), SUPPORTED, new MinimumParameterRequirements(3)),
@@ -227,7 +228,6 @@ public enum RedisCommandType {
   BITOP(new BitOpExecutor(), UNSUPPORTED, new MinimumParameterRequirements(4)),
   BITPOS(new BitPosExecutor(), UNSUPPORTED, new MinimumParameterRequirements(3)),
   GETBIT(new GetBitExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
-  GETRANGE(new GetRangeExecutor(), UNSUPPORTED, new ExactParameterRequirements(4)),
   GETSET(new GetSetExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
   INCR(new IncrExecutor(), UNSUPPORTED, new ExactParameterRequirements(2)),
   INCRBY(new IncrByExecutor(), UNSUPPORTED, new ExactParameterRequirements(3)),
diff --git a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
index 4f4681f..1a1e526 100644
--- a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
+++ b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/SupportedCommandsJUnitTest.java
@@ -39,6 +39,7 @@ public class SupportedCommandsJUnitTest {
       "EXPIRE",
       "EXPIREAT",
       "GET",
+      "GETRANGE",
       "HGET",
       "HDEL",
       "HEXISTS",
@@ -90,7 +91,6 @@ public class SupportedCommandsJUnitTest {
       "FLUSHALL",
       "FLUSHDB",
       "GETBIT",
-      "GETRANGE",
       "GETSET",
       "INCR",
       "INCRBY",