nonbinaryprogrammer commented on a change in pull request #6296:
URL: https://github.com/apache/geode/pull/6296#discussion_r626177108
##########
File path:
geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/data/RedisSetTest.java
##########
@@ -165,4 +169,65 @@ 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);
+ }
+ }
+
+ private RedisSet createRedisSetOfSpecifiedSize(int setSize) {
+ ArrayList<ByteArrayWrapper> arrayList = new ArrayList<>();
+ for (int i = 0; i < setSize; i++) {
+ arrayList.add(new ByteArrayWrapper(("abcdefgh" + i).getBytes()));
+ }
+ return new RedisSet(arrayList);
+ }
+
+ private RedisSet createRedisSetWithMemberOfSpecifiedSize(int memberSize) {
+ ArrayList<ByteArrayWrapper> arrayList = new ArrayList<>();
+ ByteArrayWrapper member =
+ new ByteArrayWrapper(createMemberOfSpecifiedSize("a",
memberSize).getBytes());
+ if (member.length() > 0) {
+ arrayList.add(member);
+ }
+ return new RedisSet(arrayList);
+ }
+
+ private String createMemberOfSpecifiedSize(final String base, final int
stringSize) {
+ Random random = new Random();
+ if (base.length() > stringSize) {
+ return "";
+ }
+ StringBuffer sb = new StringBuffer(stringSize);
+ sb.append(base);
+ for (int i = base.length(); i < stringSize; i++) {
+ int randy = random.nextInt(10);
+ sb.append(randy);
+ }
+ String javaString = sb.toString();
+ return javaString;
+ }
+
Review comment:
yes, good call.
--
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]