You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/03/11 19:11:59 UTC

[GitHub] [geode] jhutchison opened a new pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

jhutchison opened a new pull request #6119:
URL: https://github.com/apache/geode/pull/6119


   …RBY command
   
   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] sabbey37 commented on a change in pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
sabbey37 commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593364410



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -33,14 +34,15 @@
 public abstract class AbstractDecrByIntegrationTest implements RedisPortSupplier {
 
   private Jedis jedis;
-  private Random rand;
+  private Jedis jedis2;

Review comment:
       If we end up adding the additional test, could we also remove `jedis2`? it is not used.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593208896



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -50,48 +52,99 @@ public void tearDown() {
   }
 
   @Test
-  public void decrBy_errors_givenWrongNumberOfArguments() {
-    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
+  public void shouldDecrementByGivenAmount_givenValidInputsAndKey() {
+    String key1 = "key1";
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, 10);
+    String result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(90);
+
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, -10);
+    result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(110);
+
+    String key2 = "key2";
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, 10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-110);
+
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, -10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-90);
   }
 
   @Test
-  public void testDecrBy() {
-    String key1 = randString();
-    String key2 = randString();
-    String key3 = randString();
-    int decr1 = rand.nextInt(100);
-    int decr2 = rand.nextInt(100);
-    Long decr3 = Long.MAX_VALUE / 2;
-    int num1 = 100;
-    int num2 = -100;
-    jedis.set(key1, "" + num1);
-    jedis.set(key2, "" + num2);
-    jedis.set(key3, "" + Long.MIN_VALUE);
-
-    jedis.decrBy(key1, decr1);
-    jedis.decrBy(key2, decr2);
-
-    assertThat(jedis.get(key1)).isEqualTo("" + (num1 - decr1 * 1));
-    assertThat(jedis.get(key2)).isEqualTo("" + (num2 - decr2 * 1));
-
-    Exception ex = null;
-    try {
-      jedis.decrBy(key3, decr3);
-    } catch (Exception e) {
-      ex = e;
-    }
-    assertThat(ex).isNotNull();
+  public void should_returnNewValue_givenSuccessfulDecrby() {
+    jedis.set("key", "100");
+    Long decrByresult = jedis.decrBy("key", 50);
+
+    String getResult = jedis.get("key");
+
+    assertThat(decrByresult).isEqualTo(Long.valueOf(getResult)).isEqualTo(50l);
+  }
+
+
+  @Test
+  public void should_setKeyToZeroAndThenDecrement_givenKeyThatDoesNotExist() {
+
+    Long returnValue = jedis.decrBy("noneSuch", 10);
+    assertThat(returnValue).isEqualTo(-10);
+
+  }
+
+  @Test
+  public void shouldThrowError_givenWrongNumberOfArguments() {
+    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
   }
 
   @Test
   public void decrbyMoreThanMaxLongThrowsArithmeticException() {
     jedis.set("somekey", "1");
+
+    BigInteger maxLongValue = new BigInteger(String.valueOf(Long.MAX_VALUE));
+    BigInteger biggerThanMinLongValue = maxLongValue.add(new BigInteger("1"));

Review comment:
       This should probably be called `biggerThanMaxLongValue`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] sabbey37 merged pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
sabbey37 merged pull request #6119:
URL: https://github.com/apache/geode/pull/6119


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] sabbey37 commented on pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
sabbey37 commented on pull request #6119:
URL: https://github.com/apache/geode/pull/6119#issuecomment-797769635


   DUnit test failure is unrelated to this PR.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jhutchison commented on a change in pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
jhutchison commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593387036



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -33,14 +34,15 @@
 public abstract class AbstractDecrByIntegrationTest implements RedisPortSupplier {
 
   private Jedis jedis;
-  private Random rand;
+  private Jedis jedis2;

Review comment:
       added test




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jhutchison commented on a change in pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
jhutchison commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593269453



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -50,48 +52,99 @@ public void tearDown() {
   }
 
   @Test
-  public void decrBy_errors_givenWrongNumberOfArguments() {
-    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
+  public void shouldDecrementByGivenAmount_givenValidInputsAndKey() {
+    String key1 = "key1";
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, 10);
+    String result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(90);
+
+    jedis.set(key1, "100");
+    jedis.decrBy(key1, -10);
+    result = jedis.get(key1);
+    assertThat(Integer.parseInt(result)).isEqualTo(110);
+
+    String key2 = "key2";
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, 10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-110);
+
+    jedis.set(key2, "-100");
+    jedis.decrBy(key2, -10);
+    result = jedis.get(key2);
+    assertThat(Integer.parseInt(result)).isEqualTo(-90);
   }
 
   @Test
-  public void testDecrBy() {
-    String key1 = randString();
-    String key2 = randString();
-    String key3 = randString();
-    int decr1 = rand.nextInt(100);
-    int decr2 = rand.nextInt(100);
-    Long decr3 = Long.MAX_VALUE / 2;
-    int num1 = 100;
-    int num2 = -100;
-    jedis.set(key1, "" + num1);
-    jedis.set(key2, "" + num2);
-    jedis.set(key3, "" + Long.MIN_VALUE);
-
-    jedis.decrBy(key1, decr1);
-    jedis.decrBy(key2, decr2);
-
-    assertThat(jedis.get(key1)).isEqualTo("" + (num1 - decr1 * 1));
-    assertThat(jedis.get(key2)).isEqualTo("" + (num2 - decr2 * 1));
-
-    Exception ex = null;
-    try {
-      jedis.decrBy(key3, decr3);
-    } catch (Exception e) {
-      ex = e;
-    }
-    assertThat(ex).isNotNull();
+  public void should_returnNewValue_givenSuccessfulDecrby() {
+    jedis.set("key", "100");
+    Long decrByresult = jedis.decrBy("key", 50);
+
+    String getResult = jedis.get("key");
+
+    assertThat(decrByresult).isEqualTo(Long.valueOf(getResult)).isEqualTo(50l);
+  }
+
+
+  @Test
+  public void should_setKeyToZeroAndThenDecrement_givenKeyThatDoesNotExist() {
+
+    Long returnValue = jedis.decrBy("noneSuch", 10);
+    assertThat(returnValue).isEqualTo(-10);
+
+  }
+
+  @Test
+  public void shouldThrowError_givenWrongNumberOfArguments() {
+    assertExactNumberOfArgs(jedis, Protocol.Command.DECRBY, 2);
   }
 
   @Test
   public void decrbyMoreThanMaxLongThrowsArithmeticException() {
     jedis.set("somekey", "1");
+
+    BigInteger maxLongValue = new BigInteger(String.valueOf(Long.MAX_VALUE));
+    BigInteger biggerThanMinLongValue = maxLongValue.add(new BigInteger("1"));

Review comment:
       yes it should.  thanks.  changed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] jhutchison commented on a change in pull request #6119: GEODE:9009 finish support for functionality compatible with Redis DEC…

Posted by GitBox <gi...@apache.org>.
jhutchison commented on a change in pull request #6119:
URL: https://github.com/apache/geode/pull/6119#discussion_r593386840



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractDecrByIntegrationTest.java
##########
@@ -33,14 +34,15 @@
 public abstract class AbstractDecrByIntegrationTest implements RedisPortSupplier {
 
   private Jedis jedis;
-  private Random rand;
+  private Jedis jedis2;

Review comment:
       whoops-  thanks




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org