fengjiajie commented on code in PR #1160:
URL: https://github.com/apache/parquet-mr/pull/1160#discussion_r1341335124
##########
parquet-encoding/src/test/java/org/apache/parquet/bytes/TestCapacityByteArrayOutputStream.java:
##########
@@ -49,6 +49,41 @@ public void testWriteArray() throws Throwable {
validate(capacityByteArrayOutputStream, v * 3);
}
+ @Test
+ public void testWriteArrayExpand() throws Throwable {
+ CapacityByteArrayOutputStream capacityByteArrayOutputStream =
newCapacityBAOS(2);
+ assertEquals(0, capacityByteArrayOutputStream.getCapacity());
+
+ byte[] toWrite = {(byte) (1), (byte) (2), (byte) (3), (byte) (4)};
+ int toWriteOffset = 0;
+ int writeLength = 2;
+ // write 2 bytes array
+ capacityByteArrayOutputStream.write(toWrite, toWriteOffset, writeLength);
+ toWriteOffset += writeLength;
+ assertEquals(2, capacityByteArrayOutputStream.size());
+ assertEquals(2, capacityByteArrayOutputStream.getCapacity());
+
+ // write 1 byte array, expand capacity to 4
+ writeLength = 1;
+ capacityByteArrayOutputStream.write(toWrite, toWriteOffset, writeLength);
+ toWriteOffset += writeLength;
+ assertEquals(3, capacityByteArrayOutputStream.size());
+ assertEquals(4, capacityByteArrayOutputStream.getCapacity());
+
+ // write 1 byte array, not expand
+ capacityByteArrayOutputStream.write(toWrite, toWriteOffset, writeLength);
+ assertEquals(4, capacityByteArrayOutputStream.size());
+ assertEquals(4, capacityByteArrayOutputStream.getCapacity());
Review Comment:
the original version would expand the capacity to 8, it is unnecessary
--
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]