use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.
the class XAResourceRecord method getXAResourceDeserializers.
private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
if (serializableXAResourceDeserializers != null) {
return serializableXAResourceDeserializers;
}
synchronized (this) {
if (serializableXAResourceDeserializers != null) {
return serializableXAResourceDeserializers;
}
serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
if (recoveryModule instanceof XARecoveryModule) {
XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
return serializableXAResourceDeserializers;
}
}
}
return serializableXAResourceDeserializers;
}
use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.
the class XARecoveryModuleHelpersUnitTest method testTimelyXAResourceRecoveryHelperRemoval.
private void testTimelyXAResourceRecoveryHelperRemoval(final boolean somethingToRecover) throws Exception {
final XARecoveryModule xaRecoveryModule = new XARecoveryModule();
final long xAResourcesSleepMillis = 2000;
final long betweenPassesSleepMillis = 100;
final long millis = System.currentTimeMillis();
final SimpleResource testXAResource = new SimpleResource() {
@Override
public Xid[] recover(int i) throws XAException {
if (!somethingToRecover)
return new Xid[0];
return new Xid[] { new Xid() {
@Override
public int getFormatId() {
return 0;
}
@Override
public byte[] getGlobalTransactionId() {
return new byte[0];
}
@Override
public byte[] getBranchQualifier() {
return new byte[0];
}
} };
}
};
final XAResourceRecoveryHelper xaResourceRecoveryHelper = new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
System.out.printf("getXAResources sleep (%d)%n", System.currentTimeMillis() - millis);
Thread.sleep(xAResourcesSleepMillis);
System.out.printf("getXAResources return (%d)%n", System.currentTimeMillis() - millis);
return new XAResource[] { testXAResource };
}
};
final XAResourceRecoveryHelper xaResourceRecoveryHelper2 = new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[0];
}
};
/*
* Remove helpers in the background whilst recovery is running to check that they are removed when
* the scanner is in the correct state.
* The sleep time param is tuned to ensure that the add/remove recovery helper operation occurs
* during pass 1.
*/
XAHelperRemover remover = new XAHelperRemover(xaResourceRecoveryHelper, xaRecoveryModule, xAResourcesSleepMillis / 2, false);
XAHelperRemover remover2 = new XAHelperRemover(xaResourceRecoveryHelper2, xaRecoveryModule, xAResourcesSleepMillis / 2, true);
xaRecoveryModule.addXAResourceRecoveryHelper(xaResourceRecoveryHelper);
remover.start();
remover2.start();
System.out.printf("Before pass 1 (%d)%n", System.currentTimeMillis() - millis);
xaRecoveryModule.periodicWorkFirstPass();
System.out.printf("Finished pass 1 (%d)%n", System.currentTimeMillis() - millis);
Thread.sleep(betweenPassesSleepMillis);
System.out.printf("Starting pass 2 (%d)%n", System.currentTimeMillis() - millis);
xaRecoveryModule.periodicWorkSecondPass();
System.out.printf("Finished pass 2 (%d)%n", System.currentTimeMillis() - millis);
// wait for helper removal threads to finish
try {
remover.join();
remover2.join();
} catch (InterruptedException e) {
fail("Test was interrupted whilst waiting for xa resource helper threads: " + e.getMessage());
}
if (somethingToRecover) {
assertEquals("helper removed in wrong state", 0, remover.getRemoveState());
} else {
// See https://issues.jboss.org/browse/JBTM-2717
assertEquals("helper removed in wrong state", 2, remover.getRemoveState());
}
// the unused helper should have been removed after pass 1
assertEquals("helper2 removed in wrong state", 2, remover2.getRemoveState());
}
use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.
the class XARecoveryModuleHelpersUnitTest method testTimelyXAResourceRecoveryHelperRemoval3.
/**
* Test that recovery helpers can be added and removed during recovery pass 2
* (and not have to wait until pass 2 is complete)
* @throws Exception
*/
@BMScript("recovery-helper")
@Test
public void testTimelyXAResourceRecoveryHelperRemoval3() throws Exception {
final XARecoveryModule xaRecoveryModule = new XARecoveryModule();
ExecutorService pool = Executors.newFixedThreadPool(1);
new Thread() {
public void run() {
xaRecoveryModule.periodicWorkFirstPass();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
xaRecoveryModule.periodicWorkSecondPass();
}
}.start();
Future<String> future = pool.submit(new Callable<String>() {
@Override
public String call() throws Exception {
final XAResourceRecoveryHelper xaResourceRecoveryHelper = new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[0];
}
};
return addHelper(xaRecoveryModule, xaResourceRecoveryHelper, 3);
}
});
String errMsg = future.get();
assertNull(errMsg, errMsg);
}
use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testXAResourceOrphanFilterRegistration.
@Test
public void testXAResourceOrphanFilterRegistration() {
XARecoveryModule xaRecoveryModule = new XARecoveryModule();
XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter();
xaRecoveryModule.addXAResourceOrphanFilter(xaResourceOrphanFilter);
xaRecoveryModule.removeXAResourceOrphanFilter(xaResourceOrphanFilter);
}
use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testFailures.
@Test
public void testFailures() throws Exception {
XARecoveryModule xarm = new XARecoveryModule();
Class[] parameterTypes = new Class[2];
Uid u = new Uid();
Xid x = new XidImple();
parameterTypes[0] = Xid.class;
parameterTypes[1] = Uid.class;
Method m = xarm.getClass().getDeclaredMethod("addFailure", parameterTypes);
m.setAccessible(true);
Object[] parameters = new Object[2];
parameters[0] = x;
parameters[1] = u;
m.invoke(xarm, parameters);
parameterTypes = new Class[1];
parameterTypes[0] = Xid.class;
parameters = new Object[1];
parameters[0] = x;
m = xarm.getClass().getDeclaredMethod("previousFailure", parameterTypes);
m.setAccessible(true);
Uid ret = (Uid) m.invoke(xarm, parameters);
assertEquals(ret, u);
parameterTypes = new Class[2];
parameterTypes[0] = Xid.class;
parameterTypes[1] = Uid.class;
parameters = new Object[2];
parameters[0] = x;
parameters[1] = u;
m = xarm.getClass().getDeclaredMethod("removeFailure", parameterTypes);
m.setAccessible(true);
m.invoke(xarm, parameters);
m = xarm.getClass().getDeclaredMethod("clearAllFailures", (Class[]) null);
m.setAccessible(true);
m.invoke(xarm, (Object[]) null);
}
Aggregations