Search in sources :

Example 16 with GlobalSession

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

the class DefaultCoordinatorTest method test_handleRetryRollbacking.

@Test
public void test_handleRetryRollbacking() throws TransactionException, InterruptedException {
    String xid = core.begin(applicationId, txServiceGroup, txName, 10);
    Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);
    Assertions.assertNotNull(branchId);
    Thread.sleep(100);
    defaultCoordinator.timeoutCheck();
    defaultCoordinator.handleRetryRollbacking();
    GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
    Assertions.assertNull(globalSession);
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with GlobalSession

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

the class DefaultCoordinatorTest method test_handleRetryRollbackingTimeOut_unlock.

@Test
public void test_handleRetryRollbackingTimeOut_unlock() throws TransactionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    String xid = core.begin(applicationId, txServiceGroup, txName, 10);
    Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);
    GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
    Assertions.assertNotNull(globalSession);
    Assertions.assertNotNull(globalSession.getBranchSessions());
    Assertions.assertNotNull(branchId);
    ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT", Duration.ofMillis(10));
    ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE", true);
    TimeUnit.MILLISECONDS.sleep(100);
    defaultCoordinator.timeoutCheck();
    defaultCoordinator.handleRetryRollbacking();
    int lockSize = globalSession.getBranchSessions().get(0).getLockHolder().size();
    try {
        Assertions.assertTrue(lockSize == 0);
    } finally {
        globalSession.closeAndClean();
        ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT", ConfigurationFactory.getInstance().getDuration(ConfigurationKeys.MAX_ROLLBACK_RETRY_TIMEOUT, DurationUtil.DEFAULT_DURATION, 100));
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with GlobalSession

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

the class DefaultCoordinatorTest method test_handleRetryRollbackingTimeOut.

@Test
public void test_handleRetryRollbackingTimeOut() throws TransactionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    String xid = core.begin(applicationId, txServiceGroup, txName, 10);
    Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);
    GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
    Assertions.assertNotNull(globalSession);
    Assertions.assertNotNull(globalSession.getBranchSessions());
    Assertions.assertNotNull(branchId);
    ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT", Duration.ofMillis(10));
    ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE", false);
    TimeUnit.MILLISECONDS.sleep(100);
    defaultCoordinator.timeoutCheck();
    defaultCoordinator.handleRetryRollbacking();
    int lockSize = globalSession.getBranchSessions().get(0).getLockHolder().size();
    try {
        Assertions.assertTrue(lockSize > 0);
    } finally {
        globalSession.closeAndClean();
        ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT", ConfigurationFactory.getInstance().getDuration(ConfigurationKeys.MAX_ROLLBACK_RETRY_TIMEOUT, DurationUtil.DEFAULT_DURATION, 100));
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with GlobalSession

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

the class DataBaseSessionManagerTest method test_removeGlobalSession.

@Test
public void test_removeGlobalSession() throws Exception {
    GlobalSession session = GlobalSession.createGlobalSession("test", "test", "test123", 100);
    String xid = XID.generateXID(session.getTransactionId());
    session.setXid(xid);
    session.setTransactionId(146757978);
    session.setBeginTime(System.currentTimeMillis());
    session.setApplicationData("abc=878s");
    session.setStatus(GlobalStatus.Begin);
    sessionManager.addGlobalSession(session);
    String sql = "select * from global_table where xid= '" + xid + "'";
    String delSql = "delete from global_table where xid= '" + xid + "'";
    Connection conn = null;
    try {
        conn = dataSource.getConnection();
        ResultSet rs = conn.createStatement().executeQuery(sql);
        if (rs.next()) {
            Assertions.assertTrue(true);
        } else {
            Assertions.assertTrue(false);
        }
        rs.close();
        // delete
        sessionManager.removeGlobalSession(session);
        rs = conn.createStatement().executeQuery(sql);
        if (rs.next()) {
            Assertions.assertTrue(false);
        } else {
            Assertions.assertTrue(true);
        }
        rs.close();
        conn.createStatement().execute(delSql);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.jupiter.api.Test)

Example 20 with GlobalSession

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

the class DataBaseSessionManagerTest method test_findGlobalSession.

@Test
public void test_findGlobalSession() throws Exception {
    GlobalSession session = GlobalSession.createGlobalSession("test", "test", "test123", 100);
    String xid = XID.generateXID(session.getTransactionId());
    session.setXid(xid);
    session.setTransactionId(146757978);
    session.setBeginTime(System.currentTimeMillis());
    session.setApplicationData("abc=878s");
    session.setStatus(GlobalStatus.Begin);
    sessionManager.addGlobalSession(session);
    GlobalSession globalSession_db = sessionManager.findGlobalSession(session.getXid());
    Assertions.assertNotNull(globalSession_db);
    Assertions.assertEquals(globalSession_db.getTransactionId(), session.getTransactionId());
    Assertions.assertEquals(globalSession_db.getXid(), session.getXid());
    Assertions.assertEquals(globalSession_db.getApplicationData(), session.getApplicationData());
    Assertions.assertEquals(globalSession_db.getApplicationId(), session.getApplicationId());
    Assertions.assertEquals(globalSession_db.getTransactionName(), session.getTransactionName());
    Assertions.assertEquals(globalSession_db.getTransactionServiceGroup(), session.getTransactionServiceGroup());
    Assertions.assertEquals(globalSession_db.getBeginTime(), session.getBeginTime());
    Assertions.assertEquals(globalSession_db.getTimeout(), session.getTimeout());
    Assertions.assertEquals(globalSession_db.getStatus(), session.getStatus());
    String delSql = "delete from global_table where xid= '" + xid + "'";
    Connection conn = null;
    try {
        conn = dataSource.getConnection();
        conn.createStatement().execute(delSql);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) Connection(java.sql.Connection) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalSession (io.seata.server.session.GlobalSession)73 BranchSession (io.seata.server.session.BranchSession)33 Test (org.junit.jupiter.api.Test)32 Connection (java.sql.Connection)10 TransactionException (io.seata.core.exception.TransactionException)9 ArrayList (java.util.ArrayList)8 SessionCondition (io.seata.server.session.SessionCondition)7 GlobalTransactionEvent (io.seata.core.event.GlobalTransactionEvent)6 BranchStatus (io.seata.core.model.BranchStatus)6 ResultSet (java.sql.ResultSet)6 GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)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 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 BranchTransactionException (io.seata.core.exception.BranchTransactionException)4 TransactionWriteStore (io.seata.server.storage.file.TransactionWriteStore)4 GlobalStatus (io.seata.core.model.GlobalStatus)3 SessionManager (io.seata.server.session.SessionManager)3