use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementExecutorTest method assertExecuteUpdateForMultiplePreparedStatementsSuccess.
@Test
public void assertExecuteUpdateForMultiplePreparedStatementsSuccess() throws SQLException {
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper1 = createPreparedStatementExecutorWrapperForDML(preparedStatement1, "ds_0");
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper2 = createPreparedStatementExecutorWrapperForDML(preparedStatement2, "ds_1");
when(preparedStatement1.executeUpdate()).thenReturn(10);
when(preparedStatement2.executeUpdate()).thenReturn(20);
when(preparedStatement1.getConnection()).thenReturn(mock(Connection.class));
when(preparedStatement2.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(executorEngine, Arrays.asList(wrapper1, wrapper2));
assertThat(actual.executeUpdate(), is(30));
verify(preparedStatement1).executeUpdate();
verify(preparedStatement2).executeUpdate();
verify(preparedStatement1).getConnection();
verify(preparedStatement2).getConnection();
verify(eventCaller, times(2)).verifyDataSource("ds_0");
verify(eventCaller, times(2)).verifyDataSource("ds_1");
verify(eventCaller, times(4)).verifySQL("DELETE FROM dual");
verify(eventCaller, times(4)).verifyParameters(Collections.emptyList());
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(eventCaller, times(0)).verifyException(null);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementExecutorTest method assertExecuteForSinglePreparedStatementWithDQL.
@Test
public void assertExecuteForSinglePreparedStatementWithDQL() throws SQLException {
PreparedStatement preparedStatement = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper = createPreparedStatementExecutorWrapperForDQL(preparedStatement, "ds_0");
when(preparedStatement.execute()).thenReturn(true);
PreparedStatementExecutor actual = new PreparedStatementExecutor(executorEngine, Collections.singleton(wrapper));
assertTrue(actual.execute());
verify(preparedStatement).execute();
verify(eventCaller, times(2)).verifyDataSource("ds_0");
verify(eventCaller, times(2)).verifySQL("SELECT * 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);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementExecutorTest method assertExecuteUpdateForMultiplePreparedStatementsFailure.
@Test
public void assertExecuteUpdateForMultiplePreparedStatementsFailure() throws SQLException {
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper1 = createPreparedStatementExecutorWrapperForDML(preparedStatement1, "ds_0");
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper2 = createPreparedStatementExecutorWrapperForDML(preparedStatement2, "ds_1");
SQLException exp = new SQLException();
when(preparedStatement1.executeUpdate()).thenThrow(exp);
when(preparedStatement2.executeUpdate()).thenThrow(exp);
when(preparedStatement1.getConnection()).thenReturn(mock(Connection.class));
when(preparedStatement2.getConnection()).thenReturn(mock(Connection.class));
PreparedStatementExecutor actual = new PreparedStatementExecutor(executorEngine, Arrays.asList(wrapper1, wrapper2));
assertThat(actual.executeUpdate(), is(0));
verify(preparedStatement1).executeUpdate();
verify(preparedStatement2).executeUpdate();
verify(preparedStatement1).getConnection();
verify(preparedStatement2).getConnection();
verify(eventCaller, times(2)).verifyDataSource("ds_0");
verify(eventCaller, times(2)).verifyDataSource("ds_1");
verify(eventCaller, times(4)).verifySQL("DELETE FROM dual");
verify(eventCaller, times(4)).verifyParameters(Collections.emptyList());
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(eventCaller, times(2)).verifyException(exp);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementExecutorTest method assertExecuteForSinglePreparedStatementFailureWithDML.
@Test
public void assertExecuteForSinglePreparedStatementFailureWithDML() throws SQLException {
PreparedStatement preparedStatement = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper = createPreparedStatementExecutorWrapperForDML(preparedStatement, "ds_0");
SQLException exp = new SQLException();
when(preparedStatement.execute()).thenThrow(exp);
PreparedStatementExecutor actual = new PreparedStatementExecutor(executorEngine, Collections.singleton(wrapper));
assertFalse(actual.execute());
verify(preparedStatement).execute();
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_FAILURE);
verify(eventCaller).verifyException(exp);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementExecutorTest method assertExecuteForMultiplePreparedStatementsFailureWithDML.
@Test
public void assertExecuteForMultiplePreparedStatementsFailureWithDML() throws SQLException {
PreparedStatement preparedStatement1 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper1 = createPreparedStatementExecutorWrapperForDML(preparedStatement1, "ds_0");
PreparedStatement preparedStatement2 = mock(PreparedStatement.class);
PreparedStatementExecutorWrapper wrapper2 = createPreparedStatementExecutorWrapperForDML(preparedStatement2, "ds_1");
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(executorEngine, Arrays.asList(wrapper1, wrapper2));
assertFalse(actual.execute());
verify(preparedStatement1).execute();
verify(preparedStatement2).execute();
verify(preparedStatement1).getConnection();
verify(preparedStatement2).getConnection();
verify(eventCaller, times(2)).verifyDataSource("ds_0");
verify(eventCaller, times(2)).verifyDataSource("ds_1");
verify(eventCaller, times(4)).verifySQL("DELETE FROM dual");
verify(eventCaller, times(4)).verifyParameters(Collections.emptyList());
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(eventCaller, times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(eventCaller, times(2)).verifyException(exp);
}
Aggregations