use of io.seata.server.session.BranchSession in project seata by seata.
the class RedisLockManagerTest method acquireLock.
@Test
public void acquireLock() throws TransactionException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:786756");
branchSession.setTransactionId(123543465);
branchSession.setBranchId(5756678);
branchSession.setResourceId("abcss");
branchSession.setLockKey("t1:13,14;t2:11,12");
Assertions.assertTrue(lockManager.acquireLock(branchSession));
}
use of io.seata.server.session.BranchSession in project seata by seata.
the class RedisLockManagerTest method isLockable.
@Test
public void isLockable() throws TransactionException {
BranchSession branchSession = new BranchSession();
branchSession.setXid("abc-123:56877898");
branchSession.setTransactionId(245686786);
branchSession.setBranchId(467568);
branchSession.setResourceId("abcss");
branchSession.setLockKey("t1:8,7;t2:1,2");
Assertions.assertTrue(lockManager.acquireLock(branchSession));
BranchSession branchSession2 = new BranchSession();
branchSession2.setXid("abc-123:56877898");
branchSession2.setTransactionId(245686786);
branchSession2.setBranchId(1242354576);
branchSession2.setResourceId("abcss");
branchSession2.setLockKey("t1:8");
Assertions.assertTrue(lockManager.isLockable(branchSession2.getXid(), branchSession2.getResourceId(), branchSession2.getLockKey()));
}
use of io.seata.server.session.BranchSession in project seata by seata.
the class SessionConverter method convertBranchSession.
public static BranchSession convertBranchSession(BranchTransactionDO branchTransactionDO) {
if (branchTransactionDO == null) {
return null;
}
BranchSession branchSession = new BranchSession();
branchSession.setXid(branchTransactionDO.getXid());
branchSession.setTransactionId(branchTransactionDO.getTransactionId());
branchSession.setApplicationData(branchTransactionDO.getApplicationData());
branchSession.setBranchId(branchTransactionDO.getBranchId());
branchSession.setBranchType(BranchType.valueOf(branchTransactionDO.getBranchType()));
branchSession.setResourceId(branchTransactionDO.getResourceId());
branchSession.setClientId(branchTransactionDO.getClientId());
branchSession.setResourceGroupId(branchTransactionDO.getResourceGroupId());
branchSession.setStatus(BranchStatus.get(branchTransactionDO.getStatus()));
return branchSession;
}
use of io.seata.server.session.BranchSession in project XHuiCloud by sindaZeng.
the class AbstractCore method branchRegister.
@Override
public Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData, String lockKeys) throws TransactionException {
GlobalSession globalSession = assertGlobalSessionNotNull(xid, false);
return SessionHolder.lockAndExecute(globalSession, () -> {
globalSessionStatusCheck(globalSession);
globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
BranchSession branchSession = SessionHelper.newBranchByGlobal(globalSession, branchType, resourceId, applicationData, lockKeys, clientId);
branchSessionLock(globalSession, branchSession);
try {
globalSession.addBranch(branchSession);
} catch (RuntimeException ex) {
branchSessionUnlock(branchSession);
throw new BranchTransactionException(FailedToAddBranch, String.format("Failed to store branch xid = %s branchId = %s", globalSession.getXid(), branchSession.getBranchId()), ex);
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Register branch successfully, xid = {}, branchId = {}, resourceId = {} ,lockKeys = {}", globalSession.getXid(), branchSession.getBranchId(), resourceId, lockKeys);
}
return branchSession.getBranchId();
});
}
use of io.seata.server.session.BranchSession in project XHuiCloud by sindaZeng.
the class SessionConverter method convertBranchTransactionDO.
public static BranchTransactionDO convertBranchTransactionDO(SessionStorable session) {
if (session == null || !(session instanceof BranchSession)) {
throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
}
BranchSession branchSession = (BranchSession) session;
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setXid(branchSession.getXid());
branchTransactionDO.setBranchId(branchSession.getBranchId());
branchTransactionDO.setBranchType(branchSession.getBranchType().name());
branchTransactionDO.setClientId(branchSession.getClientId());
branchTransactionDO.setResourceGroupId(branchSession.getResourceGroupId());
branchTransactionDO.setTransactionId(branchSession.getTransactionId());
branchTransactionDO.setApplicationData(branchSession.getApplicationData());
branchTransactionDO.setResourceId(branchSession.getResourceId());
branchTransactionDO.setStatus(branchSession.getStatus().getCode());
return branchTransactionDO;
}
Aggregations