Search in sources :

Example 6 with TransactionManager

use of org.springframework.transaction.TransactionManager in project spring-boot by spring-projects.

the class AbstractJpaAutoConfigurationTests method usesManuallyDefinedTransactionManagerBeanIfAvailable.

@Test
void usesManuallyDefinedTransactionManagerBeanIfAvailable() {
    this.contextRunner.withUserConfiguration(TestConfigurationWithTransactionManager.class).run((context) -> {
        assertThat(context).hasSingleBean(TransactionManager.class);
        TransactionManager txManager = context.getBean(TransactionManager.class);
        assertThat(txManager).isInstanceOf(CustomJpaTransactionManager.class);
    });
}
Also used : TransactionManager(org.springframework.transaction.TransactionManager) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 7 with TransactionManager

use of org.springframework.transaction.TransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierSeveralTimes.

@Test
public void determineTransactionManagerWithQualifierSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("fooTransactionManager");
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).containsBean("fooTransactionManager");
    verify(beanFactory, times(1)).getBean("fooTransactionManager", TransactionManager.class);
}
Also used : TransactionManager(org.springframework.transaction.TransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 8 with TransactionManager

use of org.springframework.transaction.TransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithBeanNameSeveralTimes.

@Test
public void determineTransactionManagerWithBeanNameSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("fooTransactionManager", beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).getBean("fooTransactionManager", TransactionManager.class);
}
Also used : TransactionManager(org.springframework.transaction.TransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionManager (org.springframework.transaction.TransactionManager)8 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)7 Test (org.junit.jupiter.api.Test)5 BeanFactory (org.springframework.beans.factory.BeanFactory)4 Method (java.lang.reflect.Method)2 ReactiveTransactionManager (org.springframework.transaction.ReactiveTransactionManager)2 CallbackPreferringPlatformTransactionManager (org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager)2 Try (io.vavr.control.Try)1 Properties (java.util.Properties)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Continuation (kotlin.coroutines.Continuation)1 AwaitKt (kotlinx.coroutines.reactive.AwaitKt)1 ReactiveFlowKt (kotlinx.coroutines.reactive.ReactiveFlowKt)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Publisher (org.reactivestreams.Publisher)1 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 BeanFactoryAnnotationUtils (org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils)1