chungen0126 commented on code in PR #11337:
URL: https://github.com/apache/ozone/pull/11337#discussion_r4136065767
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/read/TestStreamBlockInputStream.java:
##########
@@ -124,9 +144,8 @@ private void runTestReadKey(String key, int bufferSize,
boolean randomReadOffset
if (read == -1) {
break;
}
- for (int i = 0; i < read; i++) {
- assertEquals(inputData[pos + i], buffer[i], "pos=" + pos + ", i=" +
i);
- }
+ assertArrayEquals(Arrays.copyOfRange(inputData, pos, pos + read),
+ Arrays.copyOfRange(buffer, 0, read), "pos=" + pos);
Review Comment:
I don't think allocating new arrays with `Arrays.copyOfRange` on each read
iteration is ideal here.
Here are some suggestions:
1. Wrap it into a buffer
```
assertEquals(
ByteBuffer.wrap(inputData, pos, read),
ByteBuffer.wrap(buffer, 0, read));
```
2. Use `inputData[pos + i] != buffer[i]` to validate them instead of
assertion.
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/read/TestStreamBlockInputStream.java:
##########
@@ -175,19 +194,16 @@ void runTestPositionedRead(ByteBuffer buffer,
KeyInputStream in, int pos, int le
void assertData(int pos, int length, ByteBuffer buffer) {
buffer.flip();
assertEquals(length, buffer.remaining());
- for (int i = 0; i < length; i++) {
- assertEquals(inputData[pos + i], buffer.get(i), "pos=" + pos + ", i=" +
i);
- }
- }
-
- @Test
- void testAllWithPreRead() throws Exception {
- runTestAll(true);
+ byte[] actual = new byte[length];
+ buffer.get(actual);
+ assertArrayEquals(Arrays.copyOfRange(inputData, pos, pos + length), actual,
Review Comment:
Same here—allocating a new array with `Arrays.copyOfRange` introduces
unnecessary memory copy, similar to my comment above. Please avoid copying here
as well.
--
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]