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