use of io.seata.server.session.GlobalSession in project seata by seata.
the class DataBaseSessionManagerTest method test_removeBranchSession.
@Test
public void test_removeBranchSession() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test", "test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.setTransactionId(146757978);
globalSession.setBeginTime(System.currentTimeMillis());
globalSession.setApplicationData("abc=878s");
globalSession.setStatus(GlobalStatus.Begin);
BranchSession branchSession = new BranchSession();
branchSession.setBranchId(UUIDGenerator.generateUUID());
branchSession.setXid(xid);
branchSession.setTransactionId(globalSession.getTransactionId());
branchSession.setBranchId(1L);
branchSession.setResourceGroupId("my_test_tx_group");
branchSession.setResourceId("tb_1");
branchSession.setLockKey("t_1");
branchSession.setBranchType(BranchType.AT);
branchSession.setApplicationData("{\"data\":\"test\"}");
branchSession.setStatus(BranchStatus.PhaseOne_Done);
sessionManager.addBranchSession(globalSession, branchSession);
sessionManager.removeBranchSession(globalSession, branchSession);
String sql = "select * from branch_table where xid= '" + xid + "'";
String delSql = "delete from branch_table where xid= '" + xid + "'" + ";" + "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(false);
} else {
Assertions.assertTrue(true);
}
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_addGlobalSession.
@Test
public void test_addGlobalSession() throws TransactionException, SQLException {
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);
}
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_updateBranchSessionStatus.
@Test
public void test_updateBranchSessionStatus() throws Exception {
GlobalSession globalSession = GlobalSession.createGlobalSession("test", "test", "test123", 100);
String xid = XID.generateXID(globalSession.getTransactionId());
globalSession.setXid(xid);
globalSession.setTransactionId(146757978);
globalSession.setBeginTime(System.currentTimeMillis());
globalSession.setApplicationData("abc=878s");
globalSession.setStatus(GlobalStatus.Begin);
BranchSession branchSession = new BranchSession();
branchSession.setBranchId(UUIDGenerator.generateUUID());
branchSession.setXid(xid);
branchSession.setTransactionId(globalSession.getTransactionId());
branchSession.setBranchId(1L);
branchSession.setResourceGroupId("my_test_tx_group");
branchSession.setResourceId("tb_1");
branchSession.setLockKey("t_1");
branchSession.setBranchType(BranchType.AT);
branchSession.setApplicationData("{\"data\":\"test\"}");
branchSession.setStatus(BranchStatus.PhaseOne_Done);
sessionManager.addBranchSession(globalSession, branchSession);
branchSession.setStatus(BranchStatus.PhaseOne_Timeout);
sessionManager.updateBranchSessionStatus(branchSession, BranchStatus.PhaseOne_Timeout);
String sql = "select * from branch_table where xid= '" + xid + "'";
String delSql = "delete from branch_table where xid= '" + xid + "'" + ";" + "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);
Assertions.assertEquals(rs.getInt("status"), BranchStatus.PhaseOne_Timeout.getCode());
} else {
Assertions.assertTrue(false);
}
conn.createStatement().execute(delSql);
} finally {
if (conn != null) {
conn.close();
}
}
}
use of io.seata.server.session.GlobalSession in project seata by seata.
the class SessionConverterTest method testConvertGlobalSessionNull.
@Test
public void testConvertGlobalSessionNull() {
GlobalTransactionDO globalTransactionDO = null;
GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
Assertions.assertNull(globalSession);
}
use of io.seata.server.session.GlobalSession in project seata by seata.
the class SessionConverterTest method testConvertGlobalSessionNotNull.
@Test
public void testConvertGlobalSessionNotNull() {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
Date date = new Date();
long now = date.getTime();
globalTransactionDO.setXid("192.168.158.80:8091:39372760251957248");
globalTransactionDO.setTransactionId(39372760251957248L);
globalTransactionDO.setStatus(1);
globalTransactionDO.setApplicationId("credit");
globalTransactionDO.setTransactionServiceGroup("fsp_tx");
globalTransactionDO.setTransactionName("createOrder");
globalTransactionDO.setTimeout(60);
globalTransactionDO.setBeginTime(now);
globalTransactionDO.setApplicationData("id=1,product=2");
globalTransactionDO.setGmtCreate(date);
globalTransactionDO.setGmtModified(date);
GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
Assertions.assertEquals(globalTransactionDO.getXid(), globalSession.getXid());
Assertions.assertEquals(globalTransactionDO.getTransactionId(), globalSession.getTransactionId());
Assertions.assertEquals(globalTransactionDO.getStatus(), globalSession.getStatus().getCode());
Assertions.assertEquals(globalTransactionDO.getApplicationId(), globalSession.getApplicationId());
Assertions.assertEquals(globalTransactionDO.getTransactionServiceGroup(), globalSession.getTransactionServiceGroup());
Assertions.assertEquals(globalTransactionDO.getTransactionName(), globalSession.getTransactionName());
Assertions.assertEquals(globalTransactionDO.getTimeout(), globalSession.getTimeout());
Assertions.assertEquals(globalTransactionDO.getBeginTime(), globalSession.getBeginTime());
Assertions.assertEquals(globalTransactionDO.getApplicationData(), globalSession.getApplicationData());
}
Aggregations