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