smengcl commented on code in PR #12042:
URL: https://github.com/apache/ozone/pull/12042#discussion_r4566114917


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java:
##########
@@ -1675,6 +1677,25 @@ public void 
testReadBlockResponseShorterThanResponseDataSize() throws Exception
     }
   }
 
+  @Test
+  void testReadBlockBufferIsAtMostTheRequestedRange() throws Exception {
+    final int unit = (int) BYTES_PER_CHECKSUM;
+    try (StreamFixture fixture = new StreamFixture()) {
+      fixture.appendChunk("chunk1", 0, 4 * unit);
+      fixture.appendChunk("chunk2", 4 * unit, 20);
+      assertResponses(fixture.read(unit + 1, 1, 1 << 20), unit, unit);
+      assertResponses(fixture.read(4 * unit + 5, 100, 1 << 20), 4 * unit, 20);
+      ReadBlockResult twoResponses = fixture.read(0, 4 * unit + 20, 3 * unit);
+      assertResponses(twoResponses, 0, 4 * unit + 20);
+      assertEquals(2, twoResponses.getDataResponses().size());
+
+      ArgumentCaptor<ByteBuffer> buffers = 
ArgumentCaptor.forClass(ByteBuffer.class);
+      verify(fixture.blockFile, times(4)).read(buffers.capture());
+      assertEquals(Arrays.asList(unit, 20, 3 * unit, 3 * unit),
+          
buffers.getAllValues().stream().map(ByteBuffer::capacity).collect(Collectors.toList()));

Review Comment:
   nit: AssertJ is already imported here, so this could be:
   
   ```
   
assertThat(buffers.getAllValues()).extracting(ByteBuffer::capacity).containsExactly(unit,
 20, 3 * unit, 3 * unit);`
   ```
   
   It also prints the mismatching capacities on failure and lets us drop the 
new `Arrays` and `Collectors` imports.



-- 
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]

Reply via email to