use of com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter in project narayana by jbosstm.
the class XAResourceOrphanFilterTest method testJTATransactionLogOrphanFilter.
@Test
public void testJTATransactionLogOrphanFilter() {
XAResourceOrphanFilter orphanFilter = new JTATransactionLogXAResourceOrphanFilter();
Xid notJTAFormatId = XATxConverter.getXid(new Uid(), false, 0);
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(notJTAFormatId));
Xid jtaFormatId = XATxConverter.getXid(new Uid(), false, XATxConverter.FORMAT_ID);
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(jtaFormatId));
}
use of com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter in project narayana by jbosstm.
the class TestCommitMarkableResourceFailAfterCommitOrphan method test.
@Test
@BMScript("commitMarkableResourceFailAfterCommit")
public void test() throws Exception {
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
// Test code
Utils.createTables(dataSource.getConnection());
// We can't just instantiate one as we need to be using the
// same one as
// the transaction
// manager would have used to mark the transaction for GC
CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
} else if (m instanceof XARecoveryModule) {
xarm = (XARecoveryModule) m;
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
public boolean initialise(String p) throws Exception {
return true;
}
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { xaResource };
}
});
}
}
}
// final Object o = new Object();
// synchronized (o) {
Thread preCrash = new Thread(new Runnable() {
public void run() {
try (Connection localJDBCConnection = dataSource.getConnection()) {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
localJDBCConnection.setAutoCommit(false);
cmrResource = new JDBCConnectableResource(localJDBCConnection);
tm.getTransaction().enlistResource(cmrResource);
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
} catch (ExecuteException t) {
} catch (Exception e) {
e.printStackTrace();
failed = true;
} catch (Error e) {
}
}
});
preCrash.start();
preCrash.join();
assertFalse(failed);
assertFalse(wasCommitted);
assertFalse(wasRolledback);
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
// Testing that we can find a AAC but that it won't be ignored in orphan detection so need CMRRM run
commitMarkableResourceRecoveryModule.periodicWorkFirstPass();
XAResourceOrphanFilter.Vote vote = new JTATransactionLogXAResourceOrphanFilter().checkXid(preparedXid);
assertTrue(vote == XAResourceOrphanFilter.Vote.LEAVE_ALONE);
manager.scan();
manager.scan();
assertTrue(wasCommitted);
}
Aggregations