jonvex commented on code in PR #13860:
URL: https://github.com/apache/hudi/pull/13860#discussion_r2359739916


##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/io/TestMergeHandle.java:
##########
@@ -238,30 +236,23 @@ void testWriteFailures() throws Exception {
     FileGroupReaderBasedMergeHandle fileGroupReaderBasedMergeHandle = new 
FileGroupReaderBasedMergeHandle(
         config, instantTime, table, updates.iterator(), partitionPath, fileId, 
new LocalTaskContextSupplier(),
         Option.empty());
-
+    List<WriteStatus> writeStatuses;
     String recordKeyForFailure = updates.get(5).getRecordKey();
-    try (MockedStatic<HoodieAvroUtils> mockedStatic = 
mockStatic(HoodieAvroUtils.class, 
Mockito.withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS))) {
-      int position = AVRO_SCHEMA.getField("_row_key").pos();
-      mockedStatic.when(() -> 
HoodieAvroUtils.rewriteRecordWithNewSchema(any(), 
any())).thenAnswer(invocationOnMock -> {
-        IndexedRecord record = invocationOnMock.getArgument(0);
-        if (record.get(position).toString().equals(recordKeyForFailure)) {
-          throw new HoodieIOException("Simulated write failure for record key: 
" + recordKeyForFailure);
-        }
-        return HoodieAvroUtils.rewriteRecordWithNewSchema((IndexedRecord) 
invocationOnMock.getArgument(0), invocationOnMock.getArgument(1), 
Collections.emptyMap());
-      });
+
+    try (MockedConstruction<JoinedGenericRecord> mocked = 
mockConstruction(JoinedGenericRecord.class,
+        (mock, context) -> {
+          doThrow(new HoodieIOException("Simulated write failure for record 
key: " + recordKeyForFailure))
+              .when(mock).put(any(), any());
+      })) {
       fileGroupReaderBasedMergeHandle.doMerge();
     }
 
-    List<WriteStatus> writeStatuses = fileGroupReaderBasedMergeHandle.close();
+    writeStatuses = fileGroupReaderBasedMergeHandle.close();
     WriteStatus writeStatus = writeStatuses.get(0);
-    assertEquals(1, writeStatus.getErrors().size());
+    assertEquals(2, writeStatus.getErrors().size());
     // check that record and secondary index stats are non-empty
-    assertFalse(writeStatus.getWrittenRecordDelegates().isEmpty());
-    
assertFalse(writeStatus.getIndexStats().getSecondaryIndexStats().values().stream().flatMap(Collection::stream).count()
 == 0L);
-
-    writeStatus.getWrittenRecordDelegates().forEach(recordDelegate -> 
assertNotEquals(recordKeyForFailure, recordDelegate.getRecordKey()));
-    
writeStatus.getIndexStats().getSecondaryIndexStats().values().stream().flatMap(Collection::stream)
-        .forEach(secondaryIndexStats -> assertNotEquals(recordKeyForFailure, 
secondaryIndexStats.getRecordKey()));
+    assertTrue(writeStatus.getWrittenRecordDelegates().isEmpty());
+    
assertTrue(writeStatus.getIndexStats().getSecondaryIndexStats().values().stream().flatMap(Collection::stream).count()
 == 0L);

Review Comment:
   why is this true now?



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

Reply via email to