Search in sources :

Example 21 with BranchSession

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));
}
Also used : BranchSession(io.seata.server.session.BranchSession) Test(org.junit.jupiter.api.Test)

Example 22 with 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()));
}
Also used : BranchSession(io.seata.server.session.BranchSession) Test(org.junit.jupiter.api.Test)

Example 23 with BranchSession

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;
}
Also used : BranchSession(io.seata.server.session.BranchSession)

Example 24 with 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();
    });
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) BranchTransactionException(io.seata.core.exception.BranchTransactionException)

Example 25 with BranchSession

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;
}
Also used : BranchSession(io.seata.server.session.BranchSession) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Aggregations

BranchSession (io.seata.server.session.BranchSession)60 GlobalSession (io.seata.server.session.GlobalSession)33 Test (org.junit.jupiter.api.Test)29 Connection (java.sql.Connection)9 SessionCondition (io.seata.server.session.SessionCondition)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 BranchTransactionDO (io.seata.core.store.BranchTransactionDO)5 LockManager (io.seata.server.lock.LockManager)5 FileLockManagerForTest (io.seata.server.lock.file.FileLockManagerForTest)5 FileTransactionStoreManager (io.seata.server.storage.file.store.FileTransactionStoreManager)5 ResultSet (java.sql.ResultSet)5 ArrayList (java.util.ArrayList)5 BranchTransactionException (io.seata.core.exception.BranchTransactionException)4 TransactionException (io.seata.core.exception.TransactionException)4 BranchStatus (io.seata.core.model.BranchStatus)4 TransactionWriteStore (io.seata.server.storage.file.TransactionWriteStore)4 GlobalStatus (io.seata.core.model.GlobalStatus)3 SessionManager (io.seata.server.session.SessionManager)3 TransactionStoreManager (io.seata.server.store.TransactionStoreManager)3