use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class OracleTableMetaCacheTest method getTableMetaTest.
@Test
public void getTableMetaTest() throws SQLException {
MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, pkMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy proxy = new DataSourceProxy(dataSource);
TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.ORACLE);
TableMeta tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.ot1", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.\"ot1\"", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class PostgresqlTableMetaCacheTest method getTableMetaTest.
@Test
public void getTableMetaTest() throws SQLException {
MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, pkMetas);
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
DataSourceProxy proxy = new DataSourceProxy(dataSource);
TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.POSTGRESQL);
TableMeta tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "pt1", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.pt1", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.\"pt1\"", proxy.getResourceId());
Assertions.assertNotNull(tableMeta);
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class MysqlTableMetaCacheTest method refreshTest_0.
@Test
public void refreshTest_0() throws SQLException {
MockDriver mockDriver = new MockDriver(columnMetas, indexMetas);
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl("jdbc:mock:xxx");
druidDataSource.setDriver(mockDriver);
DataSourceProxy dataSourceProxy = new DataSourceProxy(druidDataSource);
TableMeta tableMeta = getTableMetaCache().getTableMeta(dataSourceProxy.getPlainConnection(), "t1", dataSourceProxy.getResourceId());
// change the columns meta
columnMetas = new Object[][] { new Object[] { "", "", "mt1", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "mt1", "name1", Types.VARCHAR, "VARCHAR", 65, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" }, new Object[] { "", "", "mt1", "name2", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 3, "YES", "NO" }, new Object[] { "", "", "mt1", "name3", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 4, "YES", "NO" } };
mockDriver.setMockColumnsMetasReturnValue(columnMetas);
getTableMetaCache().refresh(dataSourceProxy.getPlainConnection(), dataSourceProxy.getResourceId());
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class PreparedStatementProxyTest method init.
@BeforeAll
public static void init() throws SQLException {
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());
String sql = "update prepared_statement_proxy set name = ?";
PreparedStatement preparedStatement = mockDriver.createSeataMockPreparedStatement((MockConnection) connectionProxy.getTargetConnection(), sql);
preparedStatementProxy = new PreparedStatementProxy(connectionProxy, preparedStatement, sql);
unusedConstructorPreparedStatementProxy = new TestUnusedConstructorPreparedStatementProxy(connectionProxy, preparedStatement);
EnhancedServiceLoader.load(SQLOperateRecognizerHolder.class, JdbcConstants.MYSQL, SQLOperateRecognizerHolderFactory.class.getClassLoader());
DruidDelegatingSQLRecognizerFactory recognizerFactory = (DruidDelegatingSQLRecognizerFactory) EnhancedServiceLoader.load(SQLRecognizerFactory.class, SqlParserType.SQL_PARSER_TYPE_DRUID);
}
use of io.seata.rm.datasource.mock.MockDriver in project seata by seata.
the class DataSourceProxyTest method getResourceIdTest.
@Test
public void getResourceIdTest() throws SQLException, NoSuchFieldException, IllegalAccessException {
MockDriver mockDriver = new MockDriver();
String username = "username";
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(mockDriver);
dataSource.setUsername(username);
dataSource.setPassword("password");
DataSourceProxy proxy = new DataSourceProxy(dataSource);
Field dbTypeField = proxy.getClass().getDeclaredField("dbType");
dbTypeField.setAccessible(true);
dbTypeField.set(proxy, io.seata.sqlparser.util.JdbcConstants.ORACLE);
String userName = dataSource.getConnection().getMetaData().getUserName();
Assertions.assertEquals(userName, username);
Field userNameField = proxy.getClass().getDeclaredField("userName");
userNameField.setAccessible(true);
userNameField.set(proxy, username);
Assertions.assertEquals(proxy.getResourceId(), "jdbc:mock:xxx/username");
dbTypeField.set(proxy, io.seata.sqlparser.util.JdbcConstants.MYSQL);
Assertions.assertEquals(proxy.getResourceId(), "jdbc:mock:xxx");
}
Aggregations