ringles commented on a change in pull request #7261: URL: https://github.com/apache/geode/pull/7261#discussion_r788176020
########## File path: geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/collections/SizeableListTest.java ########## @@ -0,0 +1,76 @@ +/* + * 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.data.collections; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import org.apache.geode.cache.util.ObjectSizer; +import org.apache.geode.internal.size.ReflectionObjectSizer; +import org.apache.geode.redis.internal.data.RedisList; + +public class SizeableListTest { + private final ObjectSizer sizer = ReflectionObjectSizer.getInstance(); + + private int expectedSize(SizeableList list) { + return sizer.sizeof(list); + } + + private RedisList.ElementList createTestElementList(int size) { + List<byte[]> initialElements = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + initialElements.add(new byte[] {(byte) i}); + } + RedisList.ElementList list = new RedisList.ElementList(initialElements); + return list; + } + + @Test + public void getSizeInBytesForEmptyElementList() { + RedisList.ElementList list = createTestElementList(0); Review comment: This class is pining for the fjords. ########## File path: geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/collections/SizeableListTest.java ########## @@ -0,0 +1,76 @@ +/* + * 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.data.collections; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import org.apache.geode.cache.util.ObjectSizer; +import org.apache.geode.internal.size.ReflectionObjectSizer; +import org.apache.geode.redis.internal.data.RedisList; + +public class SizeableListTest { + private final ObjectSizer sizer = ReflectionObjectSizer.getInstance(); + + private int expectedSize(SizeableList list) { + return sizer.sizeof(list); + } + + private RedisList.ElementList createTestElementList(int size) { + List<byte[]> initialElements = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + initialElements.add(new byte[] {(byte) i}); + } + RedisList.ElementList list = new RedisList.ElementList(initialElements); + return list; + } + + @Test + public void getSizeInBytesForEmptyElementList() { + RedisList.ElementList list = createTestElementList(0); + assertThat(list.getSizeInBytes()).isEqualTo(expectedSize(list)); + } + + @Test + public void getSizeInBytesIsAccurateForByteArrays() { + List<byte[]> initialElements = new ArrayList<>(); + int initialNumberOfElements = 20; + int elementsToAdd = 100; + for (int i = 0; i < initialNumberOfElements; ++i) { + initialElements.add(new byte[] {(byte) i}); + } + // Create a set with an initial size and confirm that it correctly reports its size + RedisList.ElementList list = new RedisList.ElementList(initialElements); + assertThat(list.getSizeInBytes()).isEqualTo(expectedSize(list)); + + // Add enough members to force a resize and assert that the size is correct after each add Review comment: Excised ########## File path: geode-for-redis/src/main/java/org/apache/geode/redis/internal/netty/ExecutionHandlerContext.java ########## @@ -483,17 +484,25 @@ private RedisSortedSet getRedisSortedSet(RedisKey key, boolean updateStats) { return getRegionProvider().getTypedRedisData(RedisDataType.REDIS_SORTED_SET, key, updateStats); } - public <R> R setLockedExecute(RedisKey key, boolean updateStats, FailableFunction<RedisSet, R> function) { return getRegionProvider().lockedExecute(key, () -> function.apply(getRedisSet(key, updateStats))); } + public <R> R listLockedExecute(RedisKey key, boolean updateStats, + FailableFunction<RedisList, R> function) { + return getRegionProvider().lockedExecute(key, + () -> function.apply(getRedisList(key, updateStats))); + } + public RedisSet getRedisSet(RedisKey key, boolean updateStats) { return getRegionProvider().getTypedRedisData(RedisDataType.REDIS_SET, key, updateStats); } + public RedisList getRedisList(RedisKey key, boolean updateStats) { Review comment: Privatized. -- 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]
