ringles commented on a change in pull request #7261: URL: https://github.com/apache/geode/pull/7261#discussion_r794943721
########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPopIntegrationTest.java ########## @@ -0,0 +1,113 @@ +/* + * 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.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.concurrent.atomic.AtomicLong; + +import org.assertj.core.api.AssertionsForClassTypes; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import org.apache.geode.redis.ConcurrentLoopingThreads; +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPopIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + // TODO: make private when we implement Redis 6.2+ behavior for LPOP + public JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + // not checking LPOP argument count here, see LPopIntegrationTest + + @Test + public void lpop_withStringFails() { + jedis.set("string", PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpop("string")).hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpop_withNonExistentKey_returnsNull() { + assertThat(jedis.lpop("nonexistent")).isNull(); + } + + @Test + public void lpop_returnsOneMember() { Review comment: Yup. ########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPopIntegrationTest.java ########## @@ -0,0 +1,113 @@ +/* + * 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.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.concurrent.atomic.AtomicLong; + +import org.assertj.core.api.AssertionsForClassTypes; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import org.apache.geode.redis.ConcurrentLoopingThreads; +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPopIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + // TODO: make private when we implement Redis 6.2+ behavior for LPOP + public JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + // not checking LPOP argument count here, see LPopIntegrationTest + + @Test + public void lpop_withStringFails() { + jedis.set("string", PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpop("string")).hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpop_withNonExistentKey_returnsNull() { + assertThat(jedis.lpop("nonexistent")).isNull(); + } + + @Test + public void lpop_returnsOneMember() { + jedis.lpush(KEY, "e1", "e2"); + String result = jedis.lpop(KEY); + assertThat(result).isEqualTo("e2"); + } + + @Test + public void lpop_removesKey_whenLastElementRemoved() { + final String KEY_WITH_TAG = "{tag}" + KEY; Review comment: Without it, we get "JedisCluster only supports KEYS commands with patterns containing hash-tags ( curly-brackets enclosed strings )". Clarified in constant name, also no longer ALL_CAPS to fit with coding style. ########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPopIntegrationTest.java ########## @@ -0,0 +1,113 @@ +/* + * 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.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.concurrent.atomic.AtomicLong; + +import org.assertj.core.api.AssertionsForClassTypes; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import org.apache.geode.redis.ConcurrentLoopingThreads; +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPopIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + // TODO: make private when we implement Redis 6.2+ behavior for LPOP + public JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + // not checking LPOP argument count here, see LPopIntegrationTest + + @Test + public void lpop_withStringFails() { + jedis.set("string", PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpop("string")).hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpop_withNonExistentKey_returnsNull() { + assertThat(jedis.lpop("nonexistent")).isNull(); + } + + @Test + public void lpop_returnsOneMember() { + jedis.lpush(KEY, "e1", "e2"); + String result = jedis.lpop(KEY); + assertThat(result).isEqualTo("e2"); + } + + @Test + public void lpop_removesKey_whenLastElementRemoved() { + final String KEY_WITH_TAG = "{tag}" + KEY; + + jedis.lpush(KEY_WITH_TAG, "e1"); + jedis.lpop(KEY_WITH_TAG); + assertThat(jedis.keys(KEY_WITH_TAG)).isEmpty(); + } + + @Test + public void lpop_removesKey_whenLastElementRemoved_multipleTimes() { + final String KEY_WITH_TAG = "{tag}" + KEY; + + jedis.lpush(KEY_WITH_TAG, "e1"); + jedis.lpop(KEY_WITH_TAG); + jedis.lpop(KEY_WITH_TAG); + jedis.lpop(KEY_WITH_TAG); Review comment: Suspenders added to belt. ########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPushIntegrationTest.java ########## @@ -0,0 +1,119 @@ +/* + * 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.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.exceptions.JedisDataException; + +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPushIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + private JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + @Test + public void lpushErrors_givenTooFewArguments() { + assertAtLeastNArgs(jedis, Protocol.Command.LPUSH, 2); + } + + @Test + public void lpushErrors_withExistingKey_ofWrongType() { + String elementValue = "list element value that should never get added"; + + jedis.set(KEY, PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpush(KEY, elementValue)) + .hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpush_withExistingKey_ofWrongType_shouldNotOverWriteExistingKey() { Review comment: Simplified. ########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPushIntegrationTest.java ########## @@ -0,0 +1,119 @@ +/* + * 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.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.exceptions.JedisDataException; + +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPushIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + private JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + @Test + public void lpushErrors_givenTooFewArguments() { + assertAtLeastNArgs(jedis, Protocol.Command.LPUSH, 2); + } + + @Test + public void lpushErrors_withExistingKey_ofWrongType() { + String elementValue = "list element value that should never get added"; + + jedis.set(KEY, PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpush(KEY, elementValue)) + .hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpush_withExistingKey_ofWrongType_shouldNotOverWriteExistingKey() { + String elementValue = "list element value that should never get added"; + + jedis.set(KEY, PREEXISTING_VALUE); + + assertThatThrownBy(() -> jedis.lpush(KEY, elementValue)).isInstanceOf(JedisDataException.class); + + String result = jedis.get(KEY); + + assertThat(result).isEqualTo(PREEXISTING_VALUE); + } + + @Test + public void lpush_canStoreBinaryData() { Review comment: We should file a ticket to pull similar tests from Hashes and Sets, too. ########## File path: geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLPushIntegrationTest.java ########## @@ -0,0 +1,119 @@ +/* + * 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.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs; +import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE; +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 org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.exceptions.JedisDataException; + +import org.apache.geode.redis.RedisIntegrationTest; + +public abstract class AbstractLPushIntegrationTest implements RedisIntegrationTest { + public static final String KEY = "key"; + public static final String PREEXISTING_VALUE = "preexistingValue"; + private JedisCluster jedis; + + @Before + public void setUp() { + jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, getPort()), REDIS_CLIENT_TIMEOUT); + } + + @After + public void tearDown() { + flushAll(); + jedis.close(); + } + + @Test + public void lpushErrors_givenTooFewArguments() { + assertAtLeastNArgs(jedis, Protocol.Command.LPUSH, 2); + } + + @Test + public void lpushErrors_withExistingKey_ofWrongType() { + String elementValue = "list element value that should never get added"; + + jedis.set(KEY, PREEXISTING_VALUE); + assertThatThrownBy(() -> jedis.lpush(KEY, elementValue)) + .hasMessageContaining(ERROR_WRONG_TYPE); + } + + @Test + public void lpush_withExistingKey_ofWrongType_shouldNotOverWriteExistingKey() { + String elementValue = "list element value that should never get added"; + + jedis.set(KEY, PREEXISTING_VALUE); + + assertThatThrownBy(() -> jedis.lpush(KEY, elementValue)).isInstanceOf(JedisDataException.class); + + String result = jedis.get(KEY); + + assertThat(result).isEqualTo(PREEXISTING_VALUE); + } + + @Test + public void lpush_canStoreBinaryData() { + byte[] blob = new byte[256]; + for (int i = 0; i < 256; i++) { + blob[i] = (byte) i; + } + + jedis.lpush(KEY.getBytes(), blob, blob); + + byte[] result = jedis.lpop(KEY.getBytes()); + assertThat(result).containsExactly(blob); + result = jedis.lpop(KEY.getBytes()); + assertThat(result).containsExactly(blob); + } + + @Test + public void lpush_returnsUpdatedListLength() { + Long result = jedis.lpush(KEY, "e1"); + assertThat(result).isEqualTo(jedis.llen(KEY)); + + result = jedis.lpush(KEY, "e2"); + assertThat(result).isEqualTo(jedis.llen(KEY)); + + result = jedis.lpush(KEY, "e3"); + assertThat(result).isEqualTo(jedis.llen(KEY)); Review comment: Only dependent on LPUSH now. ########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPushDUnitTest.java ########## @@ -0,0 +1,143 @@ +/* + * 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.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.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 int LIST_SIZE = 1000; + private static JedisCluster jedis; + + private static MemberVM server1; + private static MemberVM server2; + private static MemberVM server3; + + @BeforeClass + public static void classSetup() { + MemberVM 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(BIND_ADDRESS, redisServerPort), REDIS_CLIENT_TIMEOUT); + } + + @Before + public void testSetup() { + clusterStartUp.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis.close(); + + server1.stop(); + server2.stop(); + server3.stop(); Review comment: Yeah, gonna need a ticket for about five other places in the code, too. -- 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]
