Search in sources :

Example 1 with BufferedConnectWriter

use of org.apache.hudi.connect.writers.BufferedConnectWriter in project hudi by apache.

the class TestBufferedConnectWriter method testSimpleWriteAndFlush.

@Test
public void testSimpleWriteAndFlush() throws Exception {
    String partitionPath = HoodieTestDataGenerator.DEFAULT_PARTITION_PATHS[0];
    HoodieTestDataGenerator dataGen = new HoodieTestDataGenerator(new String[] { partitionPath });
    List<HoodieRecord> records = dataGen.generateInserts(COMMIT_TIME, NUM_RECORDS);
    BufferedConnectWriter writer = new BufferedConnectWriter(javaEngineContext, mockHoodieJavaWriteClient, COMMIT_TIME, configs, writeConfig, null, schemaProvider);
    for (int i = 0; i < NUM_RECORDS; i++) {
        writer.writeHudiRecord(records.get(i));
    }
    Mockito.verify(mockHoodieJavaWriteClient, times(0)).bulkInsertPreppedRecords(anyList(), eq(COMMIT_TIME), eq(Option.empty()));
    writer.flushRecords();
    final ArgumentCaptor<List<HoodieRecord>> actualRecords = ArgumentCaptor.forClass(List.class);
    Mockito.verify(mockHoodieJavaWriteClient, times(1)).bulkInsertPreppedRecords(actualRecords.capture(), eq(COMMIT_TIME), eq(Option.empty()));
    actualRecords.getValue().sort(Comparator.comparing(HoodieRecord::getRecordKey));
    records.sort(Comparator.comparing(HoodieRecord::getRecordKey));
    assertEquals(records, actualRecords.getValue());
}
Also used : BufferedConnectWriter(org.apache.hudi.connect.writers.BufferedConnectWriter) HoodieRecord(org.apache.hudi.common.model.HoodieRecord) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) HoodieTestDataGenerator(org.apache.hudi.common.testutils.HoodieTestDataGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)1 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)1 HoodieTestDataGenerator (org.apache.hudi.common.testutils.HoodieTestDataGenerator)1 BufferedConnectWriter (org.apache.hudi.connect.writers.BufferedConnectWriter)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)1