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



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

Review comment:
       I also have no idea why it is 18. I didn't do the original Set 
implementation. figuring it out will take a lot of testing so I'd rather not 
have to. but I'll check with Ray on if he remembers where that came from.




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