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;
}
});
}
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;
}
Aggregations