Search in sources :

Example 1 with MockLockConflictConnectionProxy

use of io.seata.rm.datasource.mock.MockLockConflictConnectionProxy 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();
}
Also used : MockDriver(io.seata.rm.datasource.mock.MockDriver) SQLUtils(com.alibaba.druid.sql.SQLUtils) StatementProxy(io.seata.rm.datasource.StatementProxy) MockConnectionProxy(io.seata.rm.datasource.mock.MockConnectionProxy) Field(java.lang.reflect.Field) MySQLSelectForUpdateRecognizer(io.seata.sqlparser.druid.mysql.MySQLSelectForUpdateRecognizer) MockLockConflictConnectionProxy(io.seata.rm.datasource.mock.MockLockConflictConnectionProxy) Test(org.junit.jupiter.api.Test) RootContext(io.seata.core.context.RootContext) List(java.util.List) Lists(com.google.common.collect.Lists) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) BeforeAll(org.junit.jupiter.api.BeforeAll) MockStatement(com.alibaba.druid.mock.MockStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) JdbcConstants(com.alibaba.druid.util.JdbcConstants) Assertions(org.junit.jupiter.api.Assertions) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) Types(java.sql.Types) StatementProxy(io.seata.rm.datasource.StatementProxy) MockLockConflictConnectionProxy(io.seata.rm.datasource.mock.MockLockConflictConnectionProxy) MySQLSelectForUpdateRecognizer(io.seata.sqlparser.druid.mysql.MySQLSelectForUpdateRecognizer) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) Test(org.junit.jupiter.api.Test)

Aggregations

MockStatement (com.alibaba.druid.mock.MockStatement)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 JdbcConstants (com.alibaba.druid.util.JdbcConstants)1 Lists (com.google.common.collect.Lists)1 RootContext (io.seata.core.context.RootContext)1 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)1 DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)1 StatementProxy (io.seata.rm.datasource.StatementProxy)1 MockConnectionProxy (io.seata.rm.datasource.mock.MockConnectionProxy)1 MockDriver (io.seata.rm.datasource.mock.MockDriver)1 MockLockConflictConnectionProxy (io.seata.rm.datasource.mock.MockLockConflictConnectionProxy)1 MySQLSelectForUpdateRecognizer (io.seata.sqlparser.druid.mysql.MySQLSelectForUpdateRecognizer)1 Field (java.lang.reflect.Field)1 Types (java.sql.Types)1 List (java.util.List)1 Assertions (org.junit.jupiter.api.Assertions)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1