use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class MultiExecutorTest method init.
@BeforeAll
public static void init() throws Throwable {
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_update_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_update_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 = 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 = 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");
}
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class SelectForUpdateExecutorTest method init.
@BeforeAll
public static void init() {
RootContext.unbind();
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_select_for_update_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_select_for_update_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 = new MockConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
connectionProxy.bind("xid");
MockStatement mockStatement = new MockStatement(dataSource.getConnection().getConnection());
statementProxy = new StatementProxy(connectionProxy, mockStatement);
} catch (Exception e) {
throw new RuntimeException("init failed");
}
String sql = "select * from table_select_for_update_executor_test where id = 1";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLSelectForUpdateRecognizer recognizer = new MySQLSelectForUpdateRecognizer(sql, asts.get(0));
selectForUpdateExecutor = new SelectForUpdateExecutor(statementProxy, (statement, args) -> {
return null;
}, recognizer);
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class MySQLUndoLogManagerTest method init.
@BeforeEach
public void init() throws SQLException {
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
dataSourceProxy = new DataSourceProxy(dataSource);
connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
undoLogManager = new MySQLUndoLogManager();
tableMeta = new TableMeta();
tableMeta.setTableName("table_plain_executor_test");
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class MysqlTableMetaCacheTest method getTableMetaTest_0.
/**
* The table meta fetch test.
*/
@Test
public void getTableMetaTest_0() throws SQLException {
MockDriver mockDriver = new MockDriver(columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy proxy = new DataSourceProxy(dataSource);
TableMeta tableMeta = getTableMetaCache().getTableMeta(proxy.getPlainConnection(), "mt1", proxy.getResourceId());
Assertions.assertEquals("mt1", tableMeta.getTableName());
Assertions.assertEquals("id", tableMeta.getPrimaryKeyOnlyName().get(0));
Assertions.assertEquals("id", tableMeta.getColumnMeta("id").getColumnName());
Assertions.assertEquals("id", tableMeta.getAutoIncreaseColumn().getColumnName());
Assertions.assertEquals(1, tableMeta.getPrimaryKeyMap().size());
Assertions.assertEquals(Collections.singletonList("id"), tableMeta.getPrimaryKeyOnlyName());
Assertions.assertEquals(columnMetas.length, tableMeta.getAllColumns().size());
assertColumnMetaEquals(columnMetas[0], tableMeta.getAllColumns().get("id"));
assertColumnMetaEquals(columnMetas[1], tableMeta.getAllColumns().get("name1"));
assertColumnMetaEquals(columnMetas[2], tableMeta.getAllColumns().get("name2"));
assertColumnMetaEquals(columnMetas[3], tableMeta.getAllColumns().get("name3"));
Assertions.assertEquals(indexMetas.length, tableMeta.getAllIndexes().size());
assertIndexMetaEquals(indexMetas[0], tableMeta.getAllIndexes().get("PRIMARY"));
Assertions.assertEquals(IndexType.PRIMARY, tableMeta.getAllIndexes().get("PRIMARY").getIndextype());
assertIndexMetaEquals(indexMetas[1], tableMeta.getAllIndexes().get("name1"));
Assertions.assertEquals(IndexType.UNIQUE, tableMeta.getAllIndexes().get("name1").getIndextype());
indexMetas = new Object[][] {};
mockDriver.setMockIndexMetasReturnValue(indexMetas);
Assertions.assertThrows(ShouldNeverHappenException.class, () -> {
getTableMetaCache().getTableMeta(proxy.getPlainConnection(), "mt2", proxy.getResourceId());
});
mockDriver.setMockColumnsMetasReturnValue(null);
Assertions.assertThrows(ShouldNeverHappenException.class, () -> {
getTableMetaCache().getTableMeta(proxy.getPlainConnection(), "mt2", proxy.getResourceId());
});
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class TableRecordsTest method testBuildRecords.
@Test
public void testBuildRecords() throws SQLException {
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
DataSourceProxy proxy = new DataSourceProxy(dataSource);
TableMeta tableMeta = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.MYSQL).getTableMeta(proxy.getPlainConnection(), "table_records_test", proxy.getResourceId());
ResultSet resultSet = mockDriver.executeQuery(mockStatement, "select * from table_records_test");
TableRecords tableRecords = TableRecords.buildRecords(tableMeta, resultSet);
Assertions.assertNotNull(tableRecords);
}
Aggregations