Search in sources :

Example 21 with PreparedStatementExecutorWrapper

use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.

the class PreparedStatementExecutorTest method assertExecuteUpdateForSinglePreparedStatementSuccess.

@Test
public void assertExecuteUpdateForSinglePreparedStatementSuccess() throws SQLException {
    PreparedStatement preparedStatement = mock(PreparedStatement.class);
    PreparedStatementExecutorWrapper wrapper = createPreparedStatementExecutorWrapperForDML(preparedStatement, "ds_0");
    when(preparedStatement.executeUpdate()).thenReturn(10);
    PreparedStatementExecutor actual = new PreparedStatementExecutor(executorEngine, Collections.singleton(wrapper));
    assertThat(actual.executeUpdate(), is(10));
    verify(preparedStatement).executeUpdate();
    verify(eventCaller, times(2)).verifyDataSource("ds_0");
    verify(eventCaller, times(2)).verifySQL("DELETE FROM dual");
    verify(eventCaller, times(2)).verifyParameters(Collections.emptyList());
    verify(eventCaller).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
    verify(eventCaller).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
    verify(eventCaller, times(0)).verifyException(null);
}
Also used : PreparedStatementExecutorWrapper(com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Aggregations

PreparedStatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper)21 PreparedStatement (java.sql.PreparedStatement)15 Test (org.junit.Test)14 SQLException (java.sql.SQLException)9 Connection (java.sql.Connection)7 Context (com.codahale.metrics.Timer.Context)4 MetricsContext (com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext)4 ResultSet (java.sql.ResultSet)4 MergeContext (com.dangdang.ddframe.rdb.sharding.parser.result.merger.MergeContext)1 SQLExecutionUnit (com.dangdang.ddframe.rdb.sharding.router.SQLExecutionUnit)1 SQLRouteResult (com.dangdang.ddframe.rdb.sharding.router.SQLRouteResult)1 ArrayList (java.util.ArrayList)1