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/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new 6274da1b5 [MINOR] improvement(test): Identify duplicate blocks in 
TestUtils.validateResult (#1495)
6274da1b5 is described below

commit 6274da1b5f023af4b9bd6992aa28c1a4a83cb95c
Author: Enrico Minack <[email protected]>
AuthorDate: Thu Feb 1 02:31:08 2024 +0100

    [MINOR] improvement(test): Identify duplicate blocks in 
TestUtils.validateResult (#1495)
    
    ### What changes were proposed in this pull request?
    Do not check for blocks that have already been found in data stream.
    
    ### Why are the changes needed?
    The method `TestUtils.validateResult` would pass check of a data stream 
returned by `readClient.readShuffleBlockData()` that contains duplicate blocks 
(let's say the first block in `expectedData`) while overall cardinality of 
blocks match expectation (let's say that first block is duplicated 
`expectedData.size()`-times). Such a situation should throw an assertion error.
    
    Further, the inner loop can be left on match, which saves computation time.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    Not tested.
---
 client/src/test/java/org/apache/uniffle/client/TestUtils.java | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/client/src/test/java/org/apache/uniffle/client/TestUtils.java 
b/client/src/test/java/org/apache/uniffle/client/TestUtils.java
index f83ab6e13..8b284567e 100644
--- a/client/src/test/java/org/apache/uniffle/client/TestUtils.java
+++ b/client/src/test/java/org/apache/uniffle/client/TestUtils.java
@@ -18,6 +18,7 @@
 package org.apache.uniffle.client;
 
 import java.nio.ByteBuffer;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -36,14 +37,18 @@ public class TestUtils {
   private TestUtils() {}
 
   public static void validateResult(ShuffleReadClient readClient, Map<Long, 
byte[]> expectedData) {
+    Map<Long, byte[]> pendingData = new HashMap<>(expectedData);
+
     ByteBuffer data = readClient.readShuffleBlockData().getByteBuffer();
     int blockNum = 0;
     while (data != null) {
       blockNum++;
       boolean match = false;
-      for (byte[] expected : expectedData.values()) {
-        if (compareByte(expected, data)) {
+      for (Map.Entry<Long, byte[]> expected : pendingData.entrySet()) {
+        if (compareByte(expected.getValue(), data)) {
           match = true;
+          pendingData.remove(expected.getKey());
+          break;
         }
       }
       assertTrue(match);
@@ -54,6 +59,7 @@ public class TestUtils {
         data = csb.getByteBuffer();
       }
     }
+    assertEquals(pendingData.size(), 0);
     assertEquals(expectedData.size(), blockNum);
   }
 

Reply via email to