public void testXARecoverArgCheck()
throws Throwable {
createXAEnvAndDbs(1 << 20, false, NUM_DBS);
XAEnvironment xaEnv = (XAEnvironment) env;
try {
XidImpl xid = new XidImpl(1, "TwoPCTest1".getBytes(), null);
Transaction txn = null;
/* Check that only one of TMJOIN and TMRESUME can be set. */
try {
xaEnv.start(xid, XAResource.TMJOIN | XAResource.TMRESUME);
fail("Expected XAException(XAException.XAER_INVAL)");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_INVAL);
}
/*
* Check that only one of TMJOIN and TMRESUME can be set by passing
* a bogus flag value (TMSUSPEND).
*/
try {
xaEnv.start(xid, XAResource.TMSUSPEND);
fail("Expected XAException(XAException.XAER_INVAL)");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_INVAL);
}
xaEnv.start(xid, XAResource.TMNOFLAGS);
try {
xaEnv.start(xid, XAResource.TMNOFLAGS);
fail("Expected XAER_DUPID");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_DUPID);
}
xaEnv.end(xid, XAResource.TMNOFLAGS);
/*
* Check that JOIN with a non-existant association throws NOTA.
*/
try {
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.start(xid, XAResource.TMJOIN);
fail("Expected XAER_NOTA");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_NOTA);
}
/*
* Check that RESUME with a non-existant association throws NOTA.
*/
try {
xaEnv.start(xid, XAResource.TMRESUME);
fail("Expected XAER_NOTA");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_NOTA);
}
/*
* Check that start(JOIN) from a thread that is already associated
* throws XAER_PROTO.
*/
Xid xid2 = new XidImpl(1, "TwoPCTest3".getBytes(), null);
xaEnv.start(xid2, XAResource.TMNOFLAGS);
xaEnv.end(xid2, XAResource.TMNOFLAGS);
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.start(xid, XAResource.TMNOFLAGS);
try {
xaEnv.start(xid2, XAResource.TMJOIN);
fail("Expected XAER_PROTO");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_PROTO);
}
/*
* Check that start(RESUME) for an xid that is not suspended throws
* XAER_PROTO.
*/
try {
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.start(xid, XAResource.TMRESUME);
fail("Expected XAER_PROTO");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_PROTO);
}
/*
* Check that end(TMFAIL | TMSUCCESS) throws XAER_INVAL.
*/
try {
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.end(xid, XAResource.TMFAIL | XAResource.TMSUCCESS);
fail("Expected XAER_INVAL");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_INVAL);
}
/*
* Check that end(TMFAIL | TMSUSPEND) throws XAER_INVAL.
*/
try {
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.end(xid, XAResource.TMFAIL | XAResource.TMSUSPEND);
fail("Expected XAER_INVAL");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_INVAL);
}
/*
* Check that end(TMSUCCESS | TMSUSPEND) throws XAER_INVAL.
*/
try {
xid = new XidImpl(1, "TwoPCTest2".getBytes(), null);
xaEnv.end(xid, XAResource.TMSUCCESS | XAResource.TMSUSPEND);
fail("Expected XAER_INVAL");
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_INVAL);
}
/*
* Check that end(TMSUSPEND) actually works.
*/
Xid xid4 = new XidImpl(1, "TwoPCTest4".getBytes(), null);
xaEnv.start(xid4, XAResource.TMNOFLAGS);
Transaction txn4 = xaEnv.getThreadTransaction();
assertTrue(txn4 != null);
xaEnv.end(xid4, XAResource.TMSUSPEND);
assertTrue(xaEnv.getThreadTransaction() == null);
Xid xid5 = new XidImpl(1, "TwoPCTest5".getBytes(), null);
xaEnv.start(xid5, XAResource.TMNOFLAGS);
Transaction txn5 = xaEnv.getThreadTransaction();
xaEnv.end(xid5, XAResource.TMSUSPEND);
assertTrue(xaEnv.getThreadTransaction() == null);
xaEnv.start(xid4, XAResource.TMRESUME);
assertTrue(xaEnv.getThreadTransaction().equals(txn4));
xaEnv.end(xid4, XAResource.TMNOFLAGS);
xaEnv.start(xid5, XAResource.TMRESUME);
assertTrue(xaEnv.getThreadTransaction().equals(txn5));
xaEnv.end(xid5, XAResource.TMNOFLAGS);
/*
* Check TMFAIL.
*/
try {
xid = new XidImpl(1, "TwoPCTest6".getBytes(), null);
xaEnv.start(xid, XAResource.TMNOFLAGS);
xaEnv.end(xid, XAResource.TMFAIL);
xaEnv.commit(xid, false);
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XA_RBROLLBACK);
}
xaEnv.rollback(xid);
/*
* Check TMSUCCESS.
*/
xid = new XidImpl(1, "TwoPCTest6".getBytes(), null);
xaEnv.start(xid, XAResource.TMNOFLAGS);
xaEnv.end(xid, XAResource.TMSUCCESS);
xaEnv.commit(xid, false);
/*
* Check start(); end(SUSPEND); end(SUCCESS). This is a case that
* JBoss causes to happen. It should succeed.
*/
xid = new XidImpl(1, "TwoPCTest7".getBytes(), null);
xaEnv.start(xid, XAResource.TMNOFLAGS);
xaEnv.end(xid, XAResource.TMSUSPEND);
xaEnv.end(xid, XAResource.TMSUCCESS);
xaEnv.commit(xid, false);
/*
* Check end(SUSPEND); end(SUCCESS) [with no start() call.].
* This should fail.
*/
try {
xid = new XidImpl(1, "TwoPCTest8".getBytes(), null);
xaEnv.end(xid, XAResource.TMFAIL);
xaEnv.commit(xid, false);
} catch (XAException XAE) {
/* Expect this. */
assertTrue(XAE.errorCode == XAException.XAER_NOTA);
}
} catch (Throwable t) {