This is an automated email from the ASF dual-hosted git repository.

zuston pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ccd91f1b [#2614] improvement(client): Add test case for Incorrect 
header length for getLocalShuffleDataV3 (#2617)
3ccd91f1b is described below

commit 3ccd91f1bcc85cc791ab1017ba199d38679118cd
Author: Neo Chien <[email protected]>
AuthorDate: Mon Sep 22 17:02:42 2025 +0800

    [#2614] improvement(client): Add test case for Incorrect header length for 
getLocalShuffleDataV3 (#2617)
    
    ### What changes were proposed in this pull request?
    Add test case for Incorrect header length for getLocalShuffleDataV3
    
    ### Why are the changes needed?
    for https://github.com/apache/uniffle/issues/2614
    
    ### Does this PR introduce any user-facing change?
    No.
    
    ### How was this patch tested?
    UT
---
 .../protocol/GetLocalShuffleDataV3Request.java     |  8 +++
 .../common/netty/protocol/NettyProtocolTest.java   | 58 ++++++++++++++++++++++
 .../netty/protocol/NettyProtocolTestUtils.java     | 40 +++++++++++++++
 3 files changed, 106 insertions(+)

diff --git 
a/common/src/main/java/org/apache/uniffle/common/netty/protocol/GetLocalShuffleDataV3Request.java
 
b/common/src/main/java/org/apache/uniffle/common/netty/protocol/GetLocalShuffleDataV3Request.java
index 66cd5a3c7..f2fbe958e 100644
--- 
a/common/src/main/java/org/apache/uniffle/common/netty/protocol/GetLocalShuffleDataV3Request.java
+++ 
b/common/src/main/java/org/apache/uniffle/common/netty/protocol/GetLocalShuffleDataV3Request.java
@@ -118,4 +118,12 @@ public class GetLocalShuffleDataV3Request extends 
GetLocalShuffleDataV2Request {
   public String getOperationType() {
     return "getLocalShuffleDataV3";
   }
+
+  public List<ReadSegment> getNextReadSegments() {
+    return nextReadSegments;
+  }
+
+  public long getTaskAttemptId() {
+    return taskAttemptId;
+  }
 }
diff --git 
a/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTest.java
 
b/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTest.java
index 276165d96..769fe73c8 100644
--- 
a/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTest.java
+++ 
b/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTest.java
@@ -18,6 +18,7 @@
 package org.apache.uniffle.common.netty.protocol;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test;
 import org.roaringbitmap.longlong.Roaring64NavigableMap;
 
 import org.apache.uniffle.common.BufferSegment;
+import org.apache.uniffle.common.ReadSegment;
 import org.apache.uniffle.common.ShuffleBlockInfo;
 import org.apache.uniffle.common.ShufflePartitionedBlock;
 import org.apache.uniffle.common.ShuffleServerInfo;
@@ -166,6 +168,62 @@ public class NettyProtocolTest {
         getLocalShuffleDataRequest.getTimestamp(), 
getLocalShuffleDataRequest1.getTimestamp());
   }
 
+  @Test
+  public void testGetLocalShuffleDataV3Request() {
+    List<ReadSegment> readSegments =
+        Lists.newArrayList(new ReadSegment(100, 100), new ReadSegment(200, 
200));
+    GetLocalShuffleDataV3Request request =
+        new GetLocalShuffleDataV3Request(
+            1L,
+            "test_app",
+            1,
+            1,
+            1,
+            100,
+            0,
+            200,
+            1,
+            readSegments,
+            System.currentTimeMillis(),
+            123L);
+    int encodeLength = request.encodedLength();
+    ByteBuf byteBuf = Unpooled.buffer(encodeLength, encodeLength);
+    request.encode(byteBuf);
+    assertEquals(encodeLength, byteBuf.readableBytes());
+    GetLocalShuffleDataV3Request decodedRequest = 
GetLocalShuffleDataV3Request.decode(byteBuf);
+    
assertTrue(NettyProtocolTestUtils.compareGetLocalShuffleDataV3Request(request, 
decodedRequest));
+    byteBuf.release();
+  }
+
+  @Test
+  public void testGetLocalShuffleDataV3RequestWithEmptySegments() {
+    // Edge case: Test with an empty list of read segments.
+    List<ReadSegment> readSegments = Collections.emptyList();
+    GetLocalShuffleDataV3Request request =
+        new GetLocalShuffleDataV3Request(
+            2L,
+            "test_app_empty",
+            2,
+            2,
+            2,
+            200,
+            0,
+            300,
+            2,
+            readSegments,
+            System.currentTimeMillis(),
+            456L);
+
+    int encodeLength = request.encodedLength();
+    ByteBuf byteBuf = Unpooled.buffer(encodeLength, encodeLength);
+    request.encode(byteBuf);
+    assertEquals(encodeLength, byteBuf.readableBytes());
+
+    GetLocalShuffleDataV3Request decodedRequest = 
GetLocalShuffleDataV3Request.decode(byteBuf);
+    
assertTrue(NettyProtocolTestUtils.compareGetLocalShuffleDataV3Request(request, 
decodedRequest));
+    byteBuf.release();
+  }
+
   @Test
   public void testGetLocalShuffleDataResponse() {
     byte[] data = new byte[] {1, 2, 3};
diff --git 
a/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTestUtils.java
 
b/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTestUtils.java
index 3ce237cd2..45eb0d6c4 100644
--- 
a/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTestUtils.java
+++ 
b/common/src/test/java/org/apache/uniffle/common/netty/protocol/NettyProtocolTestUtils.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.uniffle.common.ReadSegment;
 import org.apache.uniffle.common.ShuffleBlockInfo;
 import org.apache.uniffle.common.ShufflePartitionedBlock;
 
@@ -138,4 +139,43 @@ public class NettyProtocolTestUtils {
     }
     return comparePartitionToBlockListV1(req1.getPartitionToBlocks(), 
req2.getPartitionToBlocks());
   }
+
+  private static boolean compareReadSegment(List<ReadSegment> list1, 
List<ReadSegment> list2) {
+    if (list1 == list2) {
+      return true;
+    }
+    if (list1 == null || list2 == null || list1.size() != list2.size()) {
+      return false;
+    }
+    for (int i = 0; i < list1.size(); ++i) {
+      ReadSegment seg1 = list1.get(i);
+      ReadSegment seg2 = list2.get(i);
+      if (seg1.getOffset() != seg2.getOffset() || seg1.getLength() != 
seg2.getLength()) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  public static boolean compareGetLocalShuffleDataV3Request(
+      GetLocalShuffleDataV3Request req1, GetLocalShuffleDataV3Request req2) {
+    if (req1 == req2) {
+      return true;
+    }
+    if (req1 == null || req2 == null) {
+      return false;
+    }
+    return req1.getRequestId() == req2.getRequestId()
+        && req1.getAppId().equals(req2.getAppId())
+        && req1.getShuffleId() == req2.getShuffleId()
+        && req1.getPartitionId() == req2.getPartitionId()
+        && req1.getPartitionNumPerRange() == req2.getPartitionNumPerRange()
+        && req1.getPartitionNum() == req2.getPartitionNum()
+        && req1.getOffset() == req2.getOffset()
+        && req1.getLength() == req2.getLength()
+        && req1.getTimestamp() == req2.getTimestamp()
+        && req1.getStorageId() == req2.getStorageId()
+        && req1.getTaskAttemptId() == req2.getTaskAttemptId()
+        && compareReadSegment(req1.getNextReadSegments(), 
req2.getNextReadSegments());
+  }
 }

Reply via email to