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



##########
File path: 
geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPushDUnitTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * 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 java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+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 LPushDUnitTest {
+  public static final int PUSHER_COUNT = 6;
+  public static final int PUSH_LIST_SIZE = 3;
+  private static MemberVM locator;
+
+  @ClassRule
+  public static RedisClusterStartupRule clusterStartUp = new 
RedisClusterStartupRule();
+
+  @Rule
+  public ExecutorServiceRule executor = new ExecutorServiceRule();
+
+  private static final int MINIMUM_ITERATIONS = 10000;
+  private static JedisCluster jedis;
+
+  @BeforeClass
+  public static void classSetup() {
+    locator = clusterStartUp.startLocatorVM(0);
+    clusterStartUp.startRedisVM(2, locator.getPort());
+    clusterStartUp.startRedisVM(3, locator.getPort());
+  }
+
+  @Before
+  public void testSetup() {
+    clusterStartUp.startRedisVM(1, locator.getPort());
+    clusterStartUp.rebalanceAllRegions();
+    int redisServerPort = clusterStartUp.getRedisPort(1);
+    jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, redisServerPort), 
REDIS_CLIENT_TIMEOUT);
+    clusterStartUp.flushAll();
+  }
+
+  @AfterClass
+  public static void tearDown() {
+    jedis.close();
+  }
+
+  @Test
+  public void shouldPushMultipleElementsAtomically()
+      throws ExecutionException, InterruptedException {
+    AtomicLong runningCount = new AtomicLong(PUSHER_COUNT);
+
+    List<String> listHashtags = makeListHashtags();
+    List<String> keys = makeListKeys(listHashtags);
+    List<String> elements1 = makeElementList(PUSH_LIST_SIZE, "element1-");
+    List<String> elements2 = makeElementList(PUSH_LIST_SIZE, "element2-");
+    List<String> elements3 = makeElementList(PUSH_LIST_SIZE, "element3-");
+
+    List<Runnable> taskList = new ArrayList<>();
+    taskList.add(() -> lpushPerformAndVerify(keys.get(0), elements1, 
runningCount));
+    taskList.add(() -> lpushPerformAndVerify(keys.get(0), elements1, 
runningCount));
+    taskList.add(() -> lpushPerformAndVerify(keys.get(1), elements2, 
runningCount));
+    taskList.add(() -> lpushPerformAndVerify(keys.get(1), elements2, 
runningCount));
+    taskList.add(() -> lpushPerformAndVerify(keys.get(2), elements3, 
runningCount));
+    taskList.add(() -> lpushPerformAndVerify(keys.get(2), elements3, 
runningCount));
+    taskList.add(() -> verifyListLengthCondition(keys.get(0), runningCount));
+    taskList.add(() -> verifyListLengthCondition(keys.get(1), runningCount));
+    taskList.add(() -> verifyListLengthCondition(keys.get(2), runningCount));
+
+    List<Future> futureList = new ArrayList<>();
+    for (Runnable task : taskList) {
+      futureList.add(executor.runAsync(task));
+    }
+
+    for (int i = 0; i < 50 && runningCount.get() > 0; i++) {
+      clusterStartUp.moveBucketForKey(listHashtags.get(i % 
listHashtags.size()));
+      GeodeAwaitility.await().during(Duration.ofMillis(500)).until(() -> true);
+    }
+
+    for (Future future : futureList) {
+      future.get();
+    }
+
+    int totalLength = 0;
+    Long length;
+    for (String key : keys) {
+      length = jedis.llen(key);
+      assertThat(length).isGreaterThanOrEqualTo(MINIMUM_ITERATIONS * 2 * 
PUSH_LIST_SIZE);
+      totalLength += length;
+    }

Review comment:
       I think it's fine to validate destructively at this point, because we've 
stopped doing any operations on the keys and don't need to do any other 
validation once we confirm the contents of the lists. I agree that it would be 
good to update the tests once we have LINDEX, but there's nothing to stop us 
from adding that extra confirmation that the behaviour is correct right now.




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