/** * Expects all data is in staging table ready to be published. To validate this, it checks COMMIT_ON_FULL_SUCCESS and PUBLISH_DATA_AT_JOB_LEVEL * @param state * @param jdbcWriterCommandsFactory * @param conn */ @VisibleForTesting public JdbcPublisher(State state, JdbcWriterCommandsFactory jdbcWriterCommandsFactory) { super(state); this.jdbcWriterCommandsFactory = jdbcWriterCommandsFactory; validate(getState()); }
@AfterMethod private void cleanup() throws IOException { publisher.close(); }
Set<String> emptiedDestTables = Sets.newHashSet(); final Connection conn = createConnection(); final JdbcWriterCommands commands = this.jdbcWriterCommandsFactory.newInstance(this.state, conn); try { Map<String, List<WorkUnitState>> stagingTables = getStagingTables(states, branches, i); for (Map.Entry<String, List<WorkUnitState>> entry : stagingTables.entrySet()) { String stagingTable = entry.getKey();
@BeforeMethod private void setup() { state = new State(); state.setProp(JdbcPublisher.JDBC_PUBLISHER_FINAL_TABLE_NAME, destinationTable); state.setProp(JdbcPublisher.JDBC_PUBLISHER_DATABASE_NAME, database); commands = mock(JdbcWriterCommands.class); factory = mock(JdbcWriterCommandsFactory.class); conn = mock(Connection.class); when(factory.newInstance(state, conn)).thenReturn(commands); workUnitStates = new ArrayList<>(); workUnitState = mock(WorkUnitState.class); when(workUnitState.getProp(ConfigurationKeys.WRITER_STAGING_TABLE)).thenReturn(stagingTable); workUnitStates.add(workUnitState); publisher = new JdbcPublisher(state, factory); publisher = spy(publisher); doReturn(conn).when(publisher).createConnection(); }
/** * @param state * @throws IllegalArgumentException If job commit policy is not COMMIT_ON_FULL_SUCCESS or is not on PUBLISH_DATA_AT_JOB_LEVEL */ private void validate(State state) { JobCommitPolicy jobCommitPolicy = JobCommitPolicy.getCommitPolicy(this.getState().getProperties()); if (JobCommitPolicy.COMMIT_ON_FULL_SUCCESS != jobCommitPolicy) { throw new IllegalArgumentException(this.getClass().getSimpleName() + " won't publish as already commited by task. Job commit policy " + jobCommitPolicy); } if (!state.getPropAsBoolean(ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL, ConfigurationKeys.DEFAULT_PUBLISH_DATA_AT_JOB_LEVEL)) { throw new IllegalArgumentException(this.getClass().getSimpleName() + " won't publish as " + ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL + " is set as false"); } }
public void testPublish() throws IOException, SQLException { publisher.publish(workUnitStates); InOrder inOrder = inOrder(conn, commands, workUnitState); inOrder.verify(conn, times(1)).setAutoCommit(false); inOrder.verify(commands, times(1)).copyTable(database, stagingTable, destinationTable); inOrder.verify(workUnitState, times(1)).setWorkingState(WorkUnitState.WorkingState.COMMITTED); inOrder.verify(conn, times(1)).commit(); inOrder.verify(conn, times(1)).close(); verify(commands, never()).deleteAll(database, destinationTable); }
Set<String> emptiedDestTables = Sets.newHashSet(); final Connection conn = createConnection(); final JdbcWriterCommands commands = this.jdbcWriterCommandsFactory.newInstance(this.state, conn); try { Map<String, List<WorkUnitState>> stagingTables = getStagingTables(states, branches, i); for (Map.Entry<String, List<WorkUnitState>> entry : stagingTables.entrySet()) { String stagingTable = entry.getKey();
/** * @param state * @throws IllegalArgumentException If job commit policy is not COMMIT_ON_FULL_SUCCESS or is not on PUBLISH_DATA_AT_JOB_LEVEL */ private void validate(State state) { JobCommitPolicy jobCommitPolicy = JobCommitPolicy.getCommitPolicy(this.getState().getProperties()); if (JobCommitPolicy.COMMIT_ON_FULL_SUCCESS != jobCommitPolicy) { throw new IllegalArgumentException(this.getClass().getSimpleName() + " won't publish as already commited by task. Job commit policy " + jobCommitPolicy); } if (!state.getPropAsBoolean(ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL, ConfigurationKeys.DEFAULT_PUBLISH_DATA_AT_JOB_LEVEL)) { throw new IllegalArgumentException(this.getClass().getSimpleName() + " won't publish as " + ConfigurationKeys.PUBLISH_DATA_AT_JOB_LEVEL + " is set as false"); } }
public void testPublishReplaceOutput() throws IOException, SQLException { state.setProp(JdbcPublisher.JDBC_PUBLISHER_REPLACE_FINAL_TABLE, Boolean.toString(true)); publisher.publish(workUnitStates); InOrder inOrder = inOrder(conn, commands, workUnitState); inOrder.verify(conn, times(1)).setAutoCommit(false); inOrder.verify(commands, times(1)).deleteAll(database, destinationTable); inOrder.verify(commands, times(1)).copyTable(database, stagingTable, destinationTable); inOrder.verify(workUnitState, times(1)).setWorkingState(WorkUnitState.WorkingState.COMMITTED); inOrder.verify(conn, times(1)).commit(); inOrder.verify(conn, times(1)).close(); }
public void testPublishFailure() throws SQLException, IOException { doThrow(RuntimeException.class).when(commands).copyTable(database, stagingTable, destinationTable); try { publisher.publish(workUnitStates); Assert.fail("Test case didn't throw Exception."); } catch (RuntimeException e) { Assert.assertTrue(e instanceof RuntimeException); } InOrder inOrder = inOrder(conn, commands, workUnitState); inOrder.verify(conn, times(1)).setAutoCommit(false); inOrder.verify(commands, times(1)).copyTable(database, stagingTable, destinationTable); inOrder.verify(conn, times(1)).rollback(); inOrder.verify(conn, times(1)).close(); verify(conn, never()).commit(); verify(commands, never()).deleteAll(database, destinationTable); verify(workUnitState, never()).setWorkingState(any(WorkUnitState.WorkingState.class)); } }
/** * Expects all data is in staging table ready to be published. To validate this, it checks COMMIT_ON_FULL_SUCCESS and PUBLISH_DATA_AT_JOB_LEVEL * @param state * @param jdbcWriterCommandsFactory * @param conn */ @VisibleForTesting public JdbcPublisher(State state, JdbcWriterCommandsFactory jdbcWriterCommandsFactory) { super(state); this.jdbcWriterCommandsFactory = jdbcWriterCommandsFactory; validate(getState()); }