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/03 16:14:57 UTC

[GitHub] [geode] jdeppe-pivotal commented on a change in pull request #5986: GEODE-8624: Support Redis HINCRBYFLOAT

jdeppe-pivotal commented on a change in pull request #5986:
URL: https://github.com/apache/geode/pull/5986#discussion_r569546128



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHincrByFloatIntegrationTest.java
##########
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.redis.internal.executor.hash;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.offset;
+
+import java.math.BigDecimal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.Protocol;
+import redis.clients.jedis.exceptions.JedisDataException;
+
+import org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.test.dunit.rules.RedisPortSupplier;
+
+public abstract class AbstractHincrByFloatIntegrationTest implements RedisPortSupplier {
+
+  private Jedis jedis;
+  private Jedis jedis2;
+  private static int ITERATION_COUNT = 4000;
+
+  @Before
+  public void setUp() {
+    jedis = new Jedis("localhost", getPort(), 10000000);
+    jedis2 = new Jedis("localhost", getPort(), 10000000);
+  }
+
+  @After
+  public void flushAll() {
+    jedis.flushAll();
+  }
+
+  @After
+  public void tearDown() {
+    jedis.close();
+    jedis2.close();
+  }
+
+  @Test
+  public void givenKeyNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT))
+        .hasMessageContaining("ERR wrong number of arguments for 'hincrbyfloat' command");
+  }
+
+  @Test
+  public void givenHashNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key"))
+        .hasMessageContaining("ERR wrong number of arguments for 'hincrbyfloat' command");
+  }
+
+  @Test
+  public void givenIncrementNotProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "hash"))
+        .hasMessageContaining("ERR wrong number of arguments for 'hincrbyfloat' command");
+  }
+
+  @Test
+  public void givenMoreThanFourArgumentsProvided_returnsWrongNumberOfArgumentsError() {
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "hash", "5", "extraArg"))
+            .hasMessageContaining("ERR wrong number of arguments for 'hincrbyfloat' command");
+  }
+
+  @Test
+  public void testHincrByFloat_withInfinityAndVariants() {
+    jedis.hset("key", "number", "1.4");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "+inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "-inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "inf"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "+infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "-infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "infinity"))
+            .hasMessage("ERR increment would produce NaN or Infinity");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "nan"))
+            .hasMessage("ERR value is not a valid float");
+
+    assertThatThrownBy(
+        () -> jedis.sendCommand(Protocol.Command.HINCRBYFLOAT, "key", "number", "infant"))
+            .hasMessage("ERR value is not a valid float");
+  }
+
+  @Test
+  public void testHincrByFloat() {
+    double incr = 0.37373;
+    String key = "key";
+    String field = "field";
+    jedis.hset(key, field, "1.0");
+
+    double response = jedis.hincrByFloat(key, field, incr);
+    assertThat(response).isEqualTo(incr + 1, offset(.00001));

Review comment:
       Redis' floating point precision is not precise.




----------------------------------------------------------------
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