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