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/02/10 21:58:28 UTC
[GitHub] [geode] nonbinaryprogrammer opened a new pull request #6025: GEODE-8936: add INCR to list of supported commands
nonbinaryprogrammer opened a new pull request #6025:
URL: https://github.com/apache/geode/pull/6025
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 #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
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 overflow error for max 64 bit signed integer value (but not `ERR value is not an integer or out of range`, so we'd need to set a key to `9223372036854775808` then do an incr on that key (which results in `ERR value is not an integer or out of range`)). We should also add a test 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 `ERR value is not an integer or out of range` 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:
users@infra.apache.org
[GitHub] [geode] sabbey37 commented on a change in pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [geode] sabbey37 commented on a change in pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
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,809 to see if we'll return the minimum value, and doing an INCR on -9,223,372,036,854,775,810 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:
users@infra.apache.org
[GitHub] [geode] sabbey37 commented on a change in pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
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 `ERR value is not an integer or out of range` 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:
users@infra.apache.org
[GitHub] [geode] nonbinaryprogrammer commented on pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on pull request #6025:
URL: https://github.com/apache/geode/pull/6025#issuecomment-777691542
> Something else to think about is that we changed `INCRBYFLOAT` to parse a BigDecimal rather than a long. I'm not sure if we want to change all INCR/DECR related commands to parse BigIntegers or BigDecimals? (If we did, then we wouldn't have to worry about the max/min 64 bit signed integer value tests... it would be different from Redis, but we are already different due to the change in `INCRBYFLOAT`)
>
> **Update:** Jens told me BigDecimals were used in `INCRBYFLOAT` so that floating point would be more accurate... and keeping long for other INCR/DECR ops will be faster performance-wise. So unless we think there's a strong use case (maybe page view count?) or selling point for being able to INCR/DECR larger values than Redis, maybe that change doesn't make sense.
I think that in this case we should favor performance over consistency with another command, especially since that command isn't consistent with native redis. thank you for looking into that though
----------------------------------------------------------------
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] nonbinaryprogrammer merged pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer merged pull request #6025:
URL: https://github.com/apache/geode/pull/6025
----------------------------------------------------------------
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] nonbinaryprogrammer commented on a change in pull request #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on a change in pull request #6025:
URL: https://github.com/apache/geode/pull/6025#discussion_r574724909
##########
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:
Good ideas, I'll do that :)
----------------------------------------------------------------
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 #6025: GEODE-8936: add INCR to list of supported commands
Posted by GitBox <gi...@apache.org>.
sabbey37 commented on a change in pull request #6025:
URL: https://github.com/apache/geode/pull/6025#discussion_r576927251
##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/string/AbstractStringIntegrationTest.java
##########
@@ -35,6 +35,7 @@
private Jedis jedis;
private static final int REDIS_CLIENT_TIMEOUT =
Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+ private static final int NUM_ITERATIONS = 1000;
Review comment:
I don't think this variable is used in this class any longer.
----------------------------------------------------------------
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