use of org.jboss.tm.XAResourceWrapper in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testRecoverPassFailure.
@Test
public void testRecoverPassFailure() throws Exception {
int orphanSafetyInterval = jtaPropertyManager.getJTAEnvironmentBean().getOrphanSafetyInterval();
List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
jtaPropertyManager.getJTAEnvironmentBean().setOrphanSafetyInterval(0);
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(Arrays.asList(new String[] { NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES }));
XARecoveryModule xarm = new XARecoveryModule();
xarm.addXAResourceOrphanFilter(new JTANodeNameXAResourceOrphanFilter());
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
XAResource[] xares = new XAResource[] { new XAResourceWrapper() {
@Override
public XAResource getResource() {
return null;
}
@Override
public String getProductName() {
return null;
}
@Override
public String getProductVersion() {
return null;
}
@Override
public String getJndiName() {
return "test";
}
int count = 0;
Xid xid = new XidImple(new Uid());
@Override
public void commit(Xid xid, boolean b) throws XAException {
}
@Override
public void end(Xid xid, int i) throws XAException {
}
@Override
public void forget(Xid xid) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return false;
}
@Override
public int prepare(Xid xid) throws XAException {
return 0;
}
@Override
public Xid[] recover(int i) throws XAException {
count++;
if (count == 1 || count == 5) {
return new Xid[] { xid };
} else if (count > 5) {
return new Xid[0];
} else {
throw new XAException();
}
}
@Override
public void rollback(Xid xid) throws XAException {
if (count == 1) {
// This comes from the first end scan
throw new XAException(XAException.XA_RETRY);
}
rolledback = true;
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
return false;
}
@Override
public void start(Xid xid, int i) throws XAException {
}
} };
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return xares;
}
});
// The first two recovery cycles do nothing with the resource (because phase two is getting the exception)
// When count reaches 6 it sees that the xid has gone and presumes abort so calls rollback and hence assertTrue(rolledback) passes
// 1st pass: returns one xid (count is 1)
xarm.periodicWorkFirstPass();
// 2nd pass: throws an exception (count is 2)
xarm.periodicWorkSecondPass();
assertTrue(xarm.getContactedJndiNames().contains("test"));
assertFalse(rolledback);
// 1st pass: throws an exception (count is 3)
xarm.periodicWorkFirstPass();
// 2nd pass: throws an exception (count is 4)
xarm.periodicWorkSecondPass();
assertFalse(xarm.getContactedJndiNames().contains("test"));
assertFalse(rolledback);
// 1st pass: returns an empty list of xids (count is 5)
xarm.periodicWorkFirstPass();
// 2nd pass: returns an empty list of xids (count is 6)
xarm.periodicWorkSecondPass();
assertTrue(xarm.getContactedJndiNames().contains("test"));
assertTrue(rolledback);
jtaPropertyManager.getJTAEnvironmentBean().setOrphanSafetyInterval(orphanSafetyInterval);
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
}
use of org.jboss.tm.XAResourceWrapper in project narayana by jbosstm.
the class TestXAResourceRecordWrappingPlugin method transcribeWrapperData.
@Override
public void transcribeWrapperData(final XAResourceRecord xaResourceRecord) {
final XAResource xaResource = (XAResource) xaResourceRecord.value();
if (xaResource instanceof XAResourceWrapper) {
XAResourceWrapper xaResourceWrapper = (XAResourceWrapper) xaResource;
xaResourceRecord.setProductName(xaResourceWrapper.getProductName());
xaResourceRecord.setProductVersion(xaResourceWrapper.getProductVersion());
xaResourceRecord.setJndiName(xaResourceWrapper.getJndiName());
}
}
use of org.jboss.tm.XAResourceWrapper in project narayana by jbosstm.
the class XAResourceRecordWrappingPluginImpl method transcribeWrapperData.
public void transcribeWrapperData(XAResourceRecord record) {
XAResource xaResource = (XAResource) record.value();
if (xaResource instanceof XAResourceWrapper) {
XAResourceWrapper xaResourceWrapper = (XAResourceWrapper) xaResource;
record.setProductName(xaResourceWrapper.getProductName());
record.setProductVersion(xaResourceWrapper.getProductVersion());
record.setJndiName(xaResourceWrapper.getJndiName());
}
}
use of org.jboss.tm.XAResourceWrapper in project narayana by jbosstm.
the class XAResourceRecordWrappingPluginImpl method getEISName.
public Integer getEISName(XAResource xaResource) throws IOException, ObjectStoreException {
if (xaResource instanceof XAResourceWrapper) {
initialize();
String jndiName = ((XAResourceWrapper) xaResource).getJndiName();
Integer key = nameToKey.get(jndiName);
if (key == null) {
synchronized (this) {
// Recheck the resource, we do this so that we don't need to
// synchronize if this is a read
key = nameToKey.get(jndiName);
if (key == null) {
key = nextKey.getAndIncrement();
keyToName.put(key, jndiName);
nameToKey.put(jndiName, key);
OutputObjectState oos = new OutputObjectState();
oos.packString(nodeIdentifier);
oos.packInt(key);
oos.packString(jndiName);
eisNameStore.write_committed(new Uid(), "EISNAME", oos);
eisNameStore.sync();
}
}
}
return key;
} else {
return 0;
}
}
Aggregations