ringles commented on a change in pull request #7261: URL: https://github.com/apache/geode/pull/7261#discussion_r799671091
########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopAndCrashesDUnitTest.java ########## @@ -0,0 +1,108 @@ +/* + * 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 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.dunit.rules.MemberVM; +import org.apache.geode.test.dunit.rules.RedisClusterStartupRule; +import org.apache.geode.test.junit.rules.ExecutorServiceRule; + +public class LPopAndCrashesDUnitTest { + public static final int NUM_VMS = 4; + public static final int MINIMUM_ITERATIONS = 10000; + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(NUM_VMS); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static JedisCluster jedis; + + @BeforeClass + public static void classSetup() { + 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); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + } + + + @Test + public void shouldDistributeDataAmongCluster_andRetainDataAfterServerCrash() { Review comment: Done. ########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java ########## @@ -0,0 +1,166 @@ +/* + * 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.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +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 LPopDUnitTest { + public static final int NUM_VMS = 4; + public static final int MINIMUM_ITERATIONS = 10000; + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(NUM_VMS); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static JedisCluster jedis; + + @BeforeClass + public static void classSetup() { + 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); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + } + + @Test + public void givenBucketsMoveDuringLpop_thenOperationsAreNotLost() throws Exception { + AtomicBoolean running = new AtomicBoolean(true); + + List<String> listHashtags = new ArrayList<>(); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 1)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 2)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 3)); + + lpushPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0)); + lpushPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1)); + lpushPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2)); + + Runnable task1 = + () -> lpopPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0), running); + Runnable task2 = + () -> lpopPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1), running); + Runnable task3 = + () -> lpopPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2), running); + + Future<Void> future1 = executor.runAsync(task1); + Future<Void> future2 = executor.runAsync(task2); + Future<Void> future3 = executor.runAsync(task3); + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + running.set(false); + + future1.get(); + future2.get(); + future3.get(); + } + + private void lpushPerformAndVerify(int index, int minimumIterations, String hashtag) { Review comment: Done. ########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java ########## @@ -0,0 +1,166 @@ +/* + * 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.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +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 LPopDUnitTest { + public static final int NUM_VMS = 4; + public static final int MINIMUM_ITERATIONS = 10000; + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(NUM_VMS); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static JedisCluster jedis; + + @BeforeClass + public static void classSetup() { + 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); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + } + + @Test + public void givenBucketsMoveDuringLpop_thenOperationsAreNotLost() throws Exception { + AtomicBoolean running = new AtomicBoolean(true); + + List<String> listHashtags = new ArrayList<>(); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 1)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 2)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 3)); + + lpushPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0)); + lpushPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1)); + lpushPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2)); + + Runnable task1 = + () -> lpopPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0), running); + Runnable task2 = + () -> lpopPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1), running); + Runnable task3 = + () -> lpopPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2), running); + + Future<Void> future1 = executor.runAsync(task1); + Future<Void> future2 = executor.runAsync(task2); + Future<Void> future3 = executor.runAsync(task3); + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } Review comment: Yanked. ########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java ########## @@ -0,0 +1,166 @@ +/* + * 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.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +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 LPopDUnitTest { + public static final int NUM_VMS = 4; + public static final int MINIMUM_ITERATIONS = 10000; + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(NUM_VMS); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static JedisCluster jedis; + + @BeforeClass + public static void classSetup() { + 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); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + } + + @Test + public void givenBucketsMoveDuringLpop_thenOperationsAreNotLost() throws Exception { + AtomicBoolean running = new AtomicBoolean(true); + + List<String> listHashtags = new ArrayList<>(); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 1)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 2)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 3)); + + lpushPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0)); + lpushPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1)); + lpushPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2)); + + Runnable task1 = + () -> lpopPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0), running); + Runnable task2 = + () -> lpopPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1), running); + Runnable task3 = + () -> lpopPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2), running); + + Future<Void> future1 = executor.runAsync(task1); + Future<Void> future2 = executor.runAsync(task2); + Future<Void> future3 = executor.runAsync(task3); + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + running.set(false); + + future1.get(); + future2.get(); + future3.get(); + } + + private void lpushPerformAndVerify(int index, int minimumIterations, String hashtag) { + String key = makeListKeyWithHashtag(index, hashtag); + int iterationCount = 0; + + while (iterationCount < minimumIterations) { + String elementString = makeElementString(key, iterationCount); + try { + jedis.lpush(key, elementString); + } catch (Exception ex) { + throw new RuntimeException("Exception performing LPUSH " + elementString, ex); + } + iterationCount += 1; + } + + Long listLength = jedis.llen(key); + assertThat(listLength).isEqualTo(minimumIterations).withFailMessage("Initial list '" Review comment: Reworked. ########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java ########## @@ -0,0 +1,166 @@ +/* + * 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.Future; +import java.util.concurrent.atomic.AtomicBoolean; + +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 LPopDUnitTest { + public static final int NUM_VMS = 4; + public static final int MINIMUM_ITERATIONS = 10000; + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(NUM_VMS); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static JedisCluster jedis; + + @BeforeClass + public static void classSetup() { + 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); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + } + + @Test + public void givenBucketsMoveDuringLpop_thenOperationsAreNotLost() throws Exception { + AtomicBoolean running = new AtomicBoolean(true); + + List<String> listHashtags = new ArrayList<>(); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 1)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 2)); + listHashtags.add(clusterStartUp.getKeyOnServer("lpop", 3)); + + lpushPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0)); + lpushPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1)); + lpushPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2)); + + Runnable task1 = + () -> lpopPerformAndVerify(1, MINIMUM_ITERATIONS, listHashtags.get(0), running); + Runnable task2 = + () -> lpopPerformAndVerify(2, MINIMUM_ITERATIONS, listHashtags.get(1), running); + Runnable task3 = + () -> lpopPerformAndVerify(3, MINIMUM_ITERATIONS, listHashtags.get(2), running); + + Future<Void> future1 = executor.runAsync(task1); + Future<Void> future2 = executor.runAsync(task2); + Future<Void> future3 = executor.runAsync(task3); + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + for (int i = 0; i < 100 && running.get(); i++) { + clusterStartUp.moveBucketForKey(listHashtags.get(i % listHashtags.size())); + GeodeAwaitility.await().during(Duration.ofMillis(200)).until(() -> true); + } + + running.set(false); + + future1.get(); + future2.get(); + future3.get(); + } + + private void lpushPerformAndVerify(int index, int minimumIterations, String hashtag) { + String key = makeListKeyWithHashtag(index, hashtag); + int iterationCount = 0; + + while (iterationCount < minimumIterations) { + String elementString = makeElementString(key, iterationCount); + try { + jedis.lpush(key, elementString); + } catch (Exception ex) { + throw new RuntimeException("Exception performing LPUSH " + elementString, ex); + } + iterationCount += 1; + } + + Long listLength = jedis.llen(key); + assertThat(listLength).isEqualTo(minimumIterations).withFailMessage("Initial list '" + + key + "' length " + listLength + " less than target " + minimumIterations); + } + + private void lpopPerformAndVerify(int index, int minimumIterations, String hashtag, + AtomicBoolean isRunning) { + String key = makeListKeyWithHashtag(index, hashtag); + int iterationCount = 0; + + List<String> elementList = new ArrayList<>(); + while (iterationCount < minimumIterations && isRunning.get()) { Review comment: Used an AtomicLong to track running threads. -- 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]
