use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteForMultipleStatementsSuccessWithDML.
@Test
public void assertExecuteForMultipleStatementsSuccessWithDML() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
when(statement1.execute(DML_SQL)).thenReturn(false);
when(statement2.execute(DML_SQL)).thenReturn(false);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement1, "ds_0", statement2, "ds_1"));
assertFalse(actual.execute());
verify(statement1).execute(DML_SQL);
verify(statement2).execute(DML_SQL);
verify(statement1).getConnection();
verify(statement2).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.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteQueryForMultipleStatementsSuccess.
@Test
public void assertExecuteQueryForMultipleStatementsSuccess() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
ResultSet resultSet1 = mock(ResultSet.class);
ResultSet resultSet2 = mock(ResultSet.class);
when(statement1.executeQuery(DQL_SQL)).thenReturn(resultSet1);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.executeQuery(DQL_SQL)).thenReturn(resultSet2);
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DQL, createStatementUnits(DQL_SQL, statement1, "ds_0", statement2, "ds_1"));
List<ResultSet> actualResultSets = actual.executeQuery();
assertThat(actualResultSets, hasItem(resultSet1));
assertThat(actualResultSets, hasItem(resultSet2));
verify(statement1).executeQuery(DQL_SQL);
verify(statement1).getConnection();
verify(statement2).executeQuery(DQL_SQL);
verify(statement2).getConnection();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(DQL_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.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteUpdateWithColumnIndexes.
@Test
public void assertExecuteUpdateWithColumnIndexes() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.executeUpdate(DML_SQL, new int[] { 1 })).thenReturn(10);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertThat(actual.executeUpdate(new int[] { 1 }), is(10));
verify(statement).executeUpdate(DML_SQL, new int[] { 1 });
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_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertOverallExceptionFailure.
@Test
public void assertOverallExceptionFailure() throws SQLException {
ExecutorExceptionHandler.setExceptionThrown(true);
Statement statement = mock(Statement.class);
SQLException exp = new SQLException();
when(statement.execute(DML_SQL)).thenThrow(exp);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
try {
assertFalse(actual.execute());
} catch (final SQLException ignore) {
}
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteUpdateForSingleStatementFailure.
@Test
public void assertExecuteUpdateForSingleStatementFailure() throws SQLException {
Statement statement = mock(Statement.class);
SQLException exp = new SQLException();
when(statement.executeUpdate(DML_SQL)).thenThrow(exp);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertThat(actual.executeUpdate(), is(0));
verify(statement).executeUpdate(DML_SQL);
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);
}
Aggregations