use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.
the class TransactionImpleUnitTest method testInvalid.
@Test
public void testInvalid() throws Exception {
ThreadActionData.purgeActions();
TxImpleOverride tx = new TxImpleOverride();
assertEquals(tx.hashCode(), -1);
assertEquals(tx.getStatus(), Status.STATUS_NO_TRANSACTION);
try {
tx.commit();
fail();
} catch (final IllegalStateException ex) {
}
try {
tx.rollback();
fail();
} catch (final IllegalStateException ex) {
}
try {
tx.setRollbackOnly();
fail();
} catch (final IllegalStateException ex) {
}
try {
tx.registerSynchronization(new Synchronization());
fail();
} catch (final IllegalStateException ex) {
}
tx.toString();
assertFalse(tx.isAlive());
}
use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.
the class SynchronizationUnitTest method testValid.
@Test
public void testValid() {
SynchronizationImple sync = new SynchronizationImple(new Synchronization());
assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
assertTrue(sync.beforeCompletion());
assertTrue(sync.afterCompletion(Status.STATUS_COMMITTED));
SynchronizationImple comp = new SynchronizationImple(new Synchronization());
assertTrue(comp.compareTo(sync) != 0);
assertTrue(sync.toString() != null);
}
use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.
the class TransactionSynchronizationRegistryTest method testTSR.
@Test
public void testTSR() throws Exception {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryImple();
assertNull(tsr.getTransactionKey());
assertEquals(tm.getStatus(), tsr.getTransactionStatus());
tm.begin();
assertNotNull(tsr.getTransactionKey());
assertEquals(tm.getStatus(), tsr.getTransactionStatus());
String key = "key";
Object value = new Object();
assertNull(tsr.getResource(key));
tsr.putResource(key, value);
assertEquals(value, tsr.getResource(key));
Synchronization synchronization = new com.hp.mwtests.ts.jta.common.Synchronization();
tsr.registerInterposedSynchronization(synchronization);
assertFalse(tsr.getRollbackOnly());
tsr.setRollbackOnly();
assertTrue(tsr.getRollbackOnly());
boolean gotExpectedException = false;
try {
tsr.registerInterposedSynchronization(synchronization);
} catch (IllegalStateException e) {
gotExpectedException = true;
}
assertTrue(gotExpectedException);
tm.rollback();
assertEquals(tm.getStatus(), tsr.getTransactionStatus());
}
use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.
the class TransactionSynchronizationRegistryTest method testTSRUseAfterCompletion.
@Test
public void testTSRUseAfterCompletion() throws Exception {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
final CompletionCountLock ccl = new CompletionCountLock(2);
tm.begin();
final TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryImple();
tsr.registerInterposedSynchronization(new Synchronization() {
@Override
public void afterCompletion(int status) {
String key = "key";
Object value = new Object();
try {
tsr.getResource(key);
ccl.incrementFailedCount();
} catch (IllegalStateException ise) {
// Expected
ccl.incrementCount();
}
try {
tsr.putResource(key, value);
ccl.incrementFailedCount();
} catch (IllegalStateException ise) {
// Expected
ccl.incrementCount();
}
}
@Override
public void beforeCompletion() {
// TODO Auto-generated method stub
}
});
tm.commit();
assertTrue(ccl.waitForCompletion());
}
Aggregations