use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent.
@Test
public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, MultiTxManagerConfig.class);
assertThat(ctx.getBeansOfType(TransactionManager.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 org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method txManagerIsResolvedOnInvocationOfTransactionalMethod.
@Test
public void txManagerIsResolvedOnInvocationOfTransactionalMethod() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(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();
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method txManagerIsResolvedCorrectlyWithSingleTxManagerBeanAndTxMgmtConfigurer.
@Test
public void txManagerIsResolvedCorrectlyWithSingleTxManagerBeanAndTxMgmtConfigurer() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, SingleTxManagerBeanAndTxMgmtConfigurerConfig.class);
assertThat(ctx.getBeansOfType(TransactionManager.class)).hasSize(1);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
SingleTxManagerBeanAndTxMgmtConfigurerConfig config = ctx.getBean(SingleTxManagerBeanAndTxMgmtConfigurerConfig.class);
CallCountingTransactionManager annotationDriven = config.annotationDriven;
// 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(annotationDriven.begun).isEqualTo(1);
assertThat(annotationDriven.commits).isEqualTo(1);
assertThat(annotationDriven.rollbacks).isEqualTo(0);
ctx.close();
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class ScheduledAndTransactionalAnnotationIntegrationTests method succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface.
@Test
void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigB.class);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(100);
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
assertThat(AopUtils.isJdkDynamicProxy(repository)).isTrue();
assertThat(repository.getInvocationCount()).isGreaterThan(0);
assertThat(txManager.commits).isGreaterThan(0);
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class ScheduledAndTransactionalAnnotationIntegrationTests method succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface.
@Test
void succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, SubclassProxyTxConfig.class, RepoConfigA.class);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(100);
MyRepository repository = ctx.getBean(MyRepository.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
assertThat(AopUtils.isCglibProxy(repository)).isTrue();
assertThat(repository.getInvocationCount()).isGreaterThan(0);
assertThat(txManager.commits).isGreaterThan(0);
}
Aggregations