jdeppe-pivotal commented on a change in pull request #7417: URL: https://github.com/apache/geode/pull/7417#discussion_r824767934
########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/RPushDUnitTest.java ########## @@ -0,0 +1,201 @@ +/* + * 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.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicLong; + +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 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 RPushDUnitTest { + @Rule + public RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + public static final int PUSHER_COUNT = 6; + public static final int PUSH_LIST_SIZE = 3; + private static final int MINIMUM_ITERATIONS = 10000; + + private static final AtomicLong runningCount = new AtomicLong(PUSHER_COUNT); + private static List<String> listHashtags; + private static List<String> keys; + private static HashMap<String, List<String>> keyToElementListMap; + private static List<Runnable> taskList; + + private JedisCluster jedis; + + @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), 10_000); + listHashtags = makeListHashtags(); + keys = makeListKeys(listHashtags); + keyToElementListMap = new HashMap<>(); + for (String key : keys) { + keyToElementListMap.put(key, makeElementList(PUSH_LIST_SIZE, key)); + } + + taskList = new ArrayList<>(); + taskList.add(() -> rpushPerformAndVerify(keys.get(0), keyToElementListMap.get(keys.get(0)), + runningCount)); + taskList.add(() -> rpushPerformAndVerify(keys.get(0), keyToElementListMap.get(keys.get(0)), + runningCount)); + taskList.add(() -> rpushPerformAndVerify(keys.get(1), keyToElementListMap.get(keys.get(1)), + runningCount)); + taskList.add(() -> rpushPerformAndVerify(keys.get(1), keyToElementListMap.get(keys.get(1)), + runningCount)); + taskList.add(() -> rpushPerformAndVerify(keys.get(2), keyToElementListMap.get(keys.get(2)), + runningCount)); + taskList.add(() -> rpushPerformAndVerify(keys.get(2), keyToElementListMap.get(keys.get(2)), + runningCount)); + taskList.add(() -> verifyListLengthCondition(keys.get(0), runningCount)); + taskList.add(() -> verifyListLengthCondition(keys.get(1), runningCount)); + taskList.add(() -> verifyListLengthCondition(keys.get(2), runningCount)); + } + + @After + public void tearDown() { + jedis.close(); + } + + @Test + public void givenBucketsMovedDuringRPush_elementsAreAddedAtomically() + throws ExecutionException, InterruptedException { + + List<Future<Void>> futureList = new ArrayList<>(); + for (Runnable task : taskList) { + futureList.add(executor.runAsync(task)); + } + + for (int i = 0; i < 10 && runningCount.get() > 0; i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + Thread.sleep(500); + } + + for (Future<Void> future : futureList) { + future.get(); + } + + for (String key : keys) { + long length = jedis.llen(key); + assertThat(length).isGreaterThanOrEqualTo(MINIMUM_ITERATIONS * 2 * PUSH_LIST_SIZE); + validateListContents(key, keyToElementListMap); + } + } + + @Test + public void shouldNotLoseData_givenPrimaryServerCrashesDuringOperations() + throws ExecutionException, InterruptedException { + List<Future<Void>> futureList = new ArrayList<>(); + for (Runnable task : taskList) { + futureList.add(executor.runAsync(task)); + } + + Thread.sleep(200); Review comment: Hmm, the sleep is mainly to wait that anything that had been blocked, while a rebalance is going on, can continue. Since there are multiple threads, it would be difficult to determine what or 'who' to await on since not all threads will be blocked at the same time. -- 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: notifications-unsubscr...@geode.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org