use of org.h2.mvstore.db.TransactionStore.Transaction in project narayana by jbosstm.
the class TestCommitMarkableResourceGCFromCrashAfterCommit method testFailAfterCommitH2.
@Test
public void testFailAfterCommitH2() throws Exception {
final DataSource dataSource = new JdbcDataSource();
((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 recoveryModule = null;
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
}
}
}
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
XAResource nonXAResource = new JDBCConnectableResource(localJDBCConnection);
tm.getTransaction().enlistResource(nonXAResource);
XAResource xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
// Check if the item is still in the db
recoveryModule.periodicWorkFirstPass();
recoveryModule.periodicWorkSecondPass();
assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project narayana by jbosstm.
the class TestCommitMarkableResourceMBeansFailAfterPrepare method testObjStoreBrowser.
@Test
@BMScript("commitMarkableResourceFailAfterPrepare")
public void testObjStoreBrowser() throws Exception {
final DataSource dataSource = new JdbcDataSource();
ObjStoreBrowser osb = new ObjStoreBrowser();
Uid uid = generateCMRRecord(dataSource);
osb.start();
osb.probe();
// there should be one MBean corresponding to the Transaction
UidWrapper w = osb.findUid(uid);
assertNotNull("ObjStoreBrowser could not find CMR uid wrapper", w);
OSEntryBean ai = w.getMBean();
assertNotNull("ObjStoreBrowser could not find CMR uid", ai);
assertEquals("ObjStoreBrowser found the wrong uid", ai.getUid(), uid);
checkCMRRecovery(dataSource);
w = osb.findUid(uid);
assertNotNull("CMR uid still exists after a recovery can", w);
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project narayana by jbosstm.
the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterNoCommit.
@Test
public void testRMFAILAfterNoCommit() throws Exception {
jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
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) {
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 };
}
});
}
}
}
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection) {
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
throw new XAException(XAException.XAER_RMFAIL);
}
};
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
assertTrue(xaResource.wasCommitted());
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
InputObjectState uids = new InputObjectState();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
Uid uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(get_uid));
// Belt and braces but we don't expect the CMR to be removed anyway as
// the RM is "offline"
manager.scan();
manager.scan();
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
// This will make the AA a heuristic
manager.scan();
EditableAtomicAction editableAtomicAction = new EditableAtomicAction(get_uid);
editableAtomicAction.deleteHeuristicParticipant(0);
manager.scan();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(Uid.nullUid()));
// This is when the CMR deletes are done due to ordering
manager.scan();
// of the recovery modules
assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project narayana by jbosstm.
the class FailAfterPrepareBase method generateCMRRecord.
protected Uid generateCMRRecord(final DataSource dataSource) throws Exception {
((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
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
} else if (m instanceof XARecoveryModule) {
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) {
final Uid[] uids = new Uid[1];
Thread foo = new Thread(new Runnable() {
public void run() {
try {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection);
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
uids[0] = ((TransactionImple) tm.getTransaction()).get_uid();
tm.commit();
} catch (ExecuteException t) {
} catch (Exception t) {
t.printStackTrace();
failed = true;
} catch (Error t) {
}
}
});
foo.start();
foo.join();
assertFalse(failed);
return uids[0];
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project narayana by jbosstm.
the class TestCommitMarkableResourceFailActivate method testFailAfterPrepare.
@Test
@BMScript("commitMarkableResourceFailAfterCommit")
public void testFailAfterPrepare() throws Exception {
final DataSource dataSource = new JdbcDataSource();
((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 recoveryModule = null;
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
} else if (m instanceof XARecoveryModule) {
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 foo = new Thread(new Runnable() {
public void run() {
try {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection);
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
} catch (ExecuteException t) {
} catch (Exception t) {
t.printStackTrace();
failed = true;
} catch (Error t) {
}
}
});
foo.start();
foo.join();
assertFalse(failed);
// Now we need to correctly complete the transaction
manager.scan();
assertFalse(xaResource.wasCommitted());
assertFalse(xaResource.wasRolledback());
// This is test code, it allows us to verify that the
// correct XID was
// removed
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
// Run the first pass it will load the committed Xids into so we can
// indepently verify that the item was committed
recoveryModule.periodicWorkFirstPass();
recoveryModule.periodicWorkSecondPass();
assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
// Run the scan to clear the content
manager.scan();
assertTrue(xaResource.wasCommitted());
assertFalse(xaResource.wasRolledback());
// Make sure that the resource was GC'd by the CRRRM
assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
recoveryModule.periodicWorkFirstPass();
assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
// This is the pass that will delete it
recoveryModule.periodicWorkSecondPass();
assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
}
Aggregations