DonalEvans commented on a change in pull request #7392:
URL: https://github.com/apache/geode/pull/7392#discussion_r821227136



##########
File path: 
geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LInsertDUnitTest.java
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.commands.executor.list;
+
+import static 
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static 
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static redis.clients.jedis.args.ListPosition.AFTER;
+import static redis.clients.jedis.args.ListPosition.BEFORE;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.args.ListPosition;
+
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.rules.RedisClusterStartupRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class LInsertDUnitTest {
+  public static final int INITIAL_LIST_SIZE = 500;
+
+  @Rule
+  public RedisClusterStartupRule clusterStartUp = new 
RedisClusterStartupRule();
+
+  @Rule
+  public ExecutorServiceRule executor = new ExecutorServiceRule();
+
+  private static JedisCluster jedis;
+  private static final String insertedValue = "insertedValue";
+
+  @Before
+  public void testSetup() {
+    MemberVM locator = clusterStartUp.startLocatorVM(0);
+    clusterStartUp.startRedisVM(1, locator.getPort());
+    clusterStartUp.startRedisVM(2, locator.getPort());
+    clusterStartUp.startRedisVM(3, locator.getPort());
+    int redisServerPort = clusterStartUp.getRedisPort(1);
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, redisServerPort), 
REDIS_CLIENT_TIMEOUT);
+    clusterStartUp.flushAll();
+  }
+
+  @After
+  public void tearDown() {
+    jedis.close();
+  }
+
+  @Test
+  public void shouldDistributeDataAmongCluster_andRetainDataAfterServerCrash() 
{
+    String key = makeListKeyWithHashtag(1, 
clusterStartUp.getKeyOnServer("linsert", 1));
+    List<String> elementList = makeElementList(key, INITIAL_LIST_SIZE);
+    lpushPerformAndVerify(key, elementList);
+
+    assertThat(jedis.linsert(key, BEFORE, jedis.lindex(key, 2), insertedValue))
+        .isEqualTo(elementList.size() + 1);
+
+    assertThat(jedis.lindex(key, 2)).isEqualTo(insertedValue);
+
+    clusterStartUp.crashVM(1); // kill primary
+
+    assertThat(jedis.llen(key)).isEqualTo(elementList.size() + 1);
+    assertThat(jedis.lindex(key, 2)).isEqualTo(insertedValue);
+    assertThat(jedis.lindex(key, 
3)).isEqualTo(elementList.get(INITIAL_LIST_SIZE - 3));
+  }
+
+  @Test
+  public void givenBucketsMoveDuringLInsert_operationsAreNotLost() throws 
Exception {
+    AtomicBoolean continueInserting = new AtomicBoolean(true);
+    List<String> listHashtags = makeListHashtags();
+    List<String> keys = makeListKeys(listHashtags);
+
+    List<String> elementList1 = makeElementList(keys.get(0), 
INITIAL_LIST_SIZE);
+    List<String> elementList2 = makeElementList(keys.get(1), 
INITIAL_LIST_SIZE);
+    List<String> elementList3 = makeElementList(keys.get(2), 
INITIAL_LIST_SIZE);
+
+    lpushPerformAndVerify(keys.get(0), elementList1);
+    lpushPerformAndVerify(keys.get(1), elementList2);
+    lpushPerformAndVerify(keys.get(2), elementList3);
+
+    Runnable task1 = () -> {
+      while (continueInserting.get()) {
+        linsertPerformAndVerify(keys.get(0), BEFORE, jedis.lindex(keys.get(0), 
2), insertedValue);
+      }

Review comment:
       It might be a little neater to put the while loop inside the 
`linsertPerformAndVerify()` method.

##########
File path: 
geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LInsertDUnitTest.java
##########
@@ -98,24 +98,35 @@ public void 
givenBucketsMoveDuringLInsert_operationsAreNotLost() throws Exceptio
     lpushPerformAndVerify(keys.get(1), elementList2);
     lpushPerformAndVerify(keys.get(2), elementList3);
 
-    Runnable task1 = () -> linsertPerformAndVerify(keys.get(0), BEFORE,
-        jedis.lindex(keys.get(0), 2), insertedValue, numInserts);
-    Runnable task2 = () -> linsertPerformAndVerify(keys.get(1), AFTER,
-        jedis.lindex(keys.get(1), 2), insertedValue, numInserts);
-    Runnable task3 = () -> linsertPerformAndVerify(keys.get(2), AFTER,
-        jedis.lindex(keys.get(2), 2), insertedValue, numInserts);
+    Runnable task1 = () -> {
+      while (continueInserting.get()) {
+        linsertPerformAndVerify(keys.get(0), BEFORE, jedis.lindex(keys.get(0), 
2), insertedValue);
+      }
+    };
+    Runnable task2 = () -> {
+      while (continueInserting.get()) {
+        linsertPerformAndVerify(keys.get(1), AFTER, jedis.lindex(keys.get(1), 
2), insertedValue);
+      }
+    };
+    Runnable task3 = () -> {
+      while (continueInserting.get()) {
+        linsertPerformAndVerify(keys.get(2), AFTER, jedis.lindex(keys.get(2), 
2), insertedValue);
+      }
+    };
 
     Future<Void> future1 = executor.runAsync(task1);
     Future<Void> future2 = executor.runAsync(task2);
     Future<Void> future3 = executor.runAsync(task3);
 
-    for (int i = 0; i < 50 && numInserts.get() > 0; i++) {
+    for (int i = 0; i < 50; i++) {
+      if (i == 20) {
+        continueInserting.set(false);
+      }

Review comment:
       This could be simplified a bit to just have the loop run 20 times, then 
call `continueInserting.set(false);` afterwards, since we don't care about 
moving buckets if there are no operations ongoing.




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to