use of com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple 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());
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple 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.jts.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());
}
Aggregations