use of org.apache.flink.connector.jdbc.JdbcTestFixture.TestEntry in project flink by apache.
the class JdbcRowOutputFormatTest method testExceptionOnClose.
@Test
public void testExceptionOnClose() {
String expectedMsg = "Writing records to JDBC failed.";
try {
jdbcOutputFormat = JdbcRowOutputFormat.buildJdbcOutputFormat().setDrivername(DERBY_EBOOKSHOP_DB.getDriverClass()).setDBUrl(DERBY_EBOOKSHOP_DB.getUrl()).setQuery(String.format(INSERT_TEMPLATE, OUTPUT_TABLE)).setSqlTypes(new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.DOUBLE, Types.INTEGER }).finish();
setRuntimeContext(jdbcOutputFormat, true);
jdbcOutputFormat.open(0, 1);
TestEntry entry = TEST_DATA[0];
Row row = new Row(5);
row.setField(0, entry.id);
row.setField(1, entry.title);
row.setField(2, entry.author);
row.setField(3, entry.price);
row.setField(4, entry.qty);
jdbcOutputFormat.writeRecord(row);
jdbcOutputFormat.writeRecord(// writing the same record twice must yield a unique key violation.
row);
jdbcOutputFormat.close();
} catch (Exception e) {
assertTrue(findThrowable(e, RuntimeException.class).isPresent());
assertTrue(findThrowableWithMessage(e, expectedMsg).isPresent());
}
}
Aggregations