/** * Flushes JdbcWriterCommands and commit. * {@inheritDoc} * @see org.apache.gobblin.writer.DataWriter#commit() */ @Override public void commit() throws IOException { try { LOG.info("Flushing pending insert."); this.commands.flush(); LOG.info("Commiting transaction."); this.conn.commit(); } catch (Exception e) { this.failed = true; throw new RuntimeException(e); } }
@Test public void writeAndCommitTest() throws SQLException, IOException { final String database = "db"; final String table = "users"; final int writeCount = 25; JdbcWriterCommands writerCommands = mock(JdbcWriterCommands.class); Connection conn = mock(Connection.class); try (JdbcWriter writer = new JdbcWriter(writerCommands, new State(), database, table, conn)) { for(int i = 0; i < writeCount; i++) { writer.write(null); } writer.commit(); Assert.assertEquals(writer.recordsWritten(), writeCount); } verify(writerCommands, times(writeCount)).insert(anyString(), anyString(), any(JdbcEntryData.class)); verify(conn, times(1)).commit(); verify(conn, never()).rollback(); verify(writerCommands, times(1)).flush(); verify(conn, times(1)).close(); }
/** * Flushes JdbcWriterCommands and commit. * {@inheritDoc} * @see org.apache.gobblin.writer.DataWriter#commit() */ @Override public void commit() throws IOException { try { LOG.info("Flushing pending insert."); this.commands.flush(); LOG.info("Commiting transaction."); this.conn.commit(); } catch (Exception e) { this.failed = true; throw new RuntimeException(e); } }