1818package org .apache .uniffle .client .impl ;
1919
2020import java .nio .ByteBuffer ;
21+ import java .util .LinkedHashMap ;
2122import java .util .List ;
2223import java .util .Map ;
2324import java .util .Random ;
3839
3940import org .apache .uniffle .client .TestUtils ;
4041import org .apache .uniffle .client .factory .ShuffleClientFactory ;
41- import org .apache .uniffle .client .response .ShuffleBlock ;
4242import org .apache .uniffle .common .ClientType ;
4343import org .apache .uniffle .common .ShufflePartitionedBlock ;
4444import org .apache .uniffle .common .ShuffleServerInfo ;
5959import static org .junit .jupiter .api .Assertions .assertTrue ;
6060import static org .junit .jupiter .api .Assertions .fail ;
6161import static org .mockito .ArgumentMatchers .any ;
62+ import static org .mockito .ArgumentMatchers .anyInt ;
6263
6364public class ShuffleReadClientImplTest extends HadoopTestBase {
6465
@@ -371,11 +372,14 @@ public void readTest8(Supplier<ShuffleClientFactory.ReadClientBuilder> builderSu
371372 String basePath = uniq (HDFS_URI + "clientReadTest8" );
372373 HadoopShuffleWriteHandler writeHandler =
373374 new HadoopShuffleWriteHandler ("appId" , 0 , 0 , 1 , basePath , ssi1 .getId (), conf );
375+ HadoopShuffleWriteHandler writeHandler2 =
376+ new HadoopShuffleWriteHandler ("appId" , 0 , 0 , 1 , basePath , ssi2 .getId (), conf );
374377
375- Map <Long , byte []> expectedData = Maps .newHashMap ();
378+ LinkedHashMap <Long , byte []> expectedData = Maps .newLinkedHashMap ();
376379 Roaring64NavigableMap blockIdBitmap = Roaring64NavigableMap .bitmapOf ();
377380 Roaring64NavigableMap taskIdBitmap = Roaring64NavigableMap .bitmapOf (0 );
378381 writeTestData (writeHandler , 2 , 30 , 0 , 0 , expectedData , blockIdBitmap );
382+ writeTestData (writeHandler2 , 2 , 30 , 0 , 0 , expectedData , blockIdBitmap );
379383 ShuffleReadClientImpl readClient =
380384 builderSupplier
381385 .get ()
@@ -396,8 +400,19 @@ public void readTest8(Supplier<ShuffleClientFactory.ReadClientBuilder> builderSu
396400 .shuffleServerInfoList (Lists .newArrayList (ssi1 , ssi2 ))
397401 .build ();
398402 // crc32 is incorrect
403+ AtomicInteger readCount = new AtomicInteger (0 );
399404 try (MockedStatic <ChecksumUtils > checksumUtilsMock = Mockito .mockStatic (ChecksumUtils .class )) {
400- checksumUtilsMock .when (() -> ChecksumUtils .getCrc32 ((ByteBuffer ) any ())).thenReturn (-1L );
405+ checksumUtilsMock
406+ .when (() -> ChecksumUtils .getCrc32 (any (ByteBuffer .class ), anyInt (), anyInt ()))
407+ .then (
408+ invocation -> {
409+ // crc check fails for readClient1 and frist block of readClient2
410+ if (readCount .getAndIncrement () < 2 ) {
411+ return -1 ;
412+ } else {
413+ return invocation .callRealMethod ();
414+ }
415+ });
401416 try {
402417 ByteBuffer bb = readClient .readShuffleBlockData ().getByteBuffer ();
403418 while (bb != null ) {
@@ -408,8 +423,15 @@ public void readTest8(Supplier<ShuffleClientFactory.ReadClientBuilder> builderSu
408423 assertTrue (e .getMessage ().startsWith ("Unexpected crc value" ), e .getMessage ());
409424 }
410425
411- ShuffleBlock block = readClient2 .readShuffleBlockData ();
412- assertNull (block );
426+ // the frist block has been skipped due to crc check failure
427+ Long firstKey = expectedData .keySet ().iterator ().next ();
428+ expectedData .remove (firstKey );
429+ TestUtils .validateResult (readClient2 , expectedData );
430+ try {
431+ readClient2 .checkProcessedBlockIds ();
432+ } catch (Exception e ) {
433+ assertTrue (e .getMessage ().contains ("expected 4 blocks, actual 3 blocks" ), e .getMessage ());
434+ }
413435 }
414436 readClient .close ();
415437 readClient2 .close ();
0 commit comments