use of com.mysql.cj.jdbc.MysqlXid in project project by Ahaochan.
the class MysqlXANativeTest method prepare.
private Xid prepare(XAResource xaResource, String bqualStr, PreparedStatement statement) throws Exception {
// gtrid: 全局事务ID
// bqual: 分支修饰词标识符(branch qualifier)
// formatID: 是一个无符号整数,用于标记gtrid和bqual值的格式,默认为1,长度不超过64.
byte[] gtrid = "g12345".getBytes();
byte[] bqual = bqualStr.getBytes();
int formatId = 1;
// 这个xid代表了一个子事务
Xid xid = new MysqlXid(gtrid, bqual, formatId);
// 通过START和END两个操作, 定义子事务要执行的SQL语句
// 但是这里的SQL绝对不会执行的, 只是说先定义好, 在子事务中要执行哪些SQL
xaResource.start(xid, XAResource.TMNOFLAGS);
statement.execute();
xaResource.end(xid, XAResource.TMSUCCESS);
return xid;
}
use of com.mysql.cj.jdbc.MysqlXid in project aws-mysql-jdbc by awslabs.
the class ConnectionRegressionTest method testBug69506.
/**
* Tests fix for BUG#69506 - XAER_DUPID error code is not returned when a duplicate XID is offered in Java.
*
* @throws Exception
*/
@Test
public void testBug69506() throws Exception {
MysqlXADataSource dataSource = new MysqlXADataSource();
dataSource.setUrl(dbUrl);
dataSource.getStringProperty(PropertyKey.sslMode.getKeyName()).setValue("DISABLED");
dataSource.getBooleanProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName()).setValue(true);
XAConnection testXAConn1 = dataSource.getXAConnection();
XAConnection testXAConn2 = dataSource.getXAConnection();
Xid duplicateXID = new MysqlXid("1".getBytes(), "1".getBytes(), 1);
testXAConn1.getXAResource().start(duplicateXID, 0);
try {
testXAConn2.getXAResource().start(duplicateXID, 0);
fail("XAException was expected.");
} catch (XAException e) {
assertEquals(XAException.XAER_DUPID, e.errorCode, "Wrong error code retured for duplicated XID.");
}
}
use of com.mysql.cj.jdbc.MysqlXid in project aws-mysql-jdbc by awslabs.
the class XATest method createXid.
private Xid createXid() throws IOException {
ByteArrayOutputStream gtridOut = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(gtridOut);
new UID().write(dataOut);
final byte[] gtrid = gtridOut.toByteArray();
ByteArrayOutputStream bqualOut = new ByteArrayOutputStream();
dataOut = new DataOutputStream(bqualOut);
new UID().write(dataOut);
final byte[] bqual = bqualOut.toByteArray();
Xid xid = new MysqlXid(gtrid, bqual, 3306);
return xid;
}
use of com.mysql.cj.jdbc.MysqlXid in project aws-mysql-jdbc by awslabs.
the class ConnectionRegressionTest method testBug46925.
@Test
public void testBug46925() throws Exception {
MysqlXADataSource xads1 = new MysqlXADataSource();
MysqlXADataSource xads2 = new MysqlXADataSource();
Xid txid = new MysqlXid(new byte[] { 0x1 }, new byte[] { 0xf }, 3306);
xads1.getStringProperty(PropertyKey.sslMode.getKeyName()).setValue("DISABLED");
xads1.getBooleanProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName()).setValue(true);
xads1.getProperty(PropertyKey.pinGlobalTxToPhysicalConnection).setValue(true);
xads1.setUrl(dbUrl);
xads2.getStringProperty(PropertyKey.sslMode.getKeyName()).setValue("DISABLED");
xads2.getBooleanProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName()).setValue(true);
xads2.getProperty(PropertyKey.pinGlobalTxToPhysicalConnection).setValue(true);
xads2.setUrl(dbUrl);
XAConnection c1 = xads1.getXAConnection();
assertTrue(c1 instanceof SuspendableXAConnection);
// start a transaction on one connection
c1.getXAResource().start(txid, XAResource.TMNOFLAGS);
c1.getXAResource().end(txid, XAResource.TMSUCCESS);
XAConnection c2 = xads2.getXAConnection();
assertTrue(c2 instanceof SuspendableXAConnection);
// prepare on another one. Since we are using a "pinned" connection we should have the same "currentXAConnection" for both SuspendableXAConnection
// this will fail without the fix.
c2.getXAResource().prepare(txid);
c2.getXAResource().commit(txid, false);
}
use of com.mysql.cj.jdbc.MysqlXid in project aws-mysql-jdbc by awslabs.
the class ConnectionRegressionTest method testBug67803.
/**
* Tests fix for BUG#67803 - XA commands sent twice to MySQL server
*
* @throws Exception
*/
@Test
public void testBug67803() throws Exception {
MysqlXADataSource dataSource = new MysqlXADataSource();
dataSource.setUrl(dbUrl);
dataSource.getStringProperty(PropertyKey.sslMode.getKeyName()).setValue("DISABLED");
dataSource.getBooleanProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName()).setValue(true);
dataSource.getProperty(PropertyKey.useCursorFetch).setValue(true);
dataSource.getProperty(PropertyKey.defaultFetchSize).setValue(50);
dataSource.getProperty(PropertyKey.useServerPrepStmts).setValue(true);
dataSource.getProperty(PropertyKey.exceptionInterceptors).setValue("testsuite.regression.ConnectionRegressionTest$TestBug67803ExceptionInterceptor");
XAConnection testXAConn1 = dataSource.getXAConnection();
testXAConn1.getXAResource().start(new MysqlXid("2".getBytes(), "2".getBytes(), 1), 0);
}
Aggregations