Search in sources :

Example 1 with GlobalLockExecutor

use of io.seata.rm.GlobalLockExecutor in project seata by seata.

the class BaseTransactionalExecutorTest method testExecuteWithGlobalLockSet.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecuteWithGlobalLockSet() throws Throwable {
    // initial objects
    ConnectionProxy connectionProxy = new ConnectionProxy(null, null);
    StatementProxy statementProxy = new StatementProxy<>(connectionProxy, null);
    BaseTransactionalExecutor<Object, Statement> baseTransactionalExecutor = new BaseTransactionalExecutor<Object, Statement>(statementProxy, null, (SQLRecognizer) null) {

        @Override
        protected Object doExecute(Object... args) {
            return null;
        }
    };
    GlobalLockTemplate template = new GlobalLockTemplate();
    // not in global lock context
    try {
        baseTransactionalExecutor.execute(new Object());
        Assertions.assertFalse(connectionProxy.isGlobalLockRequire(), "connection context set!");
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    // in global lock context
    template.execute(new GlobalLockExecutor() {

        @Override
        public Object execute() throws Throwable {
            baseTransactionalExecutor.execute(new Object());
            Assertions.assertTrue(connectionProxy.isGlobalLockRequire(), "connection context not set!");
            return null;
        }

        @Override
        public GlobalLockConfig getGlobalLockConfig() {
            return null;
        }
    });
}
Also used : GlobalLockConfig(io.seata.core.model.GlobalLockConfig) GlobalLockTemplate(io.seata.rm.GlobalLockTemplate) GlobalLockExecutor(io.seata.rm.GlobalLockExecutor) Statement(java.sql.Statement) StatementProxy(io.seata.rm.datasource.StatementProxy) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalLockConfig (io.seata.core.model.GlobalLockConfig)1 GlobalLockExecutor (io.seata.rm.GlobalLockExecutor)1 GlobalLockTemplate (io.seata.rm.GlobalLockTemplate)1 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)1 StatementProxy (io.seata.rm.datasource.StatementProxy)1 Statement (java.sql.Statement)1 Test (org.junit.jupiter.api.Test)1