This is an automated email from the ASF dual-hosted git repository.
ringles pushed a commit to branch
GEODE-9892-Create-Infrastructure-for-Redis-Lists
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to
refs/heads/GEODE-9892-Create-Infrastructure-for-Redis-Lists by this push:
new d2c0704 Add DUNIT tests, and properly register DSFID
d2c0704 is described below
commit d2c07041273b080e0ae756f35dbdd37434b8516f
Author: Ray Ingles <[email protected]>
AuthorDate: Tue Jan 11 16:30:17 2022 -0500
Add DUNIT tests, and properly register DSFID
---
.../commands/executor/list/LPopDUnitTest.java | 164 +++++++++++++++++++++
.../commands/executor/list/LPushDUnitTest.java | 146 ++++++++++++++++++
.../geode/redis/internal/GeodeRedisService.java | 1 +
3 files changed, 311 insertions(+)
diff --git
a/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
new file mode 100644
index 0000000..5bb8c33
--- /dev/null
+++
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import com.sun.org.apache.xml.internal.serializer.utils.SerializerMessages_sv;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+
+import org.apache.geode.internal.concurrent.LI;
+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 LPopDUnitTest {
+
+ @ClassRule
+ public static RedisClusterStartupRule clusterStartUp = new
RedisClusterStartupRule(4);
+
+ private static final String LOCAL_HOST = "127.0.0.1";
+ private static final int LIST_SIZE = 1000;
+ private static final int JEDIS_TIMEOUT =
+ Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+ private static JedisCluster jedis;
+
+ private static MemberVM locator;
+ private static MemberVM server1;
+ private static MemberVM server2;
+ private static MemberVM server3;
+
+ @BeforeClass
+ public static void classSetup() {
+ locator = clusterStartUp.startLocatorVM(0);
+ server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+ server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+ server3 = clusterStartUp.startRedisVM(3, locator.getPort());
+
+ int redisServerPort = clusterStartUp.getRedisPort(1);
+ jedis = new JedisCluster(new HostAndPort(LOCAL_HOST, redisServerPort),
JEDIS_TIMEOUT);
+ }
+
+ @Before
+ public void testSetup() {
+ clusterStartUp.flushAll();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ jedis.close();
+
+ server1.stop();
+ server2.stop();
+ server3.stop();
+ }
+
+ @Test
+ public void shouldDistributeDataAmongCluster_thenRemoveHalfOfData() {
+
+ String key = "key";
+
+ List<String> members = makeElementList(LIST_SIZE, "element1-");
+ List<String> halfOfMembers = makeElementList(LIST_SIZE / 2, "element1-");
+ List<String> otherHalfOfMembers = new ArrayList<>(members);
+ otherHalfOfMembers.removeAll(halfOfMembers);
+
+ jedis.lpush(key, members.toArray(new String[]{}));
+ for (int i = 0; i < halfOfMembers.size(); i++) {
+ jedis.lpop(key);
+ }
+
+ List<String> result = getAllElements(key);
+
+ assertThat(result.toArray().length).isEqualTo(otherHalfOfMembers.size());
+
assertThat(result.toArray()).containsExactlyInAnyOrder(otherHalfOfMembers.toArray());
+
+ }
+
+ @Test
+ public void
shouldDistributeDataAmongCluster_thenRemoveDifferentDataFromSameSetConcurrently()
{
+
+ String key = "key";
+
+ List<String> members1 = makeElementList(LIST_SIZE, "element1-");
+ List<String> members2 = makeElementList(LIST_SIZE, "element2-");
+
+ List<String> allMembers = new ArrayList<>();
+ allMembers.addAll(members1);
+ allMembers.addAll(members2);
+
+ jedis.lpush(key, allMembers.toArray(new String[]{}));
+
+ new ConcurrentLoopingThreads(LIST_SIZE,
+ (i) -> jedis.lpop(key),
+ (i) -> jedis.lpop(key)).run();
+
+ List<String> result = getAllElements(key);
+
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ public void
shouldDistributeDataAmongCluster_thenRemoveFromDifferentSetsConcurrently() {
+
+ String key1 = "key1";
+ String key2 = "key2";
+
+ List<String> members1 = makeElementList(LIST_SIZE, "element1-");
+ List<String> members2 = makeElementList(LIST_SIZE, "element2-");
+
+ jedis.lpush(key1, members1.toArray(new String[]{}));
+ jedis.lpush(key2, members2.toArray(new String[]{}));
+
+ new ConcurrentLoopingThreads(LIST_SIZE,
+ (i) -> jedis.lpop(key1),
+ (i) -> jedis.lpop(key2)).run();
+
+ Set<String> results1 = jedis.smembers(key1);
+ Set<String> results2 = jedis.smembers(key2);
+
+ assertThat(results1).isEmpty();
+ assertThat(results2).isEmpty();
+ }
+
+ private List<String> makeElementList(int setSize, String baseString) {
+ List<String> members = new ArrayList<>();
+ for (int i = 0; i < setSize; i++) {
+ members.add(baseString + i);
+ }
+ return members;
+ }
+
+ private List<String> getAllElements(String key) {
+ List<String> elements = new ArrayList<>();
+ String element;
+ while ((element = jedis.lpop(key)) != null) {
+ elements.add(element);
+ }
+ return elements;
+ }
+}
diff --git
a/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPushDUnitTest.java
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPushDUnitTest.java
new file mode 100644
index 0000000..248a51d
--- /dev/null
+++
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPushDUnitTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+
+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 LPushDUnitTest {
+
+ @ClassRule
+ public static RedisClusterStartupRule clusterStartUp = new
RedisClusterStartupRule(4);
+
+ private static final String LOCAL_HOST = "127.0.0.1";
+ private static final int LIST_SIZE = 1000;
+ private static final int JEDIS_TIMEOUT =
+ Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+ private static JedisCluster jedis;
+
+ private static MemberVM locator;
+ private static MemberVM server1;
+ private static MemberVM server2;
+ private static MemberVM server3;
+
+ @BeforeClass
+ public static void classSetup() {
+ locator = clusterStartUp.startLocatorVM(0);
+ server1 = clusterStartUp.startRedisVM(1, locator.getPort());
+ server2 = clusterStartUp.startRedisVM(2, locator.getPort());
+ server3 = clusterStartUp.startRedisVM(3, locator.getPort());
+
+ int redisServerPort = clusterStartUp.getRedisPort(1);
+ jedis = new JedisCluster(new HostAndPort(LOCAL_HOST, redisServerPort),
JEDIS_TIMEOUT);
+ }
+
+ @Before
+ public void testSetup() {
+ clusterStartUp.flushAll();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ jedis.close();
+
+ server1.stop();
+ server2.stop();
+ server3.stop();
+ }
+
+ @Test
+ public void shouldDistributeDataAmongCluster() {
+ String key = "key";
+
+ List<String> elements = makeElementList(LIST_SIZE, "element1-");
+
+ jedis.lpush(key, elements.toArray(new String[] {}));
+
+ List<String> result = getAllElements(key);
+
+ assertThat(result.toArray()).containsExactlyInAnyOrder(elements.toArray());
+ }
+
+ @Test
+ public void
shouldDistributeDataAmongCluster_givenConcurrentlyAddingDifferentDataToSameList()
{
+ String key = "key";
+
+ List<String> elements1 = makeElementList(LIST_SIZE, "element1-");
+ List<String> elements2 = makeElementList(LIST_SIZE, "element2-");
+
+ List<String> allElements = new ArrayList<>();
+ allElements.addAll(elements1);
+ allElements.addAll(elements2);
+
+ new ConcurrentLoopingThreads(LIST_SIZE,
+ (i) -> jedis.lpush(key, elements1.get(i)),
+ (i) -> jedis.lpush(key, elements2.get(i))).runInLockstep();
+
+ List<String> results = getAllElements(key);
+
+
assertThat(results.toArray()).containsExactlyInAnyOrder(allElements.toArray());
+ }
+
+ @Test
+ public void
shouldDistributeDataAmongCluster_givenConcurrentlyAddingDifferentLists() {
+ String key1 = "key1";
+ String key2 = "key2";
+
+ List<String> elements1 = makeElementList(LIST_SIZE, "element1-");
+ List<String> elements2 = makeElementList(LIST_SIZE, "element2-");
+
+ new ConcurrentLoopingThreads(LIST_SIZE,
+ (i) -> jedis.lpush(key1, elements1.get(i)),
+ (i) -> jedis.lpush(key2, elements2.get(i))).runInLockstep();
+
+ List<String> results1 = getAllElements(key1);
+ List<String> results2 = getAllElements(key2);
+
+
assertThat(results1.toArray()).containsExactlyInAnyOrder(elements1.toArray());
+
assertThat(results2.toArray()).containsExactlyInAnyOrder(elements2.toArray());
+
+ }
+
+ private List<String> makeElementList(int setSize, String baseString) {
+ List<String> members = new ArrayList<>();
+ for (int i = 0; i < setSize; i++) {
+ members.add(baseString + i);
+ }
+ return members;
+ }
+
+ private List<String> getAllElements(String key) {
+ List<String> elements = new ArrayList<>();
+ String element;
+ while ((element = jedis.lpop(key)) != null) {
+ elements.add(element);
+ }
+ return elements;
+ }
+}
diff --git
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
index d296a64..19e271b 100644
---
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
+++
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
@@ -60,6 +60,7 @@ public class GeodeRedisService implements CacheService,
ResourceEventsListener,
registrar.register(DataSerializableFixedID.REDIS_KEY, RedisKey.class);
registrar.register(DataSerializableFixedID.PUBLISH_REQUEST,
Publisher.PublishRequest.class);
+ registrar.register(DataSerializableFixedID.REDIS_LIST_ID, RedisSet.class);
registrar.register(DataSerializableFixedID.REDIS_SET_ID, RedisSet.class);
registrar.register(DataSerializableFixedID.REDIS_STRING_ID,
RedisString.class);
registrar.register(DataSerializableFixedID.REDIS_HASH_ID, RedisHash.class);