Search in sources :

Example 1 with GlobalLockTemplate

use of io.seata.rm.GlobalLockTemplate 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)

Example 2 with GlobalLockTemplate

use of io.seata.rm.GlobalLockTemplate in project jboot by yangfuhai.

the class JbootSeataManager method init.

public void init() {
    if (!config.isEnable()) {
        return;
    }
    if (!config.isConfigOk()) {
        throw new JbootIllegalConfigException("please config applicationId and txServiceGroup for seata");
    }
    transactionManager = new SeataGlobalTransactionManager(config.getApplicationId(), config.getTxServiceGroup(), config.getMode());
    transactionManager.init();
    this.transactionalTemplate = new TransactionalTemplate();
    this.globalLockTemplate = new GlobalLockTemplate();
    this.enable = true;
}
Also used : JbootIllegalConfigException(io.jboot.exception.JbootIllegalConfigException) GlobalLockTemplate(io.seata.rm.GlobalLockTemplate) TransactionalTemplate(io.seata.tm.api.TransactionalTemplate)

Aggregations

GlobalLockTemplate (io.seata.rm.GlobalLockTemplate)2 JbootIllegalConfigException (io.jboot.exception.JbootIllegalConfigException)1 GlobalLockConfig (io.seata.core.model.GlobalLockConfig)1 GlobalLockExecutor (io.seata.rm.GlobalLockExecutor)1 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)1 StatementProxy (io.seata.rm.datasource.StatementProxy)1 TransactionalTemplate (io.seata.tm.api.TransactionalTemplate)1 Statement (java.sql.Statement)1 Test (org.junit.jupiter.api.Test)1