|
29 | 29 | import org.apache.avro.Schema;
|
30 | 30 | import org.apache.avro.generic.GenericData;
|
31 | 31 | import org.apache.avro.generic.GenericRecord;
|
32 |
| -import org.apache.spark.SparkException; |
33 | 32 | import org.apache.spark.api.java.JavaRDD;
|
34 | 33 | import org.junit.jupiter.api.BeforeAll;
|
35 | 34 | import org.junit.jupiter.params.ParameterizedTest;
|
36 | 35 | import org.junit.jupiter.params.provider.EnumSource;
|
| 36 | +import org.mockito.ArgumentCaptor; |
37 | 37 | import org.mockito.Mockito;
|
38 | 38 |
|
39 | 39 | import java.util.Collections;
|
| 40 | +import java.util.List; |
40 | 41 |
|
41 |
| -import static org.junit.jupiter.api.Assertions.assertThrows; |
42 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 42 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 43 | +import static org.mockito.Mockito.doNothing; |
43 | 44 |
|
44 | 45 | /**
|
45 | 46 | * Tests {@link HoodieStreamerUtils}.
|
@@ -73,12 +74,13 @@ public void testCreateHoodieRecordsWithError(HoodieRecordType recordType) {
|
73 | 74 | TypedProperties props = new TypedProperties();
|
74 | 75 | SchemaProvider schemaProvider = new SimpleSchemaProvider(jsc, schema, props);
|
75 | 76 | BaseErrorTableWriter errorTableWriter = Mockito.mock(BaseErrorTableWriter.class);
|
76 |
| - SparkException exception = assertThrows( |
77 |
| - SparkException.class, |
78 |
| - () -> HoodieStreamerUtils.createHoodieRecords(cfg, props, Option.of(recordRdd), |
79 |
| - schemaProvider, recordType, false, "000", Option.of(errorTableWriter)) |
80 |
| - .get().collect() |
81 |
| - ); |
82 |
| - assertTrue(exception.getMessage().contains("Failed to convert illegal record to json")); |
| 77 | + ArgumentCaptor<JavaRDD<?>> errorEventCaptor = ArgumentCaptor.forClass(JavaRDD.class); |
| 78 | + doNothing().when(errorTableWriter).addErrorEvents(errorEventCaptor.capture()); |
| 79 | + HoodieStreamerUtils.createHoodieRecords(cfg, props, Option.of(recordRdd), |
| 80 | + schemaProvider, recordType, false, "000", Option.of(errorTableWriter)); |
| 81 | + List<ErrorEvent<String>> actualErrorEvents = (List<ErrorEvent<String>>) errorEventCaptor.getValue().collect(); |
| 82 | + ErrorEvent<String> expectedErrorEvent = new ErrorEvent<>("{\"timestamp\": 1000, \"_row_key\": \"key1\", \"partition_path\": \"path1\", \"rider\": null, \"driver\": \"driver\"}", |
| 83 | + ErrorEvent.ErrorReason.RECORD_CREATION); |
| 84 | + assertEquals(Collections.singletonList(expectedErrorEvent), actualErrorEvents); |
83 | 85 | }
|
84 | 86 | }
|
0 commit comments