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());
}
Aggregations