ChenSammi commented on code in PR #6372:
URL: https://github.com/apache/ozone/pull/6372#discussion_r1524329911
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFSInputStream.java:
##########
@@ -162,6 +164,76 @@ public void testO3FSSingleByteRead() throws IOException {
}
}
+ @Test
+ public void testByteBufferPositionedRead() throws IOException {
+ try (FSDataInputStream inputStream = fs.open(filePath)) {
+ ByteBuffer buffer = ByteBuffer.allocate(20);
+ // Read positional from 50th index
+ int readBytes = inputStream.read(50, buffer);
+ byte[] value1 = new byte[readBytes];
+ System.arraycopy(buffer.array(), 0, value1, 0, readBytes);
+ byte[] value2 = new byte[readBytes];
+ System.arraycopy(data, 50, value2, 0, readBytes);
+ // Verify input and positional read data
+ assertArrayEquals(value1, value2, "value mismatch");
+
+ buffer.clear();
+ // Verify offset of file didn't change
+ // Read positional from 8th index again using same inputStream
+ readBytes = inputStream.read(8, buffer);
+ byte[] value3 = new byte[readBytes];
+ System.arraycopy(buffer.array(), 0, value3, 0, readBytes);
+ byte[] value4 = new byte[readBytes];
+ System.arraycopy(data, 8, value4, 0, readBytes);
+ // Verify input and positional read data
+ assertArrayEquals(value3, value4, "value mismatch");
+
+ // Buffer size more than actual data, still read should succeed
+ ByteBuffer buffer1 = ByteBuffer.allocate(30 * 1024 * 1024 * 2);
+ readBytes = inputStream.read(12, buffer1);
Review Comment:
Can you add readBytes check, to make sure the bytes read value is as
expected?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]