chungen0126 commented on code in PR #10765:
URL: https://github.com/apache/ozone/pull/10765#discussion_r3600123810
##########
hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestChunkInputStream.java:
##########
@@ -284,4 +284,26 @@ public void connectsToNewPipeline() throws Exception {
verify(newToken).encodeToUrlString();
}
}
+
+ @Test
+ public void testPositionedRead() throws Exception {
+ byte[] buffer = new byte[50];
+ ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
+ int bytesRead = chunkStream.read(30, byteBuffer);
+
+ assertEquals(50, bytesRead);
+ byte[] expected = Arrays.copyOfRange(chunkData, 30, 80);
+ assertArrayEquals(expected, buffer);
+ }
+
+ @Test
+ public void testPositionedReadFully() throws Exception {
Review Comment:
As it stands, this method will read as much as possible until either the
buffer is full or the stream reaches EOF (End of File). The only way we can
verify if we've reached the end of the stream is by checking the final
remaining length of the buffer.
However, looking at how the upper-level BlockInputStream actually uses it,
we might not even need this method. I think we should consider removing it
entirely. What do you think?
Here is how the overall architecture/flow would look:
If the stream reaches EOF but the buffer is not yet full:
1. ChunkInputStream returns normally to BlockInputStream.
2. BlockInputStream has two choices:
a. If there is another ChunkInputStream available, switch to it and
continue reading (loop back).
b. If there are no more chunks, return to MultiPartInputStream.
4. MultiPartInputStream also has two choices:
a. If there is another BlockInputStream available, switch to it (loop
back).
b. If there are no more blocks AND the buffer is still not full, throw
an EOFException.
--
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]