use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.
the class XAResourceRecordUnitTest method test.
@Test
public void test() throws Exception {
XAResourceRecord xares = new XAResourceRecord();
Object obj = new Object();
xares.setValue(obj);
assertTrue(xares.value() != obj);
DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
Object[] params = new Object[1];
params[XAResourceRecord.XACONNECTION] = rc;
xares = new XAResourceRecord(new TransactionImple(0), new DummyXA(false), new XidImple(new Uid()), params);
assertTrue(xares.type() != null);
xares.merge(xares);
xares.replace(xares);
assertTrue(xares.toString() != null);
}
use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.
the class XARecoveryResourceUnitTest method testRecoveryResource.
@Test
public void testRecoveryResource() {
XARecoveryResourceImple res = new XARecoveryResourceImple(new Uid());
assertEquals(res.getXAResource(), null);
assertEquals(res.recoverable(), XARecoveryResource.INCOMPLETE_STATE);
res = new XARecoveryResourceImple(new Uid(), new DummyXA(false));
assertEquals(res.recoverable(), XARecoveryResource.RECOVERY_REQUIRED);
assertEquals(res.recover(), XARecoveryResource.WAITING_FOR_RECOVERY);
}
use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.
the class TransactionImpleUnitTest method testEnlist.
@Test
public void testEnlist() throws Exception {
ThreadActionData.purgeActions();
TransactionImple tx = new TransactionImple(0);
tx.setRollbackOnly();
try {
tx.enlistResource(null);
fail();
} catch (final SystemException ex) {
}
try {
tx.enlistResource(new DummyXA(false));
fail();
} catch (final RollbackException ex) {
}
try {
tx.commit();
fail();
} catch (final RollbackException ex) {
}
try {
tx.enlistResource(new DummyXA(false));
fail();
} catch (final IllegalStateException ex) {
}
}
use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.
the class TransactionImpleUnitTest method testXidCreation.
@Test
public void testXidCreation() throws Exception {
ThreadActionData.purgeActions();
Class[] parameterTypes = new Class[3];
TransactionImple tx = new TransactionImple(0);
parameterTypes[0] = boolean.class;
parameterTypes[1] = XAModifier.class;
parameterTypes[2] = XAResource.class;
Method m = tx.getClass().getDeclaredMethod("createXid", parameterTypes);
m.setAccessible(true);
Object[] parameters = new Object[3];
parameters[0] = false;
parameters[1] = new DummyXAModifier();
parameters[2] = new DummyXA(false);
Xid res = (Xid) m.invoke(tx, parameters);
assertTrue(res != null);
tx.rollback();
}
use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.
the class SynchronizationUnitTest method testSynchronizationFailure.
@Test
public void testSynchronizationFailure() throws Exception {
TransactionImple tx = new TransactionImple(0);
DummyXA res = new DummyXA(false) {
public void rollback(Xid xid) throws XAException {
super.rollback(xid);
throw new XAException(XAException.XA_RETRY);
}
};
tx.enlistResource(res);
final String exceptionError = "intentional testing exception";
tx.registerSynchronization(new javax.transaction.Synchronization() {
@Override
public void beforeCompletion() {
throw new RuntimeException(exceptionError);
}
@Override
public void afterCompletion(int status) {
}
});
try {
tx.commit();
} catch (Exception e) {
Throwable exceptionToCheck = e;
while (exceptionToCheck != null) {
if (exceptionToCheck.getMessage().equals(exceptionError))
return;
exceptionToCheck = exceptionToCheck.getCause();
}
throw e;
}
}
Aggregations