use of cn.taketoday.transaction.CallCountingTransactionManager in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionAttributeSourceTests method serializable.
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor((PlatformTransactionManager) ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.class);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
assertThat(ptm.commits).isEqualTo(1);
ITestBean1 serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
assertThat(serializedPtm.commits).isEqualTo(2);
}
use of cn.taketoday.transaction.CallCountingTransactionManager in project today-infrastructure by TAKETODAY.
the class EnableTransactionManagementTests method spr14322FindsOnInterfaceWithInterfaceProxy.
@Test
public void spr14322FindsOnInterfaceWithInterfaceProxy() {
StandardApplicationContext ctx = new StandardApplicationContext(Spr14322ConfigA.class);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
bean.saveFoo();
bean.saveBar();
assertThat(txManager.begun).isEqualTo(2);
assertThat(txManager.commits).isEqualTo(2);
assertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
use of cn.taketoday.transaction.CallCountingTransactionManager in project today-infrastructure by TAKETODAY.
the class EnableTransactionManagementTests method txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent.
@Test
public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent() {
StandardApplicationContext ctx = new StandardApplicationContext(EnableTxConfig.class, MultiTxManagerConfig.class);
assertThat(ctx.getBeansOfType(PlatformTransactionManager.class)).hasSize(2);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager txManager = ctx.getBean("txManager", CallCountingTransactionManager.class);
CallCountingTransactionManager txManager2 = ctx.getBean("txManager2", CallCountingTransactionManager.class);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean.findAllFoos();
assertThat(txManager.begun).isEqualTo(0);
assertThat(txManager.commits).isEqualTo(0);
assertThat(txManager.rollbacks).isEqualTo(0);
assertThat(txManager2.begun).isEqualTo(1);
assertThat(txManager2.commits).isEqualTo(1);
assertThat(txManager2.rollbacks).isEqualTo(0);
ctx.close();
}
use of cn.taketoday.transaction.CallCountingTransactionManager in project today-infrastructure by TAKETODAY.
the class EnableTransactionManagementTests method spr14322FindsOnInterfaceWithCglibProxy.
@Test
public void spr14322FindsOnInterfaceWithCglibProxy() {
StandardApplicationContext ctx = new StandardApplicationContext(Spr14322ConfigB.class);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
bean.saveFoo();
bean.saveBar();
assertThat(txManager.begun).isEqualTo(2);
assertThat(txManager.commits).isEqualTo(2);
assertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
use of cn.taketoday.transaction.CallCountingTransactionManager in project today-infrastructure by TAKETODAY.
the class EnableTransactionManagementTests method txManagerIsResolvedOnInvocationOfTransactionalMethod.
@Test
public void txManagerIsResolvedOnInvocationOfTransactionalMethod() {
StandardApplicationContext ctx = new StandardApplicationContext(EnableTxConfig.class, TxManagerConfig.class);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager txManager = ctx.getBean("txManager", CallCountingTransactionManager.class);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean.findAllFoos();
assertThat(txManager.begun).isEqualTo(1);
assertThat(txManager.commits).isEqualTo(1);
assertThat(txManager.rollbacks).isEqualTo(0);
assertThat(txManager.lastDefinition.isReadOnly()).isTrue();
assertThat(txManager.lastDefinition.getTimeout()).isEqualTo(5);
assertThat(((TransactionAttribute) txManager.lastDefinition).getLabels()).contains("LABEL");
ctx.close();
}
Aggregations