Search in sources :

Example 1 with JdbcBufferedInserter

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

the class MySqlBufferedInserterTest method testMySqlBufferedInsert.

public void testMySqlBufferedInsert() throws SQLException {
    final int colNums = 20;
    final int batchSize = 10;
    final int entryCount = 107;
    final int colSize = 7;
    State state = new State();
    state.setProp(WRITER_JDBC_INSERT_BATCH_SIZE, Integer.toString(batchSize));
    JdbcBufferedInserter inserter = getJdbcBufferedInserter(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();
    verify(conn, times(2)).prepareStatement(anyString());
    verify(pstmt, times(11)).clearParameters();
    verify(pstmt, times(11)).execute();
    verify(pstmt, times(colNums * entryCount)).setObject(anyInt(), anyObject());
    reset(pstmt);
}
Also used : State(org.apache.gobblin.configuration.State) PreparedStatement(java.sql.PreparedStatement) JdbcBufferedInserter(org.apache.gobblin.writer.commands.JdbcBufferedInserter) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData)

Example 2 with JdbcBufferedInserter

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

the class TeradataBufferedInserterTest method testTeradataBufferedInsert.

public void testTeradataBufferedInsert() throws SQLException {
    final int colNums = 20;
    final int batchSize = 10;
    final int entryCount = 107;
    final int colSize = 7;
    State state = new State();
    state.setProp(WRITER_JDBC_INSERT_BATCH_SIZE, Integer.toString(batchSize));
    JdbcBufferedInserter inserter = getJdbcBufferedInserter(state, conn);
    MockParameterMetaData mockMetadata = new MockParameterMetaData();
    mockMetadata.setParameterCount(2);
    mockMetadata.setParameterType(0, 12);
    mockMetadata.setParameterType(1, -5);
    PreparedStatement pstmt = Mockito.mock(PreparedStatement.class);
    when(pstmt.getParameterMetaData()).thenReturn(mockMetadata);
    when(pstmt.executeBatch()).thenReturn(new int[] { 1, 1, 1 });
    when(conn.prepareStatement(anyString())).thenReturn(pstmt);
    List<JdbcEntryData> jdbcEntries = createJdbcEntries(colNums, colSize, entryCount);
    for (JdbcEntryData entry : jdbcEntries) {
        inserter.insert(db, table, entry);
    }
    inserter.flush();
    verify(conn, times(2)).prepareStatement(anyString());
    verify(pstmt, times(107)).addBatch();
    verify(pstmt, times((int) Math.ceil((double) entryCount / batchSize))).executeBatch();
    verify(pstmt, times(entryCount)).clearParameters();
    verify(pstmt, times(colNums * entryCount)).setObject(anyInt(), anyObject());
    reset(pstmt);
}
Also used : State(org.apache.gobblin.configuration.State) PreparedStatement(java.sql.PreparedStatement) JdbcBufferedInserter(org.apache.gobblin.writer.commands.JdbcBufferedInserter) JdbcEntryData(org.apache.gobblin.converter.jdbc.JdbcEntryData) MockParameterMetaData(com.mockrunner.mock.jdbc.MockParameterMetaData)

Aggregations

PreparedStatement (java.sql.PreparedStatement)2 State (org.apache.gobblin.configuration.State)2 JdbcEntryData (org.apache.gobblin.converter.jdbc.JdbcEntryData)2 JdbcBufferedInserter (org.apache.gobblin.writer.commands.JdbcBufferedInserter)2 MockParameterMetaData (com.mockrunner.mock.jdbc.MockParameterMetaData)1