use of cn.taketoday.transaction.interceptor.TransactionInterceptor in project today-infrastructure by TAKETODAY.
the class ProxyTransactionManagementConfiguration method transactionInterceptor.
@Component
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionInterceptor transactionInterceptor(TransactionAttributeSource transactionAttributeSource) {
TransactionInterceptor interceptor = new TransactionInterceptor();
interceptor.setTransactionAttributeSource(transactionAttributeSource);
if (this.txManager != null) {
interceptor.setTransactionManager(this.txManager);
}
return interceptor;
}
use of cn.taketoday.transaction.interceptor.TransactionInterceptor 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.interceptor.TransactionInterceptor in project today-framework by TAKETODAY.
the class AnnotationTransactionInterceptorTests method withMonoRollback.
@Test
public void withMonoRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
StepVerifier.withVirtualTime(proxy::monoSuccess).thenAwait(Duration.ofSeconds(1)).thenCancel().verify();
assertReactiveGetTransactionAndRollbackCount(1);
}
use of cn.taketoday.transaction.interceptor.TransactionInterceptor in project today-framework by TAKETODAY.
the class AnnotationTransactionInterceptorTests method withMonoSuccess.
@Test
public void withMonoSuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
StepVerifier.withVirtualTime(proxy::monoSuccess).thenAwait(Duration.ofSeconds(10)).verifyComplete();
assertReactiveGetTransactionAndCommitCount(1);
}
use of cn.taketoday.transaction.interceptor.TransactionInterceptor in project today-framework by TAKETODAY.
the class AnnotationTransactionInterceptorTests method withMonoFailure.
@Test
public void withMonoFailure() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithReactive());
proxyFactory.addAdvice(new TransactionInterceptor(rtm, this.source));
TestWithReactive proxy = (TestWithReactive) proxyFactory.getProxy();
proxy.monoFailure().as(StepVerifier::create).verifyError();
assertReactiveGetTransactionAndRollbackCount(1);
}
Aggregations