You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ri...@apache.org on 2021/06/29 02:13:46 UTC

[geode] branch develop updated: Return 'inf' and '-inf' like Redis does, add Coder tests (#6658)

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

ringles pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new cdc7fd8  Return 'inf' and '-inf' like Redis does, add Coder tests (#6658)
cdc7fd8 is described below

commit cdc7fd8868ff470bd9f153197b5354e7b9d6721c
Author: Ray Ingles <ri...@pivotal.io>
AuthorDate: Mon Jun 28 22:12:50 2021 -0400

    Return 'inf' and '-inf' like Redis does, add Coder tests (#6658)
    
    Co-authored-by: Ray Ingles <ri...@vmware.com>
---
 .../apache/geode/redis/internal/netty/Coder.java   |  4 ++--
 .../geode/redis/internal/netty/CoderTest.java      | 23 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/netty/Coder.java b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/netty/Coder.java
index b48a09f..c4e08d1 100644
--- a/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/netty/Coder.java
+++ b/geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/netty/Coder.java
@@ -280,10 +280,10 @@ public class Coder {
 
   public static String doubleToString(double d) {
     if (d == Double.POSITIVE_INFINITY) {
-      return "Infinity";
+      return "inf";
     }
     if (d == Double.NEGATIVE_INFINITY) {
-      return "-Infinity";
+      return "-inf";
     }
 
     String stringValue = String.valueOf(d);
diff --git a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/netty/CoderTest.java b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/netty/CoderTest.java
index bf6e23a..cda6982 100644
--- a/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/netty/CoderTest.java
+++ b/geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/netty/CoderTest.java
@@ -14,7 +14,9 @@
  */
 package org.apache.geode.redis.internal.netty;
 
+import static org.apache.geode.redis.internal.netty.Coder.bytesToDouble;
 import static org.apache.geode.redis.internal.netty.Coder.bytesToString;
+import static org.apache.geode.redis.internal.netty.Coder.doubleToString;
 import static org.apache.geode.redis.internal.netty.Coder.equalsIgnoreCaseBytes;
 import static org.apache.geode.redis.internal.netty.Coder.isInfinity;
 import static org.apache.geode.redis.internal.netty.Coder.isNaN;
@@ -63,6 +65,13 @@ public class CoderTest {
     assertThat(isNaN(bytes)).isEqualTo(isNaN);
   }
 
+  @Test
+  @Parameters(method = "infinityReturnStrings")
+  public void doubleToString_processesLikeRedis(String inputString, String expectedString) {
+    byte[] bytes = stringToBytes(inputString);
+    assertThat(doubleToString(bytesToDouble(bytes))).isEqualTo(expectedString);
+  }
+
   @SuppressWarnings("unused")
   private Object[] stringPairs() {
     // string1, string2
@@ -102,4 +111,18 @@ public class CoderTest {
         new Object[] {null, false, false, false}
     };
   }
+
+  @SuppressWarnings("unused")
+  private Object[] infinityReturnStrings() {
+    // string, expectedString
+    return new Object[] {
+        new Object[] {"inf", "inf"},
+        new Object[] {"+inf", "inf"},
+        new Object[] {"Infinity", "inf"},
+        new Object[] {"+Infinity", "inf"},
+        new Object[] {"-inf", "-inf"},
+        new Object[] {"-Infinity", "-inf"},
+    };
+  }
+
 }