use of io.seata.rm.datasource.ConnectionProxy in project seata by seata.
the class DeleteExecutorTest method init.
@BeforeAll
public static void init() {
List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
Object[][] returnValue = new Object[][] { new Object[] { 1, "Tom" }, new Object[] { 2, "Jack" } };
Object[][] columnMetas = new Object[][] { new Object[] { "", "", "table_delete_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_delete_executor_test", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" } };
Object[][] indexMetas = new Object[][] { new Object[] { "PRIMARY", "id", false, "", 3, 1, "A", 34 } };
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
try {
Field field = dataSourceProxy.getClass().getDeclaredField("dbType");
field.setAccessible(true);
field.set(dataSourceProxy, "mysql");
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
statementProxy = new StatementProxy(connectionProxy, mockStatement);
} catch (Exception e) {
throw new RuntimeException("init failed");
}
String sql = "delete from t where id = 1";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLDeleteRecognizer recognizer = new MySQLDeleteRecognizer(sql, asts.get(0));
deleteExecutor = new DeleteExecutor(statementProxy, (statement, args) -> {
return null;
}, recognizer);
}
use of io.seata.rm.datasource.ConnectionProxy in project seata by seata.
the class PostgresqlInsertExecutorTest method init.
@BeforeEach
public void init() {
ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.POSTGRESQL);
statementProxy = mock(PreparedStatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = mock(StatementCallback.class);
sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
tableMeta = mock(TableMeta.class);
insertExecutor = Mockito.spy(new PostgresqlInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
pkIndexMap = new HashMap<String, Integer>() {
{
put(ID_COLUMN, pkIndex);
}
};
}
use of io.seata.rm.datasource.ConnectionProxy in project seata by seata.
the class MySQLInsertExecutorTest method init.
@BeforeEach
public void init() throws SQLException {
ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.MYSQL);
DataSourceProxy dataSourceProxy = new DataSourceProxy(new MockDataSource());
when(connectionProxy.getDataSourceProxy()).thenReturn(dataSourceProxy);
statementProxy = mock(PreparedStatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
when(statementProxy.getTargetStatement()).thenReturn(statementProxy);
MockResultSet resultSet = new MockResultSet(statementProxy);
resultSet.mockResultSet(Arrays.asList("Variable_name", "Value"), new Object[][] { { "auto_increment_increment", "1" } });
when(statementProxy.getTargetStatement().executeQuery("SHOW VARIABLES LIKE 'auto_increment_increment'")).thenReturn(resultSet);
StatementCallback statementCallback = mock(StatementCallback.class);
sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
tableMeta = mock(TableMeta.class);
insertExecutor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
pkIndexMap = new HashMap<String, Integer>() {
{
put(ID_COLUMN, pkIndex);
}
};
}
use of io.seata.rm.datasource.ConnectionProxy in project seata by seata.
the class PlainExecutorTest method init.
@BeforeEach
public void init() throws SQLException {
List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
Object[][] returnValue = new Object[][] { new Object[] { 1, "Tom" }, new Object[] { 2, "Jack" } };
Object[][] columnMetas = new Object[][] { new Object[] { "", "", "table_plain_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_plain_executor_test", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" } };
Object[][] indexMetas = new Object[][] { new Object[] { "PRIMARY", "id", false, "", 3, 1, "A", 34 } };
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
StatementProxy statementProxy = new StatementProxy(connectionProxy, mockStatement);
plainExecutor = new PlainExecutor(statementProxy, (statement, args) -> null);
}
use of io.seata.rm.datasource.ConnectionProxy in project seata by seata.
the class SelectForUpdateExecutorTest method testDoExecute.
@Test
public void testDoExecute() throws Throwable {
Assertions.assertThrows(RuntimeException.class, () -> selectForUpdateExecutor.doExecute((Object) null));
RootContext.bind("xid");
Assertions.assertDoesNotThrow(() -> {
selectForUpdateExecutor.doExecute((Object) null);
});
RootContext.unbind();
RootContext.bindGlobalLockFlag();
Assertions.assertDoesNotThrow(() -> {
selectForUpdateExecutor.doExecute((Object) null);
});
RootContext.unbindGlobalLockFlag();
connectionProxy = new MockLockConflictConnectionProxy(connectionProxy.getDataSourceProxy(), connectionProxy.getTargetConnection());
statementProxy = new StatementProxy(connectionProxy, statementProxy.getTargetStatement());
statementProxy.getTargetStatement().getConnection().setAutoCommit(false);
String sql = "select * from dual";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLSelectForUpdateRecognizer recognizer = new MySQLSelectForUpdateRecognizer(sql, asts.get(0));
selectForUpdateExecutor = new SelectForUpdateExecutor(statementProxy, (statement, args) -> null, recognizer);
RootContext.bind("xid");
Assertions.assertThrows(LockWaitTimeoutException.class, () -> selectForUpdateExecutor.doExecute((Object) null));
RootContext.unbind();
}
Aggregations