use of org.springframework.tests.transaction.CallCountingTransactionManager in project spring-framework by spring-projects.
the class ScheduledAndTransactionalAnnotationIntegrationTests method succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface.
@Test
public 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("repository is not a proxy", AopUtils.isJdkDynamicProxy(repository), is(true));
assertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
assertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
use of org.springframework.tests.transaction.CallCountingTransactionManager in project spring-framework by spring-projects.
the class ScheduledAndTransactionalAnnotationIntegrationTests method succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface.
@Test
public 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("repository is not a proxy", AopUtils.isCglibProxy(repository), equalTo(true));
assertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
assertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
use of org.springframework.tests.transaction.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementIntegrationTests method implicitTxManager.
@Test
public void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImplicitTxManagerConfig.class);
ctx.refresh();
FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll();
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
assertThat(txManager.begun, equalTo(1));
assertThat(txManager.commits, equalTo(1));
assertThat(txManager.rollbacks, equalTo(0));
}
use of org.springframework.tests.transaction.CallCountingTransactionManager in project spring-framework by spring-projects.
the class Rollback method testProgrammaticRollback.
@Test
public void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
assertTrue(bean instanceof CallCountingTransactionManager);
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
Rollback rb = (Rollback) bf.getBean("rollback");
assertEquals(0, txMan.commits);
rb.rollbackOnly(false);
assertEquals("Transaction counts match", 1, txMan.commits);
assertEquals(0, txMan.rollbacks);
// Will cause rollback only
rb.rollbackOnly(true);
assertEquals(1, txMan.rollbacks);
}
use of org.springframework.tests.transaction.CallCountingTransactionManager in project spring-framework by spring-projects.
the class Rollback method testRollbackRulesOnMethodCauseRollback.
/**
* Should not roll back on servlet exception.
*/
@Test
public void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
assertEquals(0, txc.getCountingBeforeAdvice().getCalls());
assertEquals(0, txMan.commits);
rb.echoException(null);
// Fires only on setters
assertEquals(0, txc.getCountingBeforeAdvice().getCalls());
assertEquals("Transaction counts match", 1, txMan.commits);
assertEquals(0, txMan.rollbacks);
Exception ex = new Exception();
try {
rb.echoException(ex);
} catch (Exception actual) {
assertEquals(ex, actual);
}
assertEquals("Transaction counts match", 1, txMan.rollbacks);
}
Aggregations