use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.
the class ObjStoreBrowserTest method setUp.
@Before
public void setUp() throws Exception {
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
rcm = new RecoveryManagerImple(false);
rcm.addModule(new AtomicActionRecoveryModule());
}
use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.
the class JTSSynchronizationTest method test.
@Test
public void test() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("com.arjuna.orbportability.orb.PreInit1", "com.arjuna.ats.internal.jts.context.ContextPropagationManager");
map.put("com.arjuna.orbportability.orb.PostInit", "com.arjuna.ats.jts.utils.ORBSetup");
map.put("com.arjuna.orbportability.orb.PostInit2", "com.arjuna.ats.internal.jts.recovery.RecoveryInit");
map.put("com.arjuna.orbportability.orb.PostSet1", "com.arjuna.ats.jts.utils.ORBSetup");
opPropertyManager.getOrbPortabilityEnvironmentBean().setOrbInitializationProperties(map);
ORB myORB = ORB.getInstance("test");
RootOA myOA = OA.getRootOA(myORB);
final Properties initORBProperties = new Properties();
initORBProperties.setProperty("com.sun.CORBA.POA.ORBServerId", "1");
initORBProperties.setProperty("com.sun.CORBA.POA.ORBPersistentServerPort", "" + jtsPropertyManager.getJTSEnvironmentBean().getRecoveryManagerPort());
myORB.initORB(new String[] {}, initORBProperties);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryActivatorClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement" }));
final TransactionSynchronizationRegistry tsr = new com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple();
new RecoveryManagerImple(false);
final javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.getStatus();
tm.begin();
javax.transaction.Transaction theTransaction = tm.getTransaction();
assertTrue(theTransaction.enlistResource(new XARMERRXAResource(false)));
assertTrue(theTransaction.enlistResource(new XARMERRXAResource(false)));
tsr.registerInterposedSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
}
@Override
public void afterCompletion(int arg0) {
try {
Transaction transaction = tm.getTransaction();
Transaction suspend = tm.suspend();
assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_NO_TRANSACTION);
Transaction suspend2 = tm.suspend();
assertTrue(suspend2 == null);
tm.begin();
assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_ACTIVE);
tm.commit();
assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_NO_TRANSACTION);
tm.resume(suspend);
assertTrue(tm.getStatus() == arg0);
Transaction transaction2 = tm.getTransaction();
assertTrue(transaction == transaction2);
} catch (SystemException | IllegalStateException | SecurityException | InvalidTransactionException | NotSupportedException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
failed = true;
e.printStackTrace();
}
}
});
tm.commit();
myOA.destroy();
myORB.shutdown();
if (failed) {
fail("Issues");
}
}
use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.
the class RecoveryManagerService method start.
/**
* Called when the service is started.
* @param args The arguments
* @return The exit code to return if the task didn't start successfully, otherwise null.
*/
public Integer start(String[] args) {
Integer returnCode = null;
try {
new Uid();
_rm = new RecoveryManagerImple(true);
} catch (Throwable e) {
e.printStackTrace(System.err);
returnCode = new Integer(FAILED_TO_START_RETURN_CODE);
}
return returnCode;
}
use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.
the class TestCommitMarkableResourceFailAfterPrepareTwoXAResources method testFailAfterPrepare.
@Test
@BMScript("commitMarkableResourceFailAfterPrepare")
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;
XARecoveryModule xarm = 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) {
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, xaResource2 };
}
});
}
}
}
// 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);
xaResource2 = new SimpleXAResource2();
tm.getTransaction().enlistResource(xaResource2);
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);
// 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 memory
manager.scan();
assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
// Now we need to correctly complete the transaction
assertFalse(xaResource.wasCommitted());
assertFalse(xaResource.wasRolledback());
SimpleXAResource2.injectRollbackError();
boolean scanned = false;
try {
manager.scan();
scanned = true;
} catch (Error error) {
// This is expected from xaResource2, it is intended to simulate a
// crash
// Should clear off the scanning flag only
xarm.periodicWorkSecondPass();
}
if (scanned) {
fail("Should have failed scan");
}
assertFalse(xaResource.wasCommitted());
assertTrue(xaResource.wasRolledback());
assertFalse(xaResource2.commitCalled());
assertFalse(xaResource2.rollbackCalled());
RecoveryManagerImple recoveryManagerImple = new RecoveryManagerImple(false);
recoveryManagerImple.scan();
assertFalse(xaResource2.commitCalled());
assertTrue(xaResource2.rollbackCalled());
}
Aggregations