use of org.springframework.transaction.interceptor.TransactionAspectSupport.TransactionInfo in project spring-framework by spring-projects.
the class AbstractTransactionAspectTests method enclosingTransactionWithNonTransactionMethodOnAdvisedInside.
@Test
public void enclosingTransactionWithNonTransactionMethodOnAdvisedInside() throws Throwable {
TransactionAttribute txatt = new DefaultTransactionAttribute();
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(exceptionalMethod, txatt);
TransactionStatus status = mock(TransactionStatus.class);
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
// Expect a transaction
given(ptm.getTransaction(txatt)).willReturn(status);
final String spouseName = "innerName";
TestBean outer = new TestBean() {
@Override
public void exceptional(Throwable t) throws Throwable {
TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo();
assertTrue(ti.hasTransaction());
assertEquals(spouseName, getSpouse().getName());
}
};
TestBean inner = new TestBean() {
@Override
public String getName() {
// Assert that we're in the inner proxy
TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo();
assertFalse(ti.hasTransaction());
return spouseName;
}
};
ITestBean outerProxy = (ITestBean) advised(outer, ptm, tas);
ITestBean innerProxy = (ITestBean) advised(inner, ptm, tas);
outer.setSpouse(innerProxy);
checkTransactionStatus(false);
// Will invoke inner.getName, which is non-transactional
outerProxy.exceptional(null);
checkTransactionStatus(false);
verify(ptm).commit(status);
}
use of org.springframework.transaction.interceptor.TransactionAspectSupport.TransactionInfo in project spring-framework by spring-projects.
the class AbstractTransactionAspectTests method enclosingTransactionWithNestedTransactionOnAdvisedInside.
@Test
public void enclosingTransactionWithNestedTransactionOnAdvisedInside() throws Throwable {
final TransactionAttribute outerTxatt = new DefaultTransactionAttribute();
final TransactionAttribute innerTxatt = new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_NESTED);
Method outerMethod = exceptionalMethod;
Method innerMethod = getNameMethod;
MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
tas.register(outerMethod, outerTxatt);
tas.register(innerMethod, innerTxatt);
TransactionStatus outerStatus = mock(TransactionStatus.class);
TransactionStatus innerStatus = mock(TransactionStatus.class);
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
// Expect a transaction
given(ptm.getTransaction(outerTxatt)).willReturn(outerStatus);
given(ptm.getTransaction(innerTxatt)).willReturn(innerStatus);
final String spouseName = "innerName";
TestBean outer = new TestBean() {
@Override
public void exceptional(Throwable t) throws Throwable {
TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo();
assertTrue(ti.hasTransaction());
assertEquals(outerTxatt, ti.getTransactionAttribute());
assertEquals(spouseName, getSpouse().getName());
}
};
TestBean inner = new TestBean() {
@Override
public String getName() {
// Assert that we're in the inner proxy
TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo();
// Has nested transaction
assertTrue(ti.hasTransaction());
assertEquals(innerTxatt, ti.getTransactionAttribute());
return spouseName;
}
};
ITestBean outerProxy = (ITestBean) advised(outer, ptm, tas);
ITestBean innerProxy = (ITestBean) advised(inner, ptm, tas);
outer.setSpouse(innerProxy);
checkTransactionStatus(false);
// Will invoke inner.getName, which is non-transactional
outerProxy.exceptional(null);
checkTransactionStatus(false);
verify(ptm).commit(innerStatus);
verify(ptm).commit(outerStatus);
}
Aggregations