use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method assertExecuteForMultiplePreparedStatementsFailureWithDML.
@Test
public void assertExecuteForMultiplePreparedStatementsFailureWithDML() throws SQLException {
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
SQLException exp = new SQLException();
when(preparedStatement1.execute()).thenThrow(exp);
when(preparedStatement2.execute()).thenThrow(exp);
when(preparedStatement1.getConnection()).thenReturn(mock(Connection.class));
when(preparedStatement2.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement1, "ds_0", preparedStatement2, "ds_1"), Collections.emptyList());
assertFalse(actual.execute());
verify(preparedStatement1).execute();
verify(preparedStatement2).execute();
verify(preparedStatement1).getConnection();
verify(preparedStatement2).getConnection();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(DML_SQL);
verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList());
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(getEventCaller(), times(2)).verifyException(exp);
}
use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method assertExecuteForMultiplePreparedStatementsSuccessWithDML.
@Test
public void assertExecuteForMultiplePreparedStatementsSuccessWithDML() throws SQLException {
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
when(preparedStatement1.execute()).thenReturn(false);
when(preparedStatement2.execute()).thenReturn(false);
when(preparedStatement1.getConnection()).thenReturn(mock(Connection.class));
when(preparedStatement2.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement1, "ds_0", preparedStatement2, "ds_1"), Collections.emptyList());
assertFalse(actual.execute());
verify(preparedStatement1).execute();
verify(preparedStatement2).execute();
verify(preparedStatement1).getConnection();
verify(preparedStatement2).getConnection();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(DML_SQL);
verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList());
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method assertExecuteUpdateForSinglePreparedStatementFailure.
@Test
public void assertExecuteUpdateForSinglePreparedStatementFailure() throws SQLException {
PreparedStatement preparedStatement = mock(PreparedStatement.class);
SQLException exp = new SQLException();
when(preparedStatement.executeUpdate()).thenThrow(exp);
when(preparedStatement.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement, "ds_0"), Collections.emptyList());
assertThat(actual.executeUpdate(), is(0));
verify(preparedStatement).executeUpdate();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DML_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(getEventCaller()).verifyException(exp);
}
use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method assertExecuteForSinglePreparedStatementFailureWithDML.
@Test
public void assertExecuteForSinglePreparedStatementFailureWithDML() throws SQLException {
PreparedStatement preparedStatement = mock(PreparedStatement.class);
SQLException exp = new SQLException();
when(preparedStatement.execute()).thenThrow(exp);
when(preparedStatement.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement, "ds_0"), Collections.emptyList());
assertFalse(actual.execute());
verify(preparedStatement).execute();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DML_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(getEventCaller()).verifyException(exp);
}
use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.
the class PreparedStatementExecutorTest method assertNoStatement.
@SuppressWarnings("unchecked")
@Test
public void assertNoStatement() throws SQLException {
PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DQL, Collections.<PreparedStatementUnit>emptyList(), Collections.emptyList());
assertFalse(actual.execute());
assertThat(actual.executeUpdate(), is(0));
assertThat(actual.executeQuery().size(), is(0));
}
Aggregations