DonalEvans commented on a change in pull request #7519:
URL: https://github.com/apache/geode/pull/7519#discussion_r840954052
##########
File path:
geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/collections/SizeableByteArrayListTest.java
##########
@@ -73,22 +74,190 @@ public void removeObjects_getSizeInBytesIsAccurate() {
assertThat(list.size()).isEqualTo(0);
}
+ @Test
+ public void removeObject_getSizeInBytesIsAccurate() {
Review comment:
The test above this one, `removeObjects_getSizeInBytesIsAccurate()`,
could be improved, since it's currently possible that it will remove all the
elements from the list in one go, or never test the case where the count is
negative. A better test might be something like:
```
@Test
public void removeObjects_getSizeInBytesIsAccurate() {
// Create a list with only duplicate elements and confirm that it
correctly reports its size
SizeableByteArrayList list = new SizeableByteArrayList();
byte[] bytes = "anElement".getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < INITIAL_NUMBER_OF_ELEMENTS; ++i) {
// Clone the byte array because otherwise we end up with the list
containing multiple
// references to the same object in memory rather than references to
multiple different
// objects
list.addFirst(bytes.clone());
}
assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
// Remove elements from the head
list.remove(bytes, INITIAL_NUMBER_OF_ELEMENTS / 4);
assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
// Remove elements from the tail
list.remove(bytes, INITIAL_NUMBER_OF_ELEMENTS / 4);
assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
// Remove all of the remaining elements
list.remove(bytes, 0);
assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
assertThat(list).isEmpty();
}
```
##########
File path:
geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/collections/SizeableByteArrayListTest.java
##########
@@ -73,22 +74,190 @@ public void removeObjects_getSizeInBytesIsAccurate() {
assertThat(list.size()).isEqualTo(0);
}
+ @Test
+ public void removeObject_getSizeInBytesIsAccurate() {
+ // Create a list with an initial size and confirm that it correctly
reports its size
+ SizeableByteArrayList list = createList();
+ assertThat(list.getSizeInBytes()).isEqualTo(sizer.sizeof(list));
+
+ // Remove all the elements and assert that the size is correct after each
remove
+ Random rand = new Random();
Review comment:
This variable is not used and can be removed.
--
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]