ringles commented on a change in pull request #7403:
URL: https://github.com/apache/geode/pull/7403#discussion_r840600961
##########
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:
Yanked, since it's pretty simple for a one-element list.
##########
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:
Swept away.
##########
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:
Done.
##########
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:
Since we don't care about the contents of the element, now there's no
arg at all.
--
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]