nonbinaryprogrammer commented on a change in pull request #6296:
URL: https://github.com/apache/geode/pull/6296#discussion_r627588837



##########
File path: 
geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSetTest.java
##########
@@ -165,4 +174,142 @@ public void 
setExpirationTimestamp_stores_delta_that_is_stable() throws IOExcept
     o2.fromDelta(in);
     assertThat(o2).isEqualTo(o1);
   }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void should_calculateSize_closeToROS_withVaryingMemberCounts() {
+    for (int i = 0; i < 1024; i += 16) {
+      RedisSet set = createRedisSetOfSpecifiedSize(i);
+
+      int expected = reflectionObjectSizer.sizeof(set);
+      Long actual = Long.valueOf(set.getSizeInBytes());
+      Offset<Long> offset = Offset.offset(Math.round(expected * 0.06));
+
+      assertThat(actual).isCloseTo(expected, offset);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void should_calculateSize_closeToROS_withVaryingMemberSize() {
+    for (int i = 0; i < 16; i++) {
+      RedisSet set = createRedisSetWithMemberOfSpecifiedSize(i * 64);
+      int expected = reflectionObjectSizer.sizeof(set);
+      Long actual = Long.valueOf(set.getSizeInBytes());
+      Offset<Long> offset = Offset.offset(Math.round(expected * 0.06));
+
+      assertThat(actual).isCloseTo(expected, offset);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void size_shouldDecrease_WhenValueIsRemoved() {
+    Region region = mock(Region.class);
+    final RedisData returnData = mock(RedisData.class);
+    when(region.put(Object.class, Object.class)).thenReturn(returnData);
+    final RedisKey key = new RedisKey("key".getBytes());
+    final ByteArrayWrapper value = new ByteArrayWrapper("value".getBytes());
+
+    RedisSet set = createRedisSetOfSpecifiedSize(10);
+
+    ArrayList<ByteArrayWrapper> members = new ArrayList<>();
+    members.add(value);
+    set.sadd(members, region, key);
+
+    int initialSize = set.getSizeInBytes();
+
+    set.srem(members, region, key);
+
+    int finalSize = set.getSizeInBytes();
+    int expectedSize = initialSize - value.length() - PER_MEMBER_OVERHEAD;
+
+    assertThat(finalSize).isEqualTo(expectedSize);
+  }
+
+  /******** constants *******/
+  @Test
+  public void baseOverheadConstant_shouldMatchCalculatedValue() {
+    ReflectionObjectSizer reflectionObjectSizer = 
ReflectionObjectSizer.getInstance();
+    int baseRedisSetOverhead = reflectionObjectSizer.sizeof(new RedisSet()) + 
18;
+
+    HashSet<ByteArrayWrapper> temp_hashset = new HashSet<>();
+    int base_hashset_size = reflectionObjectSizer.sizeof(temp_hashset);

Review comment:
       yeah I thought I had changed everything from snake case but I must have 
missed at least one.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to