Search in sources :

Example 6 with LockManager

use of io.seata.server.lock.LockManager in project seata by seata.

the class SessionStoreTest method testRestoredFromFileRollbackFailed.

/**
 * Test restored from file rollback failed.
 *
 * @throws Exception the exception
 */
@Test
public void testRestoredFromFileRollbackFailed() 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_CommitFailed_Unretryable);
        SessionHelper.endRollbackFailed(globalSession);
        // Lock is released.
        Assertions.assertTrue(lockManager.isLockable(otherXID, RESOURCE_ID, "ta:1"));
        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.assertNull(reloadSession);
    } finally {
        SessionHolder.destroy();
    }
}
Also used : LockManager(io.seata.server.lock.LockManager) FileLockManagerForTest(io.seata.server.lock.file.FileLockManagerForTest) GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) Test(org.junit.jupiter.api.Test) FileLockManagerForTest(io.seata.server.lock.file.FileLockManagerForTest)

Aggregations

LockManager (io.seata.server.lock.LockManager)6 FileLockManagerForTest (io.seata.server.lock.file.FileLockManagerForTest)6 BranchSession (io.seata.server.session.BranchSession)5 GlobalSession (io.seata.server.session.GlobalSession)5 Test (org.junit.jupiter.api.Test)5 File (java.io.File)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1