use of org.osgi.service.transaction.control.TransactionStatus in project aries by apache.
the class TransactionContextImpl method postCompletion.
@Override
public void postCompletion(Consumer<TransactionStatus> job) throws IllegalStateException {
TransactionStatus status = tranStatus.get();
if (status == COMMITTED || status == ROLLED_BACK) {
throw new IllegalStateException("The current transaction is in state " + tranStatus);
}
postCompletion.add(job);
}
use of org.osgi.service.transaction.control.TransactionStatus in project aries by apache.
the class TransactionControlRunningTest method testTwoRequiredsNestedOuterThrowsException.
@Test
public void testTwoRequiredsNestedOuterThrowsException() {
AtomicReference<TransactionStatus> finalStatusOuter = new AtomicReference<>();
AtomicReference<TransactionStatus> finalStatusInner = new AtomicReference<>();
Exception userEx = new Exception("Bang!");
try {
txControl.required(() -> {
assertTrue(txControl.activeTransaction());
Object key = txControl.getCurrentContext().getTransactionKey();
txControl.getCurrentContext().postCompletion(finalStatusOuter::set);
txControl.setRollbackOnly();
txControl.requiresNew(() -> {
assertFalse(key.equals(txControl.getCurrentContext().getTransactionKey()));
txControl.getCurrentContext().postCompletion(finalStatusInner::set);
return null;
});
throw userEx;
});
fail("Should not be reached");
} catch (ScopedWorkException swe) {
assertSame(userEx, swe.getCause());
}
assertEquals(ROLLED_BACK, finalStatusOuter.get());
assertEquals(COMMITTED, finalStatusInner.get());
}
use of org.osgi.service.transaction.control.TransactionStatus in project aries by apache.
the class TransactionControlRunningTest method testRequiredUserException.
@Test
public void testRequiredUserException() {
AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>();
Exception userEx = new Exception("Bang!");
try {
txControl.required(() -> {
assertTrue(txControl.activeTransaction());
txControl.getCurrentContext().postCompletion(finalStatus::set);
throw userEx;
});
fail("Should not be reached");
} catch (ScopedWorkException swe) {
assertSame(userEx, swe.getCause());
}
assertEquals(ROLLED_BACK, finalStatus.get());
}
use of org.osgi.service.transaction.control.TransactionStatus in project aries by apache.
the class TransactionControlRunningTest method testTwoRequiredsNestedOuterThrowsException.
@Test
public void testTwoRequiredsNestedOuterThrowsException() {
AtomicReference<TransactionStatus> finalStatusOuter = new AtomicReference<>();
AtomicReference<TransactionStatus> finalStatusInner = new AtomicReference<>();
Exception userEx = new Exception("Bang!");
try {
txControl.required(() -> {
assertTrue(txControl.activeTransaction());
Object key = txControl.getCurrentContext().getTransactionKey();
txControl.getCurrentContext().postCompletion(finalStatusOuter::set);
txControl.setRollbackOnly();
txControl.requiresNew(() -> {
assertFalse(key.equals(txControl.getCurrentContext().getTransactionKey()));
txControl.getCurrentContext().postCompletion(finalStatusInner::set);
return null;
});
throw userEx;
});
fail("Should not be reached");
} catch (ScopedWorkException swe) {
assertSame(userEx, swe.getCause());
}
assertEquals(ROLLED_BACK, finalStatusOuter.get());
assertEquals(COMMITTED, finalStatusInner.get());
}
use of org.osgi.service.transaction.control.TransactionStatus in project aries by apache.
the class TransactionControlRunningTest method testRequiredNoRollbackException.
@Test
public void testRequiredNoRollbackException() {
AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>();
Exception userEx = new BindException("Bang!");
try {
txControl.build().noRollbackFor(BindException.class).required(() -> {
assertTrue(txControl.activeTransaction());
txControl.getCurrentContext().postCompletion(finalStatus::set);
throw userEx;
});
fail("Should not be reached");
} catch (ScopedWorkException swe) {
assertSame(userEx, swe.getCause());
}
assertEquals(COMMITTED, finalStatus.get());
}
Aggregations