DataBaseSessionManager extends AbstractSessionManager implements SessionManager, SessionLifecycleListener, Initialize { @Override public void addBranchSession(GlobalSession globalSession, BranchSession session) throws TransactionException { if (StringUtils.isNotBlank(taskName)) { return; } boolean ret = transactionStoreManager.writeSession(LogOperation.BRANCH_ADD, session); if (!ret) { throw new StoreException("addBranchSession failed."); } } DataBaseSessionManager();  DataBaseSessionManager(String name); @Override void init(); @Override void addGlobalSession(GlobalSession session); @Override void updateGlobalSessionStatus(GlobalSession session, GlobalStatus status); @Override void removeGlobalSession(GlobalSession session); @Override void addBranchSession(GlobalSession globalSession, BranchSession session); @Override void updateBranchSessionStatus(BranchSession session, BranchStatus status); @Override void removeBranchSession(GlobalSession globalSession, BranchSession session); @Override GlobalSession findGlobalSession(String xid); @Override Collection<GlobalSession> allSessions(); @Override List<GlobalSession> findGlobalSessions(SessionCondition condition);  }
@Test public void test_addBranchSession() 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\"}"); sessionManager.addBranchSession(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(true); }else{ Assertions.assertTrue(false); } conn.createStatement().execute(delSql); }finally { if(conn != null){ conn.close(); } } }