use of io.seata.server.lock.LockManager in project seata by seata.
the class SessionStoreTest method testRestoredFromFile.
/**
* Test restored from file.
*
* @throws Exception the exception
*/
@Test
public void testRestoredFromFile() throws Exception {
try {
SessionHolder.init("file");
GlobalSession globalSession = new GlobalSession("demo-app", "my_test_tx_group", "test", 6000);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
globalSession.begin();
BranchSession branchSession1 = SessionHelper.newBranchByGlobal(globalSession, BranchType.AT, RESOURCE_ID, "ta:1,2;tb:3", "xxx");
branchSession1.setXid(xid);
branchSession1.lock();
globalSession.addBranch(branchSession1);
LockManager lockManager = new FileLockManagerForTest();
String otherXID = XID.generateXID(0L);
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:2"));
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "tb:3"));
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:4"));
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "tb:5"));
lockManager.cleanAllLocks();
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:2"));
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "tb:3"));
// Re-init SessionHolder: restore sessions from file
SessionHolder.init("file");
long tid = globalSession.getTransactionId();
GlobalSession reloadSession = SessionHolder.findGlobalSession(globalSession.getXid());
Assertions.assertNotNull(reloadSession);
Assertions.assertFalse(globalSession == reloadSession);
Assertions.assertEquals(globalSession.getApplicationId(), reloadSession.getApplicationId());
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:2"));
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "tb:3"));
Assertions.assertTrue(lockManager.isLockable(xid, RESOURCE_ID, "tb:3"));
// clear
reloadSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
reloadSession.end();
} finally {
SessionHolder.destroy();
}
}
use of io.seata.server.lock.LockManager in project seata by seata.
the class SessionStoreTest method testRestoredFromFileAsyncCommitting.
/**
* Test restored from file async committing.
*
* @throws Exception the exception
*/
@Test
public void testRestoredFromFileAsyncCommitting() throws Exception {
try {
SessionHolder.init("file");
GlobalSession globalSession = new GlobalSession("demo-app", "my_test_tx_group", "test", 6000);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
globalSession.begin();
BranchSession branchSession1 = SessionHelper.newBranchByGlobal(globalSession, BranchType.AT, RESOURCE_ID, "ta:1", "xxx");
Assertions.assertTrue(branchSession1.lock());
globalSession.addBranch(branchSession1);
LockManager lockManager = new FileLockManagerForTest();
String otherXID = XID.generateXID(0L);
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
globalSession.changeStatus(GlobalStatus.AsyncCommitting);
lockManager.cleanAllLocks();
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// Re-init SessionHolder: restore sessions from file
SessionHolder.init("file");
long tid = globalSession.getTransactionId();
GlobalSession reloadSession = SessionHolder.findGlobalSession(globalSession.getXid());
Assertions.assertEquals(reloadSession.getStatus(), GlobalStatus.AsyncCommitting);
GlobalSession sessionInAsyncCommittingQueue = SessionHolder.getAsyncCommittingSessionManager().findGlobalSession(globalSession.getXid());
Assertions.assertTrue(reloadSession == sessionInAsyncCommittingQueue);
// No locking for session in AsyncCommitting status
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// clear
reloadSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
reloadSession.end();
} finally {
SessionHolder.destroy();
}
}
use of io.seata.server.lock.LockManager in project seata by seata.
the class SessionStoreTest method testRestoredFromFileCommitRetry.
/**
* Test restored from file commit retry.
*
* @throws Exception the exception
*/
@Test
public void testRestoredFromFileCommitRetry() throws Exception {
try {
SessionHolder.init("file");
GlobalSession globalSession = new GlobalSession("demo-app", "my_test_tx_group", "test", 6000);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
globalSession.begin();
BranchSession branchSession1 = SessionHelper.newBranchByGlobal(globalSession, BranchType.AT, RESOURCE_ID, "ta:1", "xxx");
branchSession1.lock();
globalSession.addBranch(branchSession1);
LockManager lockManager = new FileLockManagerForTest();
String otherXID = XID.generateXID(0L);
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
globalSession.changeStatus(GlobalStatus.Committing);
globalSession.changeBranchStatus(branchSession1, BranchStatus.PhaseTwo_CommitFailed_Retryable);
globalSession.changeStatus(GlobalStatus.CommitRetrying);
lockManager.cleanAllLocks();
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// Re-init SessionHolder: restore sessions from file
SessionHolder.init("file");
long tid = globalSession.getTransactionId();
GlobalSession reloadSession = SessionHolder.findGlobalSession(globalSession.getXid());
Assertions.assertEquals(reloadSession.getStatus(), GlobalStatus.CommitRetrying);
GlobalSession sessionInRetryCommittingQueue = SessionHolder.getRetryCommittingSessionManager().findGlobalSession(globalSession.getXid());
Assertions.assertTrue(reloadSession == sessionInRetryCommittingQueue);
BranchSession reloadBranchSession = reloadSession.getBranch(branchSession1.getBranchId());
Assertions.assertEquals(reloadBranchSession.getStatus(), BranchStatus.PhaseTwo_CommitFailed_Retryable);
// Lock is held by session in CommitRetrying status
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// clear
reloadSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
reloadSession.end();
} finally {
SessionHolder.destroy();
}
}
use of io.seata.server.lock.LockManager in project seata by seata.
the class SessionStoreTest method clean.
/**
* Clean.
*
* @throws Exception the exception
*/
@BeforeEach
public void clean() throws Exception {
String sessionStorePath = CONFIG.getConfig(ConfigurationKeys.STORE_FILE_DIR);
File rootDataFile = new File(sessionStorePath + File.separator + SessionHolder.ROOT_SESSION_MANAGER_NAME);
File rootDataFileHis = new File(sessionStorePath + File.separator + SessionHolder.ROOT_SESSION_MANAGER_NAME + ".1");
if (rootDataFile.exists()) {
rootDataFile.delete();
}
if (rootDataFileHis.exists()) {
rootDataFileHis.delete();
}
LockManager lockManager = new FileLockManagerForTest();
lockManager.cleanAllLocks();
}
use of io.seata.server.lock.LockManager in project seata by seata.
the class SessionStoreTest method testRestoredFromFileRollbackRetry.
/**
* Test restored from file rollback retry.
*
* @throws Exception the exception
*/
@Test
public void testRestoredFromFileRollbackRetry() throws Exception {
try {
SessionHolder.init("file");
GlobalSession globalSession = new GlobalSession("demo-app", "my_test_tx_group", "test", 6000);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
globalSession.begin();
BranchSession branchSession1 = SessionHelper.newBranchByGlobal(globalSession, BranchType.AT, RESOURCE_ID, "ta:1", "xxx");
branchSession1.lock();
globalSession.addBranch(branchSession1);
LockManager lockManager = new FileLockManagerForTest();
String otherXID = XID.generateXID(0L);
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
globalSession.changeStatus(GlobalStatus.Rollbacking);
globalSession.changeBranchStatus(branchSession1, BranchStatus.PhaseTwo_RollbackFailed_Retryable);
globalSession.changeStatus(GlobalStatus.RollbackRetrying);
lockManager.cleanAllLocks();
Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// Re-init SessionHolder: restore sessions from file
SessionHolder.init("file");
long tid = globalSession.getTransactionId();
GlobalSession reloadSession = SessionHolder.findGlobalSession(globalSession.getXid());
Assertions.assertEquals(reloadSession.getStatus(), GlobalStatus.RollbackRetrying);
GlobalSession sessionInRetryRollbackingQueue = SessionHolder.getRetryRollbackingSessionManager().findGlobalSession(globalSession.getXid());
Assertions.assertTrue(reloadSession == sessionInRetryRollbackingQueue);
BranchSession reloadBranchSession = reloadSession.getBranch(branchSession1.getBranchId());
Assertions.assertEquals(reloadBranchSession.getStatus(), BranchStatus.PhaseTwo_RollbackFailed_Retryable);
// Lock is held by session in RollbackRetrying status
Assertions.assertFalse(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
// clear
reloadSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
reloadSession.end();
} finally {
SessionHolder.destroy();
}
}
Aggregations