use of org.apache.flink.connector.jdbc.JdbcDataTestBase in project flink by apache.
the class JdbcTableOutputFormatTest method testJdbcOutputFormat.
@Test
public void testJdbcOutputFormat() throws Exception {
JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl(getDbMetadata().getUrl()).setTableName(OUTPUT_TABLE).build();
JdbcDmlOptions dmlOptions = JdbcDmlOptions.builder().withTableName(options.getTableName()).withDialect(options.getDialect()).withFieldNames(fieldNames).withKeyFields(keyFields).build();
format = new TableJdbcUpsertOutputFormat(new SimpleJdbcConnectionProvider(options), dmlOptions, JdbcExecutionOptions.defaults());
RuntimeContext context = Mockito.mock(RuntimeContext.class);
ExecutionConfig config = Mockito.mock(ExecutionConfig.class);
doReturn(config).when(context).getExecutionConfig();
doReturn(true).when(config).isObjectReuseEnabled();
format.setRuntimeContext(context);
format.open(0, 1);
for (TestEntry entry : TEST_DATA) {
format.writeRecord(Tuple2.of(true, toRow(entry)));
}
format.flush();
check(Arrays.stream(TEST_DATA).map(JdbcDataTestBase::toRow).toArray(Row[]::new));
// override
for (TestEntry entry : TEST_DATA) {
format.writeRecord(Tuple2.of(true, toRow(entry)));
}
format.flush();
check(Arrays.stream(TEST_DATA).map(JdbcDataTestBase::toRow).toArray(Row[]::new));
// delete
for (int i = 0; i < TEST_DATA.length / 2; i++) {
format.writeRecord(Tuple2.of(false, toRow(TEST_DATA[i])));
}
Row[] expected = new Row[TEST_DATA.length - TEST_DATA.length / 2];
for (int i = TEST_DATA.length / 2; i < TEST_DATA.length; i++) {
expected[i - TEST_DATA.length / 2] = toRow(TEST_DATA[i]);
}
format.flush();
check(expected);
}
Aggregations