Search in sources :

Example 1 with XAXid

use of io.seata.rm.datasource.xa.XAXid in project seata by seata.

the class XAXidBuilderTest method testXid.

@Test
public void testXid() throws Throwable {
    long mockBranchId = 1582688600006L;
    String mockXid = "127.0.0.1:8091:" + mockBranchId;
    XAXid xaXid = XAXidBuilder.build(mockXid, mockBranchId);
    XAXid retrievedXAXid = XAXidBuilder.build(xaXid.getGlobalTransactionId(), xaXid.getBranchQualifier());
    String retrievedXid = retrievedXAXid.getGlobalXid();
    long retrievedBranchId = retrievedXAXid.getBranchId();
    Assertions.assertEquals(mockXid, retrievedXid);
    Assertions.assertEquals(mockBranchId, retrievedBranchId);
}
Also used : XAXid(io.seata.rm.datasource.xa.XAXid) Test(org.junit.jupiter.api.Test)

Example 2 with XAXid

use of io.seata.rm.datasource.xa.XAXid in project seata by seata.

the class XAModeTest2 method testXid.

@Test
@Disabled
public void testXid() throws Throwable {
    XAXid xaXid = XAXidBuilder.build(mockXid, mockBranchId);
    XAXid retrievedXAXid = XAXidBuilder.build(xaXid.getGlobalTransactionId(), xaXid.getBranchQualifier());
    String retrievedXid = retrievedXAXid.getGlobalXid();
    long retrievedBranchId = retrievedXAXid.getBranchId();
    Assertions.assertEquals(mockXid, retrievedXid);
    Assertions.assertEquals(mockBranchId, retrievedBranchId);
}
Also used : XAXid(io.seata.rm.datasource.xa.XAXid) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with XAXid

use of io.seata.rm.datasource.xa.XAXid in project seata by seata.

the class XAModeTest2 method doTestXAModeNormalCasePhase1.

private void doTestXAModeNormalCasePhase1(String mockXid, Long mockBranchId) throws Throwable {
    // init DataSource: helper
    DruidDataSource helperDS = createNewDruidDataSource();
    Connection helperConn = null;
    Statement helperStat = null;
    ResultSet helperRes = null;
    // init RM
    initRM();
    AbstractDataSourceProxyXA dataSourceProxyXA = null;
    if (nativeXA) {
        // init XADataSource runnerXA
        XADataSource runnerXADS = createNewNativeXADataSource();
        dataSourceProxyXA = new DataSourceProxyXANative(runnerXADS);
    } else {
        // init DataSource: runner
        DruidDataSource runnerDS = createNewDruidDataSource();
        dataSourceProxyXA = new DataSourceProxyXA(runnerDS);
    }
    // Global Tx Phase 1:
    RootContext.bind(mockXid);
    Connection testConn = dataSourceProxyXA.getConnection();
    Statement testStat = testConn.createStatement();
    // >>> insert the test record with XA mode
    testStat.execute("insert into test(id, name) values(" + testRecordId + ", '" + testRecordName + "')");
    // >>> close the statement and connection
    testStat.close();
    testConn.close();
    RootContext.unbind();
    // have a check
    helperConn = helperDS.getConnection();
    helperStat = helperConn.createStatement();
    helperRes = helperStat.executeQuery("select * from test where id = " + testRecordId);
    // should NOT see the record(id=888) now
    Assertions.assertFalse(helperRes.next());
    helperRes.close();
    helperStat.close();
    helperConn.close();
    if (JdbcUtils.MYSQL.equals(dbType)) {
        XAXid xaXid = XAXidBuilder.build(mockXid, mockBranchId);
        dataSourceProxyXA.forceClosePhysicalConnection(xaXid);
    }
    System.out.println("Phase1 looks good!");
}
Also used : AbstractDataSourceProxyXA(io.seata.rm.datasource.xa.AbstractDataSourceProxyXA) DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) XADataSource(javax.sql.XADataSource) MysqlXADataSource(com.mysql.jdbc.jdbc2.optional.MysqlXADataSource) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource) PGXADataSource(org.postgresql.xa.PGXADataSource) DataSourceProxyXANative(io.seata.rm.datasource.xa.DataSourceProxyXANative) Statement(java.sql.Statement) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) ResultSet(java.sql.ResultSet) XAXid(io.seata.rm.datasource.xa.XAXid) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) AbstractDataSourceProxyXA(io.seata.rm.datasource.xa.AbstractDataSourceProxyXA)

Aggregations

XAXid (io.seata.rm.datasource.xa.XAXid)3 Test (org.junit.jupiter.api.Test)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 DruidXADataSource (com.alibaba.druid.pool.xa.DruidXADataSource)1 MysqlXADataSource (com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)1 AbstractDataSourceProxyXA (io.seata.rm.datasource.xa.AbstractDataSourceProxyXA)1 DataSourceProxyXA (io.seata.rm.datasource.xa.DataSourceProxyXA)1 DataSourceProxyXANative (io.seata.rm.datasource.xa.DataSourceProxyXANative)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 XAConnection (javax.sql.XAConnection)1 XADataSource (javax.sql.XADataSource)1 Disabled (org.junit.jupiter.api.Disabled)1 PGXADataSource (org.postgresql.xa.PGXADataSource)1