sabbey37 commented on a change in pull request #6025:
URL: https://github.com/apache/geode/pull/6025#discussion_r574569469



##########
File path: 
geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractStringIntegrationTest.java
##########
@@ -128,6 +130,62 @@ public void testStrlen_withFloatData() {
     assertThat(jedis.strlen(key)).isEqualTo(value.length);
   }
 
+  @Test
+  public void testIncr_ErrorsWithWrongNumberOfArguments() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.INCR))
+        .hasMessageContaining("ERR wrong number of arguments for 'incr' 
command");
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.INCR, "1", 
"2"))
+        .hasMessageContaining("ERR wrong number of arguments for 'incr' 
command");
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.INCR, "1", 
"2", "3"))
+        .hasMessageContaining("ERR wrong number of arguments for 'incr' 
command");
+  }
+
+  @Test
+  public void testIncr_errorsGivenWrongType() {
+    String key1 = "hashKey";
+    String key2 = "key";
+
+    jedis.hset(key1, "field", "non-int value");
+    jedis.set(key2, "non-int value");
+
+    assertThatThrownBy(() -> jedis.incr(key1))
+        .isInstanceOf(JedisDataException.class)
+        .hasMessageContaining(RedisConstants.ERROR_WRONG_TYPE);
+    assertThatThrownBy(() -> jedis.incr(key2))
+        .isInstanceOf(JedisDataException.class)
+        .hasMessageContaining(RedisConstants.ERROR_NOT_INTEGER);
+  }
+
+  @Test
+  public void testIncr_incrementsPositiveAndNegativeIntegerValues() {
+    String key1 = "positiveKey";
+    String key2 = "negativeKey";
+
+    jedis.set(key1, "10");
+    jedis.set(key2, "-10");
+
+    jedis.incr(key1);
+    jedis.incr(key2);
+
+    assertThat(Long.parseLong(jedis.get(key1))).isEqualTo(11L);
+    assertThat(Long.parseLong(jedis.get(key2))).isEqualTo(-9L);
+  }
+
+  @Test
+  public void testConcurrentIncr_performsAllIncrs() {
+    Jedis jedis2 = new Jedis("localhost", getPort(), REDIS_CLIENT_TIMEOUT);
+    String key = "key";
+    int expectedValue = NUM_ITERATIONS * 2;
+
+    jedis.set(key, "0");
+
+    new ConcurrentLoopingThreads(NUM_ITERATIONS,
+        (i) -> jedis.incr(key),
+        (i) -> jedis2.incr(key)).run();
+
+    assertThat(Integer.parseInt(jedis.get(key))).isEqualTo(expectedValue);
+  }
+

Review comment:
       There's actually an `AbstractIncrIntegrationTest` file.  Some of these 
could be merged into that file. Others are duplicates.  A couple tests that 
aren't in either file: performing `INCR` on a key that doesn't exist, and we 
test the max 64 bit signed integer value, but it would be interesting to do an 
incr with the min value as well (min value is -9,223,372,036,854,775,808, so 
maybe doing an INCR on -9,223,372,036,854,775,808 to see if we'll return 
-9,223,372,036,854,775,807, and doing an INCR on -9,223,372,036,854,775,809 to 
make sure we still get the OVERFLOW error when an INCR is performed).




----------------------------------------------------------------
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:
[email protected]


Reply via email to