Search in sources :

Example 1 with MySqlBufferedInserter

use of org.apache.gobblin.writer.commands.MySqlBufferedInserter in project incubator-gobblin by apache.

the class MySqlBufferedInserterTest method testMySqlBufferedInsertParamLimit.

public void testMySqlBufferedInsertParamLimit() throws SQLException {
    final int colNums = 50;
    final int batchSize = 10;
    final int entryCount = 107;
    final int colSize = 3;
    final int maxParamSize = 500;
    State state = new State();
    state.setProp(WRITER_JDBC_INSERT_BATCH_SIZE, Integer.toString(batchSize));
    state.setProp(WRITER_JDBC_MAX_PARAM_SIZE, maxParamSize);
    MySqlBufferedInserter inserter = new MySqlBufferedInserter(state, conn);
    PreparedStatement pstmt = mock(PreparedStatement.class);
    when(conn.prepareStatement(anyString())).thenReturn(pstmt);
    List<JdbcEntryData> jdbcEntries = createJdbcEntries(colNums, colSize, entryCount);
    for (JdbcEntryData entry : jdbcEntries) {
        inserter.insert(db, table, entry);
    }
    inserter.flush();
    int expectedBatchSize = maxParamSize / colNums;
    int expectedExecuteCount = entryCount / expectedBatchSize + 1;
    verify(conn, times(2)).prepareStatement(anyString());
    verify(pstmt, times(expectedExecuteCount)).clearParameters();
    verify(pstmt, times(expectedExecuteCount)).execute();
    verify(pstmt, times(colNums * entryCount)).setObject(anyInt(), anyObject());
    reset(pstmt);
}
Also used : State(org.apache.gobblin.configuration.State) PreparedStatement(java.sql.PreparedStatement) MySqlBufferedInserter(org.apache.gobblin.writer.commands.MySqlBufferedInserter) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 State (org.apache.gobblin.configuration.State)1 JdbcEntryData (org.apache.gobblin.converter.jdbc.JdbcEntryData)1 MySqlBufferedInserter (org.apache.gobblin.writer.commands.MySqlBufferedInserter)1