adoroszlai commented on code in PR #7564:
URL: https://github.com/apache/ozone/pull/7564#discussion_r1884381131


##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/utils/MockGatheringChannel.java:
##########
@@ -17,10 +17,13 @@
  */
 package org.apache.hadoop.hdds.utils;
 
+import org.junit.jupiter.api.Assertions;

Review Comment:
   nit: please use static import for assertions and mocks (see HDDS-9961).



##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/utils/MockGatheringChannel.java:
##########
@@ -59,21 +78,36 @@ public long write(ByteBuffer[] srcs) throws IOException {
 
   @Override
   public int write(ByteBuffer src) throws IOException {
-    // If src has more than 1 byte left, simulate partial write by adjusting 
limit.
-    // Remaining 1 byte should be written on next call.
-    // This helps verify that the caller ensures buffer is written fully.
-    final int adjustment = 1;
-    final boolean limitWrite = src.remaining() > adjustment;
-    if (limitWrite) {
-      src.limit(src.limit() - adjustment);
-    }
-    try {
-      return delegate.write(src);
-    } finally {
-      if (limitWrite) {
-        src.limit(src.limit() + adjustment);
-      }
+    final int remaining = src.remaining();
+    if (remaining <= 0) {
+      return 0;
     }
+    // Simulate partial write by setting a random limit.
+    final int adjustment = ThreadLocalRandom.current().nextInt(remaining + 1);
+    return adjustedWrite(src, adjustment);
+  }
+
+  private int adjustedWrite(ByteBuffer src, int adjustment) throws IOException 
{
+    Assertions.assertTrue(adjustment >= 0);
+    final int remaining = src.remaining();
+    Assertions.assertTrue(adjustment <= remaining);

Review Comment:
   nit: prefer `assertThat(adjustment).isLessThanOrEqualTo(remaining)` and 
similar instead of `assertTrue` for better description in case of failure.



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