[ 
https://issues.apache.org/jira/browse/GEODE-8852?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17269652#comment-17269652
 ] 

ASF GitHub Bot commented on GEODE-8852:
---------------------------------------

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



##########
File path: 
geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHashesIntegrationTest.java
##########
@@ -373,23 +373,32 @@ public void testHVals() {
     String key = "HVals_key";
     String field1 = "field_1";
     String field2 = "field_2";
-    String value = "value";
+    String value1 = "value_1";
+    String value2 = "value_2";
 
-    List<String> list = jedis.hvals(key);
-    assertThat(list == null || list.isEmpty()).isTrue();
+    List<String> list = jedis.hvals("non-existent-key");
+    assertThat(list == null);
 
-    Long result = jedis.hset(key, field1, value);
+    Long result = jedis.hset(key, field1, value1);
     assertThat(result).isEqualTo(1);
 
-    result = jedis.hset(key, field2, value);
+    result = jedis.hset(key, field2, value2);
     assertThat(result).isEqualTo(1);
     list = jedis.hvals(key);
 
-    assertThat(list).isNotNull();
-    assertThat(list).isNotEmpty();
     assertThat(list).hasSize(2);
+    assertThat(list).contains(value1, value2);
+  }
 
-    assertThat(list).contains(value);
+  @Test
+  public void hvalsFailsForNonHash() {
+    jedis.sadd("farm", "chicken");
+    assertThatThrownBy(() -> jedis.hvals("farm"))
+        .hasMessageContaining("WRONGTYPE");
+
+    jedis.set("tractor", "John Deere");
+    assertThatThrownBy(() -> jedis.hvals("tractor"))
+        .hasMessageContaining("WRONGTYPE");

Review comment:
       I mentioned this in Ray's PR, but it would be nice if we checked the 
full error message here. We store the rest of it as a constant in 
RedisConstants, so it could be something like:
   ```
   .hasMessageContaining("WRONGTYPE " + ERROR_WRONG_TYPE);
   ```
   if you want to be even more exact, it could be:
   ```
   .hasMessage("(error) WRONGTYPE " + ERROR_WRONG_TYPE);
   ```
   
   I know it might seem like overkill, but I remember us having problems with 
other error messages not matching Redis's exactly.

##########
File path: 
geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HvalsDUnitTest.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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 java.util.List;
+import java.util.Random;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+
+import org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.rules.RedisClusterStartupRule;
+
+public class HvalsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new 
RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  @BeforeClass
+  public static void classSetup() {
+    MemberVM locator = clusterStartUp.startLocatorVM(0);
+    clusterStartUp.startRedisVM(1, locator.getPort());
+    clusterStartUp.startRedisVM(2, locator.getPort());
+
+    int redisServerPort1 = clusterStartUp.getRedisPort(1);
+    int redisServerPort2 = clusterStartUp.getRedisPort(2);
+
+    jedis1 = new Jedis(LOCAL_HOST, redisServerPort1, JEDIS_TIMEOUT);
+    jedis2 = new Jedis(LOCAL_HOST, redisServerPort2, JEDIS_TIMEOUT);
+    jedis3 = new Jedis(LOCAL_HOST, redisServerPort1, JEDIS_TIMEOUT);
+  }
+
+  @Before
+  public void testSetup() {
+    jedis1.flushAll();
+  }
+
+  @Test
+  public void hvalsWorks_whileAlsoUpdatingHash() {
+    String key = "key";
+    int fieldCount = 100;
+    int iterations = 10000;
+    Random rand = new Random();
+
+    for (int i = 0; i < fieldCount; i++) {
+      jedis1.hset(key, "field-" + i, "" + i);
+    }
+
+    new ConcurrentLoopingThreads(iterations,
+        (i) -> {
+          int x = rand.nextInt(fieldCount);
+          String field = "field-" + x;
+          String currentValue = jedis1.hget(key, field);
+          jedis1.hset(key, field, "" + (Long.parseLong(currentValue) + i));
+        },
+        (i) -> assertThat(jedis2.hvals(key)).hasSize(fieldCount),
+        (i) -> assertThat(jedis3.hvals(key)).hasSize(fieldCount))
+            .run();
+
+    List<String> values = jedis1.hvals(key);
+    long finalTotal = values.stream().mapToLong(Long::valueOf).sum();
+
+    long sumOfBothSequenceSums = (fieldCount / 2) * ((fieldCount - 1) - 0) +
+        (iterations / 2) * ((iterations - 1) - 0);

Review comment:
       What is the purpose of subtracting 0 here?

##########
File path: 
geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHashesIntegrationTest.java
##########
@@ -373,23 +373,32 @@ public void testHVals() {
     String key = "HVals_key";
     String field1 = "field_1";
     String field2 = "field_2";
-    String value = "value";
+    String value1 = "value_1";
+    String value2 = "value_2";
 
-    List<String> list = jedis.hvals(key);
-    assertThat(list == null || list.isEmpty()).isTrue();
+    List<String> list = jedis.hvals("non-existent-key");
+    assertThat(list == null);

Review comment:
       Is there a reason for doing  `assertThat(list == null);` vs 
`assertThat(list).isEmpty();` here?




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


> Add additional tests for Redis HVALS command
> --------------------------------------------
>
>                 Key: GEODE-8852
>                 URL: https://issues.apache.org/jira/browse/GEODE-8852
>             Project: Geode
>          Issue Type: Test
>          Components: redis
>            Reporter: Jens Deppe
>            Priority: Major
>              Labels: pull-request-available
>
> Adding concurrency test as well as additional integration test



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to