Search in sources :

Example 16 with BranchSession

use of io.seata.server.session.BranchSession in project seata by seata.

the class DefaultCoreTest method doGlobalRollBackUnretryableTest.

/**
 * Do global roll back test.
 *
 * @param xid the xid
 * @throws Exception the exception
 */
@ParameterizedTest
@MethodSource("xidProvider")
public void doGlobalRollBackUnretryableTest(String xid) throws Exception {
    globalSession = SessionHolder.findGlobalSession(xid);
    BranchSession branchSession = SessionHelper.newBranchByGlobal(globalSession, BranchType.AT, resourceId, applicationData, "t1:1", clientId);
    globalSession.addBranch(branchSession);
    globalSession.changeBranchStatus(branchSession, BranchStatus.PhaseOne_Done);
    core.mockCore(BranchType.AT, new MockCore(BranchStatus.PhaseTwo_Committed, BranchStatus.PhaseTwo_RollbackFailed_Unretryable));
    core.doGlobalRollback(globalSession, false);
    Assertions.assertEquals(globalSession.getStatus(), GlobalStatus.RollbackFailed);
}
Also used : BranchSession(io.seata.server.session.BranchSession) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with BranchSession

use of io.seata.server.session.BranchSession in project seata by seata.

the class DefaultCoreTest method branchReportTest.

/**
 * Branch report test.
 *
 * @param xid      the xid
 * @param branchId the branch id
 * @throws Exception the exception
 */
@ParameterizedTest
@MethodSource("xidAndBranchIdProvider")
public void branchReportTest(String xid, Long branchId) throws Exception {
    core.branchReport(BranchType.AT, xid, branchId, BranchStatus.PhaseOne_Done, applicationData);
    globalSession = SessionHolder.findGlobalSession(xid);
    BranchSession branchSession = globalSession.getBranch(branchId);
    Assertions.assertEquals(branchSession.getStatus(), BranchStatus.PhaseOne_Done);
}
Also used : BranchSession(io.seata.server.session.BranchSession) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with BranchSession

use of io.seata.server.session.BranchSession in project seata by seata.

the class LockManagerTest method baseBranchSessionsProvider.

/**
 * Base branch sessions provider object [ ] [ ]. Could assign resource and lock keys.
 *
 * @return the object [ ] [ ]
 */
static Stream<Arguments> baseBranchSessionsProvider(String resource, String lockKey1, String lockKey2) {
    BranchSession branchSession1 = new BranchSession();
    branchSession1.setTransactionId(UUIDGenerator.generateUUID());
    branchSession1.setBranchId(1L);
    branchSession1.setClientId("c1");
    branchSession1.setResourceGroupId("my_test_tx_group");
    branchSession1.setResourceId(resource);
    branchSession1.setLockKey(lockKey1);
    branchSession1.setBranchType(BranchType.AT);
    branchSession1.setApplicationData("{\"data\":\"test\"}");
    branchSession1.setBranchType(BranchType.AT);
    BranchSession branchSession2 = new BranchSession();
    branchSession2.setTransactionId(UUIDGenerator.generateUUID());
    branchSession2.setBranchId(2L);
    branchSession2.setClientId("c1");
    branchSession2.setResourceGroupId("my_test_tx_group");
    branchSession2.setResourceId(resource);
    branchSession2.setLockKey(lockKey2);
    branchSession2.setBranchType(BranchType.AT);
    branchSession2.setApplicationData("{\"data\":\"test\"}");
    branchSession2.setBranchType(BranchType.AT);
    return Stream.of(Arguments.of(branchSession1, branchSession2));
}
Also used : BranchSession(io.seata.server.session.BranchSession)

Example 19 with BranchSession

use of io.seata.server.session.BranchSession in project seata by seata.

the class FileLockManagerImplTest method branchSessionProvider.

/**
 * Branch session provider object [ ] [ ].
 *
 * @return Stream<BranchSession>
 */
static Stream<BranchSession> branchSessionProvider() {
    BranchSession branchSession = new BranchSession();
    branchSession.setXid(XID.generateXID(transactionId));
    branchSession.setBranchId(1L);
    branchSession.setTransactionId(transactionId);
    branchSession.setClientId("c1");
    branchSession.setResourceGroupId("my_test_tx_group");
    branchSession.setResourceId(resourceId);
    branchSession.setLockKey(lockKey);
    branchSession.setBranchType(BranchType.AT);
    branchSession.setApplicationData("{\"data\":\"test\"}");
    return Stream.of(branchSession);
}
Also used : BranchSession(io.seata.server.session.BranchSession)

Example 20 with BranchSession

use of io.seata.server.session.BranchSession in project seata by seata.

the class DataBaseLockManagerImplTest method re_acquireLock.

@Test
public void re_acquireLock() throws TransactionException, SQLException {
    BranchSession branchSession = new BranchSession();
    branchSession.setXid("abc-123:65867978");
    branchSession.setTransactionId(123543465);
    branchSession.setBranchId(5756678);
    branchSession.setResourceId("abcss");
    branchSession.setLockKey("t1:53,54;t2:21,32");
    Assertions.assertTrue(lockManager.acquireLock(branchSession));
    BranchSession branchSession2 = new BranchSession();
    branchSession2.setXid("abc-123:65867978");
    branchSession2.setTransactionId(123543465);
    branchSession2.setBranchId(575667854);
    branchSession2.setResourceId("abcss");
    branchSession2.setLockKey("t1:13,14;t2:21,45");
    Assertions.assertTrue(lockManager.acquireLock(branchSession2));
    BranchSession branchSession3 = new BranchSession();
    branchSession3.setXid("abc-123:5678789");
    branchSession3.setTransactionId(334123);
    branchSession3.setBranchId(5657);
    branchSession3.setResourceId("abcss");
    branchSession3.setLockKey("t1:53,14;t2:21,45");
    Assertions.assertTrue(!lockManager.acquireLock(branchSession3));
    String delSql = "delete from lock_table where xid in( 'abc-123:65867978' , 'abc-123:65867978' , 'abc-123:5678789'  )";
    Connection conn = null;
    try {
        conn = dataSource.getConnection();
        conn.createStatement().execute(delSql);
    } finally {
        IOUtil.close(conn);
    }
}
Also used : BranchSession(io.seata.server.session.BranchSession) Connection(java.sql.Connection) Test(org.junit.jupiter.api.Test)

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