use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.
the class CrashRecovery2 method setUp.
@Before
public void setUp() {
RecoveryEnvironmentBean recoveryEnvironmentBean = recoveryPropertyManager.getRecoveryEnvironmentBean();
recoveryEnvironmentBean.setRecoveryModuleClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule", "com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule" }));
JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
jtaEnvironmentBean.setXaResourceRecoveryClassNames(Arrays.asList(new String[] { "com.hp.mwtests.ts.jta.recovery.TestXAResourceRecovery" }));
jtaEnvironmentBean.setXaResourceOrphanFilterClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter", "com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter" }));
jtaEnvironmentBean.setXaRecoveryNodes(Arrays.asList(new String[] { "1" }));
}
use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.
the class CrashRecoveryCommitReturnsXA_RETRY method test.
@Test
public void test() throws Exception {
// this test is supposed to leave a record around in the log store
// during a commit long enough
// that the periodic recovery thread runs and detects it. rather than
// rely on delays to make
// this happen (placing us at the mercy of the scheduler) we use a
// byteman script to enforce
// the thread sequence we need
RecoveryEnvironmentBean recoveryEnvironmentBean = BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class);
recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
recoveryEnvironmentBean.setPeriodicRecoveryPeriod(1);
List<String> recoveryModuleClassNames = new ArrayList<String>();
recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
List<String> expiryScannerClassNames = new ArrayList<String>();
expiryScannerClassNames.add("com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScannerClassNames);
recoveryEnvironmentBean.setRecoveryActivators(null);
// start the recovery manager
RecoveryManager.manager().initialize();
XARecoveryModule xaRecoveryModule = null;
for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) RecoveryManager.manager().getModules())) {
if (recoveryModule instanceof XARecoveryModule) {
xaRecoveryModule = (XARecoveryModule) recoveryModule;
break;
}
}
if (xaRecoveryModule == null) {
throw new Exception("No XARM");
}
XAResource firstResource = new SimpleResource();
final SimpleResourceXA_RETRY secondResource = new SimpleResourceXA_RETRY(this);
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
// TODO Auto-generated method stub
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
// TODO Auto-generated method stub
return new XAResource[] { secondResource };
}
});
// ok, now drive a TX to completion. the script should ensure that the
// recovery
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
javax.transaction.Transaction theTransaction = tm.getTransaction();
theTransaction.enlistResource(firstResource);
theTransaction.enlistResource(secondResource);
assertFalse(secondResource.wasCommitted());
tm.commit();
synchronized (this) {
while (!committed) {
wait();
}
}
assertTrue(secondResource.wasCommitted());
}
use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project wildfly by wildfly.
the class ArjunaRecoveryManagerService method start.
public synchronized void start(StartContext context) throws StartException {
// Recovery env bean
final RecoveryEnvironmentBean recoveryEnvironmentBean = recoveryPropertyManager.getRecoveryEnvironmentBean();
final SocketBinding recoveryBinding = recoveryBindingInjector.getValue();
recoveryEnvironmentBean.setRecoveryInetAddress(recoveryBinding.getSocketAddress().getAddress());
recoveryEnvironmentBean.setRecoveryPort(recoveryBinding.getSocketAddress().getPort());
final SocketBinding statusBinding = statusBindingInjector.getValue();
recoveryEnvironmentBean.setTransactionStatusManagerInetAddress(statusBinding.getSocketAddress().getAddress());
recoveryEnvironmentBean.setTransactionStatusManagerPort(statusBinding.getSocketAddress().getPort());
recoveryEnvironmentBean.setRecoveryListener(recoveryListener);
if (recoveryListener) {
ManagedBinding binding = ManagedBinding.Factory.createSimpleManagedBinding(recoveryBinding);
bindingManager.getValue().getNamedRegistry().registerBinding(binding);
}
final List<String> recoveryExtensions = new ArrayList<String>();
// must be first
recoveryExtensions.add(CommitMarkableResourceRecordRecoveryModule.class.getName());
recoveryExtensions.add(AtomicActionRecoveryModule.class.getName());
recoveryExtensions.add(TORecoveryModule.class.getName());
recoveryExtensions.add(SubordinateAtomicActionRecoveryModule.class.getName());
final List<String> expiryScanners;
if (System.getProperty("RecoveryEnvironmentBean.expiryScannerClassNames") != null || System.getProperty("com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean.expiryScannerClassNames") != null) {
expiryScanners = recoveryEnvironmentBean.getExpiryScannerClassNames();
} else {
expiryScanners = new ArrayList<String>();
expiryScanners.add(ExpiredTransactionStatusManagerScanner.class.getName());
}
if (!jts) {
recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.class.getName());
recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
recoveryEnvironmentBean.setRecoveryActivators(null);
final RecoveryManagerService recoveryManagerService = new RecoveryManagerService();
try {
recoveryManagerService.create();
} catch (Exception e) {
throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
}
recoveryManagerService.start();
this.recoveryManagerService = recoveryManagerService;
} else {
final ORB orb = orbInjector.getValue();
new PostInitLoader(PostInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb"), orb);
recoveryExtensions.add(TopLevelTransactionRecoveryModule.class.getName());
recoveryExtensions.add(ServerTransactionRecoveryModule.class.getName());
recoveryExtensions.add(JCAServerTransactionRecoveryModule.class.getName());
recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule.class.getName());
expiryScanners.add(ExpiredContactScanner.class.getName());
expiryScanners.add(ExpiredToplevelScanner.class.getName());
expiryScanners.add(ExpiredServerScanner.class.getName());
recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
recoveryEnvironmentBean.setRecoveryActivatorClassNames(Collections.singletonList(com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement.class.getName()));
try {
final RecoveryManagerService recoveryManagerService = new com.arjuna.ats.jbossatx.jts.RecoveryManagerService(orb);
recoveryManagerService.create();
recoveryManagerService.start();
this.recoveryManagerService = recoveryManagerService;
} catch (Exception e) {
throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
}
}
recoverySuspendController = new RecoverySuspendController(recoveryManagerService);
processStateInjector.getValue().addPropertyChangeListener(recoverySuspendController);
suspendControllerInjector.getValue().registerActivity(recoverySuspendController);
}
use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.
the class PeriodicRecoveryTest method testInitialDelay.
@Test
public void testInitialDelay() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
RecoveryEnvironmentBean bean = recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryInitilizationOffset(1);
PeriodicRecovery periodicRecovery = new PeriodicRecovery(false, false);
Method doInitialWait = periodicRecovery.getClass().getDeclaredMethod("doInitialWait");
doInitialWait.setAccessible(true);
long l = System.currentTimeMillis();
try {
doInitialWait.invoke(periodicRecovery, null);
} finally {
doInitialWait.setAccessible(false);
}
assertTrue(System.currentTimeMillis() - l > 500);
}
use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.
the class CrashRecoveryCommitReturnsXA_RETRYHeuristicRollback method testHeuristicRollback.
@Test
public void testHeuristicRollback() throws Exception {
// this test is supposed to leave a record around in the log store
// during a commit long enough
// that the periodic recovery thread runs and detects it. rather than
// rely on delays to make
// this happen (placing us at the mercy of the scheduler) we use a
// byteman script to enforce
// the thread sequence we need
RecoveryEnvironmentBean recoveryEnvironmentBean = BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class);
// JBTM-1354 we need to make sure that a full scan has gone off
recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
recoveryEnvironmentBean.setPeriodicRecoveryPeriod(Integer.MAX_VALUE);
List<String> recoveryModuleClassNames = new ArrayList<String>();
recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
List<String> expiryScannerClassNames = new ArrayList<String>();
expiryScannerClassNames.add("com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScannerClassNames);
recoveryEnvironmentBean.setRecoveryActivators(null);
// start the recovery manager
RecoveryManager.manager().initialize();
XARecoveryModule xaRecoveryModule = null;
for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) RecoveryManager.manager().getModules())) {
if (recoveryModule instanceof XARecoveryModule) {
xaRecoveryModule = (XARecoveryModule) recoveryModule;
break;
}
}
if (xaRecoveryModule == null) {
throw new Exception("No XARM");
}
// JBTM-1354 Run a scan to make sure that the recovery thread has completed a full run before starting the test
// The important thing is that replayCompletion is allowed to do a scan of the transactions
RecoveryManager.manager().scan();
XAResource firstResource = new SimpleResource();
Object toWakeUp = new Object();
final SimpleResourceXA_RETRYHeuristicRollback secondResource = new SimpleResourceXA_RETRYHeuristicRollback();
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
// TODO Auto-generated method stub
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
// TODO Auto-generated method stub
return new XAResource[] { secondResource };
}
});
// ok, now drive a TX to completion. the script should ensure that the
// recovery
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
javax.transaction.Transaction theTransaction = tm.getTransaction();
Uid txUid = ((TransactionImple) theTransaction).get_uid();
theTransaction.enlistResource(firstResource);
theTransaction.enlistResource(secondResource);
assertFalse(secondResource.wasCommitted());
tm.commit();
InputObjectState uids = new InputObjectState();
String type = new AtomicAction().type();
StoreManager.getRecoveryStore().allObjUids(type, uids);
boolean moreUids = true;
boolean found = false;
while (moreUids) {
Uid theUid = UidHelper.unpackFrom(uids);
if (theUid.equals(txUid)) {
found = true;
Field heuristicListField = BasicAction.class.getDeclaredField("heuristicList");
heuristicListField.setAccessible(true);
ActionStatusService ass = new ActionStatusService();
{
int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
assertTrue(theStatus == ActionStatus.COMMITTED);
RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
theStatus = rcvAtomicAction.status();
rcvAtomicAction.replayPhase2();
assertTrue(theStatus == ActionStatus.COMMITTED);
assertTrue(secondResource.wasCommitted());
RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
}
{
int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
assertTrue(theStatus == ActionStatus.COMMITTED);
RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
theStatus = rcvAtomicAction.status();
assertTrue(theStatus == ActionStatus.COMMITTED);
RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
assertTrue(secondResource.wasCommitted());
}
} else if (theUid.equals(Uid.nullUid())) {
moreUids = false;
}
}
if (!found) {
throw new Exception("Could not locate the Uid");
}
}
Aggregations