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



##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -287,15 +287,15 @@ public Void ltrim(int start, int end, Region<RedisKey, 
RedisData> region,
     return null;
   }
 
-  private int getBoundedStartIndex(long index, int size) {
+  private int getBoundedStartIndex(int index, int size) {
     if (index >= 0L) {
       return (int) Math.min(index, size);
     } else {
       return (int) Math.max(index + size, 0);

Review comment:
       These casts are now redundant and can be removed, as are the ones in 
`getBoundedEndIndex()`.

##########
File path: 
geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/RedisListTest.java
##########
@@ -173,4 +195,10 @@ private RedisList createRedisList(int e1, int e2) {
     newList.elementPushHead(new byte[] {(byte) e2});
     return newList;
   }
+
+  private RedisList createRedisListWithOneElement(int e1) {
+    RedisList newList = new RedisList();
+    newList.elementPushHead(new byte[] {(byte) e1});

Review comment:
       For simplicity, could this method just take a `byte[]` as the argument 
rather than an int that we then have to fiddle with to put into the list?

##########
File path: 
geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/RedisListTest.java
##########
@@ -143,6 +143,28 @@ public void 
versionDoesNotUpdateWhenReferenceElementNotFound() {
     assertThat(list.getVersion()).isEqualTo(originalVersion);
   }
 
+  @Test
+  public void versionDoesNotUpdateWhenLtrimDoesNotModifyList() {
+    Region<RedisKey, RedisData> region = 
uncheckedCast(mock(PartitionedRegion.class));
+    RedisList list = createRedisListWithDuplicateElements();
+
+    byte originalVersion = list.getVersion();
+    list.ltrim(0, 5, region, null);

Review comment:
       To make it more obvious what this is doing, could the end index be `-1`? 
That way, regardless of the size of the list, we're guaranteed to always do a 
no-op.

##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLTrimIntegrationTest.java
##########
@@ -147,6 +147,31 @@ public void removesKey_whenRangeIsEmpty(long start, long 
end) {
     };
   }
 
+  @Test
+  @Parameters(method = "getRangesForOneElementList")
+  @TestCaseName("{method}: start:{0}, end:{1}, expected:{2}")
+  public void trimsToSpecifiedRange_givenListWithOneElement(long start, long 
end,
+      String[] expected) {
+    jedis.lpush(KEY, "e1");
+
+    jedis.ltrim(KEY, start, end);
+    assertThat(jedis.lrange(KEY, 0, -1)).containsExactly(expected);
+  }
+
+  @SuppressWarnings("unused")
+  private Object[] getRangesForOneElementList() {
+    // Values are start, end, expected
+    // For initial list of {e4, e3, e2, e1}

Review comment:
       This comment is incorrect

##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractLTrimIntegrationTest.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.assertExactNumberOfArgs;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_NOT_INTEGER;
+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.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import junitparams.Parameters;
+import junitparams.naming.TestCaseName;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+
+import org.apache.geode.redis.ConcurrentLoopingThreads;
+import org.apache.geode.redis.RedisIntegrationTest;
+import org.apache.geode.test.junit.runners.GeodeParamsRunner;
+
+@RunWith(GeodeParamsRunner.class)
+public abstract class AbstractLTrimIntegrationTest implements 
RedisIntegrationTest {

Review comment:
       What you have looks comprehensive to me




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