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/02 00:06:16 UTC

[GitHub] [geode] nonbinaryprogrammer opened a new pull request #5988: Geode 8904 hexists tests

nonbinaryprogrammer opened a new pull request #5988:
URL: https://github.com/apache/geode/pull/5988


   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 #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
sabbey37 commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r569622226



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHashesIntegrationTest.java
##########
@@ -344,31 +336,40 @@ public void incrByFloatFailsWithNonFloatFieldValue() {
   }
 
   @Test
-  public void testHExists() {
-    String key = Double.valueOf(rand.nextDouble()).toString();
-    String field = Double.valueOf(rand.nextInt(50)).toString() + ".field";
-    String value = Double.valueOf(rand.nextInt(50)).toString() + ".value";
-
-    assertThat(jedis.hexists(key, field)).isFalse();
+  public void testHExists_isFalseForNonexistentKeyOrField() {
+    jedis.hset("key", "field", "value");
 
-    jedis.hset(key, field, value);
-
-    assertThat(jedis.hget(key, field)).isEqualTo(value);
-
-    assertThat(jedis.hexists(key, field)).isTrue();
+    assertThat(jedis.hexists("nonexitentKey", "someField")).isFalse();

Review comment:
       Not super important, but `nonexistent` is spelled incorrectly.

##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHashesIntegrationTest.java
##########
@@ -251,12 +248,7 @@ public void testHStrLen_failsForNonHashes() {
 
   @Test
   public void testHStrlen_givenWrongNumberOfArguments() {
-    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HSTRLEN))
-        .hasMessageContaining("ERR wrong number of arguments for 'hstrlen' command");
-    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HSTRLEN, "1"))
-        .hasMessageContaining("ERR wrong number of arguments for 'hstrlen' command");
-    assertThatThrownBy(() -> jedis.sendCommand(Protocol.Command.HSTRLEN, "1", "2", "3"))
-        .hasMessageContaining("ERR wrong number of arguments for 'hstrlen' command");
+    assertExactNumberOfArgs(Protocol.Command.HSTRLEN, 2);
   }

Review comment:
       This is great!




----------------------------------------------------------------
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] ringles commented on a change in pull request #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
ringles commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r569621965



##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       With a queue, there's never a time when we're calling HEXISTS on something that doesn't exist yet, right? Awaitility is definitely slower, but does seem to allow more "asynchronicity".
   
   I suppose an alternative *might* be randomly HEXISTSing fields in the appropriate range. But at that point, we couldn't know if the return value was really correct, right?




----------------------------------------------------------------
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 #5988: GEODE-8904: Redis - hexists tests

Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r569768113



##########
File path: geode-redis/src/integrationTest/java/org/apache/geode/redis/internal/executor/hash/AbstractHashesIntegrationTest.java
##########
@@ -344,31 +336,40 @@ public void incrByFloatFailsWithNonFloatFieldValue() {
   }
 
   @Test
-  public void testHExists() {
-    String key = Double.valueOf(rand.nextDouble()).toString();
-    String field = Double.valueOf(rand.nextInt(50)).toString() + ".field";
-    String value = Double.valueOf(rand.nextInt(50)).toString() + ".value";
-
-    assertThat(jedis.hexists(key, field)).isFalse();
+  public void testHExists_isFalseForNonexistentKeyOrField() {
+    jedis.hset("key", "field", "value");
 
-    jedis.hset(key, field, value);
-
-    assertThat(jedis.hget(key, field)).isEqualTo(value);
-
-    assertThat(jedis.hexists(key, field)).isTrue();
+    assertThat(jedis.hexists("nonexitentKey", "someField")).isFalse();

Review comment:
       >.< oops. I think I'll go ahead and merge it and fix it in my next PR. don't want to send it back through CI




----------------------------------------------------------------
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 #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r568770441



##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       the downside to doing it with the queue is that it makes it essentially synchronous




----------------------------------------------------------------
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 #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r568770441



##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       the downside to doing it with the queue is that it makes it essentially synchronous




----------------------------------------------------------------
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] jdeppe-pivotal commented on a change in pull request #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r568763020



##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       This would be more efficient using a queue to pass the field name from one thread to another (as we had done in some other tests) - the test will run way quicker. It also removes the notion that there is some kind of eventual consistency at play here.

##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))
+            .untilAsserted(() -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue()))
+                .run();
+
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedValues);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileDeletingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hdel(key, "field-" + i),
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       Ditto the above comment.




----------------------------------------------------------------
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] jdeppe-pivotal commented on a change in pull request #5988: Geode 8904 hexists tests

Posted by GitBox <gi...@apache.org>.
jdeppe-pivotal commented on a change in pull request #5988:
URL: https://github.com/apache/geode/pull/5988#discussion_r568763020



##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       This would be more efficient using a queue to pass the field name from one thread to another (as we had done in some other tests) - the test will run way quicker. It also removes the notion that there is some kind of eventual consistency at play here.

##########
File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/hash/HExistsDUnitTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+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 HExistsDUnitTest {
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4);
+
+  private static final String LOCAL_HOST = "127.0.0.1";
+  private static final int HASH_SIZE = 1000;
+  private static final int JEDIS_TIMEOUT =
+      Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+  private static Jedis jedis1;
+  private static Jedis jedis2;
+  private static Jedis jedis3;
+
+  private static Properties locatorProperties;
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+  private static MemberVM server2;
+
+  private static int redisServerPort1;
+  private static int redisServerPort2;
+
+  @BeforeClass
+  public static void classSetup() {
+    locatorProperties = new Properties();
+    locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+    locator = clusterStartUp.startLocatorVM(0, locatorProperties);
+    server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+    server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+
+    redisServerPort1 = clusterStartUp.getRedisPort(1);
+    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();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis1.disconnect();
+    jedis2.disconnect();
+
+    server1.stop();
+    server2.stop();
+  }
+
+  @Test
+  public void testConcurrentHExists_whileUpdatingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hset(key, "field-" + i, "changedValue-" + i),
+        (i) -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue(),
+        (i) -> assertThat(jedis3.hexists(key, "field-" + i)).isTrue()).run();
+
+    Map<String, String> expectedResult = makeHashMap(HASH_SIZE, "field-", "changedValue-");
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedResult);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileAddingValues() {
+    String key = "key";
+
+    Map<String, String> expectedValues = new HashMap<>();
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> {
+          jedis1.hset(key, "field-" + i, "value-" + i);
+          expectedValues.put("field-" + i, "value-" + i);
+        },
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))
+            .untilAsserted(() -> assertThat(jedis2.hexists(key, "field-" + i)).isTrue()))
+                .run();
+
+    assertThat(jedis1.hgetAll(key)).containsExactlyInAnyOrderEntriesOf(expectedValues);
+  }
+
+  @Test
+  public void testConcurrentHExists_whileDeletingValues() {
+    String key = "key";
+
+    Map<String, String> testMap = makeHashMap(HASH_SIZE, "field-", "value-");
+
+    jedis1.hset(key, testMap);
+
+    new ConcurrentLoopingThreads(HASH_SIZE,
+        (i) -> jedis1.hdel(key, "field-" + i),
+        (i) -> GeodeAwaitility.await().atMost(Duration.ofSeconds(1))

Review comment:
       Ditto the above comment.




----------------------------------------------------------------
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 #5988: GEODE-8904: Redis - hexists tests

Posted by GitBox <gi...@apache.org>.
nonbinaryprogrammer merged pull request #5988:
URL: https://github.com/apache/geode/pull/5988


   


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