use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class StatementExecutorTest method assertExecuteUpdateWithColumnNames.
@Test
public void assertExecuteUpdateWithColumnNames() throws SQLException {
Statement statement = mock(Statement.class);
StatementExecutorWrapper wrapper = createStatementExecutorWrapperForDML(statement, "ds_0");
when(statement.executeUpdate(DELETE_FROM_DUAL, new String[] { "col" })).thenReturn(10);
StatementExecutor actual = new StatementExecutor(executorEngine);
actual.addStatement(wrapper);
assertThat(actual.executeUpdate(new String[] { "col" }), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL, new String[] { "col" });
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);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class StatementExecutorTest method assertExecuteUpdateForMultipleStatementsFailure.
@Test
public void assertExecuteUpdateForMultipleStatementsFailure() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
SQLException exp = new SQLException();
when(statement1.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp);
when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(executorEngine);
StatementExecutorWrapper wrapper1 = createStatementExecutorWrapperForDML(statement1, "ds_0");
actual.addStatement(wrapper1);
StatementExecutorWrapper wrapper2 = createStatementExecutorWrapperForDML(statement2, "ds_1");
actual.addStatement(wrapper2);
assertThat(actual.executeUpdate(), is(0));
verify(statement1).executeUpdate(DELETE_FROM_DUAL);
verify(statement2).executeUpdate(DELETE_FROM_DUAL);
verify(statement1).getConnection();
verify(statement2).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.StatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class StatementExecutorTest method assertExecuteUpdateForMultipleStatementsSuccess.
@Test
public void assertExecuteUpdateForMultipleStatementsSuccess() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
when(statement1.executeUpdate(DELETE_FROM_DUAL)).thenReturn(10);
when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenReturn(20);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(executorEngine);
StatementExecutorWrapper wrapper1 = createStatementExecutorWrapperForDML(statement1, "ds_0");
actual.addStatement(wrapper1);
StatementExecutorWrapper wrapper2 = createStatementExecutorWrapperForDML(statement2, "ds_1");
actual.addStatement(wrapper2);
assertThat(actual.executeUpdate(), is(30));
verify(statement1).executeUpdate(DELETE_FROM_DUAL);
verify(statement2).executeUpdate(DELETE_FROM_DUAL);
verify(statement1).getConnection();
verify(statement2).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.StatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class StatementExecutorTest method assertExecuteUpdateWithAutoGeneratedKeys.
@Test
public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException {
Statement statement = mock(Statement.class);
StatementExecutorWrapper wrapper = createStatementExecutorWrapperForDML(statement, "ds_0");
when(statement.executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS)).thenReturn(10);
StatementExecutor actual = new StatementExecutor(executorEngine);
actual.addStatement(wrapper);
assertThat(actual.executeUpdate(Statement.NO_GENERATED_KEYS), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS);
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);
}
use of com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper in project sharding-jdbc by dangdangdotcom.
the class StatementExecutorTest method assertExecuteWithColumnIndexes.
@Test
public void assertExecuteWithColumnIndexes() throws SQLException {
Statement statement = mock(Statement.class);
StatementExecutorWrapper wrapper = createStatementExecutorWrapperForDML(statement, "ds_0");
when(statement.execute(DELETE_FROM_DUAL, new int[] { 1 })).thenReturn(false);
StatementExecutor actual = new StatementExecutor(executorEngine);
actual.addStatement(wrapper);
assertFalse(actual.execute(new int[] { 1 }));
verify(statement).execute(DELETE_FROM_DUAL, new int[] { 1 });
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);
}
Aggregations