Here are the examples of the java api org.springframework.tests.transaction.CallCountingTransactionManager taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
54 Examples
19
View Source File : EnableTransactionManagementIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImplicitTxManagerConfig.clreplaced);
ctx.refresh();
FooRepository fooRepository = ctx.getBean(FooRepository.clreplaced);
fooRepository.findAll();
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
replacedertThat(txManager.begun, equalTo(1));
replacedertThat(txManager.commits, equalTo(1));
replacedertThat(txManager.rollbacks, equalTo(0));
}
19
View Source File : ScheduledAndTransactionalAnnotationIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.clreplaced, JdkProxyTxConfig.clreplaced, RepoConfigB.clreplaced);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(100);
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
replacedertThat("repository is not a proxy", AopUtils.isJdkDynamicProxy(repository), is(true));
replacedertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
replacedertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
19
View Source File : ScheduledAndTransactionalAnnotationIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void succeedsWhenSubclreplacedProxyAndScheduledMethodNotPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.clreplaced, SubclreplacedProxyTxConfig.clreplaced, RepoConfigA.clreplaced);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(100);
MyRepository repository = ctx.getBean(MyRepository.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
replacedertThat("repository is not a proxy", AopUtils.isCglibProxy(repository), equalTo(true));
replacedertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
replacedertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
19
View Source File : AdvisorAutoProxyCreatorIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testTransactionAttributeOnMethod() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
replacedertEquals(0, txc.getCountingBeforeAdvice().getCalls());
replacedertEquals(0, txMan.commits);
replacedertEquals("Initial value was correct", 4, test.getAge());
int newAge = 5;
test.setAge(newAge);
replacedertEquals(1, txc.getCountingBeforeAdvice().getCalls());
replacedertEquals("New value set correctly", newAge, test.getAge());
replacedertEquals("Transaction counts match", 1, txMan.commits);
}
19
View Source File : AdvisorAutoProxyCreatorIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testRollbackRulesOnMethodPreventRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
replacedertEquals(0, txMan.commits);
// Should NOT roll back on ServletException
try {
rb.echoException(new ServletException());
} catch (ServletException ex) {
}
replacedertEquals("Transaction counts match", 1, txMan.commits);
}
19
View Source File : AdvisorAutoProxyCreatorIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* 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");
replacedertEquals(0, txc.getCountingBeforeAdvice().getCalls());
replacedertEquals(0, txMan.commits);
rb.echoException(null);
// Fires only on setters
replacedertEquals(0, txc.getCountingBeforeAdvice().getCalls());
replacedertEquals("Transaction counts match", 1, txMan.commits);
replacedertEquals(0, txMan.rollbacks);
Exception ex = new Exception();
try {
rb.echoException(ex);
} catch (Exception actual) {
replacedertEquals(ex, actual);
}
replacedertEquals("Transaction counts match", 1, txMan.rollbacks);
}
19
View Source File : BeanFactoryTransactionTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Test that we can set the target to a dynamic TargetSource.
*/
@Test
public void testDynamicTargetSource() {
// Install facade
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = txMan;
TestBean tb = (TestBean) factory.getBean("hotSwapped");
replacedertEquals(666, tb.getAge());
int newAge = 557;
tb.setAge(newAge);
replacedertEquals(newAge, tb.getAge());
TestBean target2 = new TestBean();
target2.setAge(65);
HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
ts.swap(target2);
replacedertEquals(target2.getAge(), tb.getAge());
tb.setAge(newAge);
replacedertEquals(newAge, target2.getAge());
replacedertEquals(0, txMan.inflight);
replacedertEquals(2, txMan.commits);
replacedertEquals(0, txMan.rollbacks);
}
19
View Source File : EnableTransactionManagementTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void spr14322FindsOnInterfaceWithCglibProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.clreplaced);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
bean.saveFoo();
bean.saveBar();
replacedertThat(txManager.begun, equalTo(2));
replacedertThat(txManager.commits, equalTo(2));
replacedertThat(txManager.rollbacks, equalTo(0));
ctx.close();
}
19
View Source File : EnableTransactionManagementTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void spr14322FindsOnInterfaceWithInterfaceProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.clreplaced);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
bean.saveFoo();
bean.saveBar();
replacedertThat(txManager.begun, equalTo(2));
replacedertThat(txManager.commits, equalTo(2));
replacedertThat(txManager.rollbacks, equalTo(0));
ctx.close();
}
19
View Source File : EnableTransactionManagementTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void spr11915TransactionManagerAsManualSingleton() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.clreplaced);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.clreplaced);
bean.saveQualifiedFoo();
replacedertThat(txManager.begun, equalTo(1));
replacedertThat(txManager.commits, equalTo(1));
replacedertThat(txManager.rollbacks, equalTo(0));
bean.saveQualifiedFooWithAttributeAlias();
replacedertThat(txManager.begun, equalTo(2));
replacedertThat(txManager.commits, equalTo(2));
replacedertThat(txManager.rollbacks, equalTo(0));
ctx.close();
}
19
View Source File : AnnotationTransactionNamespaceHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void nonPublicMethodsNotAdvised() {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
replacedertEquals("Should not have any started transactions", 0, ptm.begun);
testBean.annotationsOnProtectedAreIgnored();
replacedertEquals("Should not have any started transactions", 0, ptm.begun);
}
19
View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public clreplaced AnnotationTransactionInterceptorTests {
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource();
private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source);
@Test
public void clreplacedLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClreplacedLevelOnly());
proxyFactory.addAdvice(this.ti);
TestClreplacedLevelOnly proxy = (TestClreplacedLevelOnly) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverride proxy = (TestWithSingleMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withRollbackOnRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
try {
proxy.doSomethingErroneous();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ex) {
replacedertGetTransactionAndRollbackCount(1);
}
try {
proxy.doSomethingElseErroneous();
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
replacedertGetTransactionAndRollbackCount(2);
}
}
@Test
public void withCommitOnCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
try {
proxy.doSomethingElseWithCheckedException();
fail("Should throw Exception");
} catch (Exception ex) {
replacedertGetTransactionAndCommitCount(1);
}
}
@Test
public void withRollbackOnCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
try {
proxy.doSomethingElseWithCheckedExceptionAndRollbackRule();
fail("Should throw Exception");
} catch (Exception ex) {
replacedertGetTransactionAndRollbackCount(1);
}
}
@Test
public void withVavrTrySuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withVavrTryRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneous();
replacedertGetTransactionAndRollbackCount(1);
}
@Test
public void withVavrTryCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneousWithCheckedException();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withVavrTryCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneousWithCheckedExceptionAndRollbackRule();
replacedertGetTransactionAndRollbackCount(1);
}
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void crossClreplacedInterfaceMethodLevelOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.clreplaced);
proxyFactory.addAdvice(this.ti);
SomeService someService = (SomeService) proxyFactory.getProxy();
someService.bar();
replacedertGetTransactionAndCommitCount(1);
someService.foo();
replacedertGetTransactionAndCommitCount(2);
someService.fooBar();
replacedertGetTransactionAndCommitCount(3);
}
@Test
public void crossClreplacedInterfaceOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.clreplaced);
proxyFactory.addAdvice(this.ti);
OtherService otherService = (OtherService) proxyFactory.getProxy();
otherService.foo();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withInterfaceOnTargetJdkProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.addInterface(TestWithInterface.clreplaced);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void withInterfaceOnTargetCglibProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.setProxyTargetClreplaced(true);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
private void replacedertGetTransactionAndCommitCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.commits);
}
private void replacedertGetTransactionAndRollbackCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.rollbacks);
}
@Transactional
public static clreplaced TestClreplacedLevelOnly {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithSingleMethodOverride {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional(readOnly = true)
public static clreplaced TestWithSingleMethodOverrideInverted {
@Transactional
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithMultiMethodOverride {
@Transactional(readOnly = true)
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithExceptions {
public void doSomethingErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalStateException();
}
public void doSomethingElseErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalArgumentException();
}
@Transactional
public void doSomethingElseWithCheckedException() throws Exception {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new Exception();
}
@Transactional(rollbackFor = Exception.clreplaced)
public void doSomethingElseWithCheckedExceptionAndRollbackRule() throws Exception {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new Exception();
}
}
@Transactional
public static clreplaced TestWithVavrTry {
public Try<String> doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return Try.success("ok");
}
public Try<String> doSomethingErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return Try.failure(new IllegalStateException());
}
public Try<String> doSomethingErroneousWithCheckedException() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return Try.failure(new Exception());
}
@Transactional(rollbackFor = Exception.clreplaced)
public Try<String> doSomethingErroneousWithCheckedExceptionAndRollbackRule() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return Try.failure(new Exception());
}
}
public interface BaseInterface {
void doSomething();
}
@Transactional
public interface TestWithInterface extends BaseInterface {
@Transactional(readOnly = true)
void doSomethingElse();
default void doSomethingDefault() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
public static clreplaced TestWithInterfaceImpl implements TestWithInterface {
@Override
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Override
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
public interface SomeService {
void foo();
@Transactional
void bar();
@Transactional(readOnly = true)
void fooBar();
}
public static clreplaced SomeServiceImpl implements SomeService {
@Override
public void bar() {
}
@Override
@Transactional
public void foo() {
}
@Override
@Transactional(readOnly = false)
public void fooBar() {
}
}
public interface OtherService {
void foo();
}
@Transactional
public static clreplaced OtherServiceImpl implements OtherService {
@Override
public void foo() {
}
}
}
19
View Source File : LookUpTxMgrByTypeAndQualifierAtMethodLevelTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced LookUpTxMgrByTypeAndQualifierAtMethodLevelTests {
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager();
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager txManager1() {
return txManager1;
}
@Bean
public PlatformTransactionManager txManager2() {
return txManager2;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager1.clear();
txManager2.clear();
}
@Transactional("txManager1")
@Test
public void transactionalTest() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(1, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(0, txManager1.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(0, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(1, txManager1.rollbacks);
}
}
19
View Source File : LookUpTxMgrByTypeAndQualifierAtClassLevelTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@Transactional("txManager1")
public clreplaced LookUpTxMgrByTypeAndQualifierAtClreplacedLevelTests {
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager();
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager txManager1() {
return txManager1;
}
@Bean
public PlatformTransactionManager txManager2() {
return txManager2;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager1.clear();
txManager2.clear();
}
@Test
public void transactionalTest() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(1, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(0, txManager1.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(0, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(1, txManager1.rollbacks);
}
}
19
View Source File : LookUpTxMgrByTypeAndNameTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@Transactional("txManager1")
public clreplaced LookUpTxMgrByTypeAndNameTests {
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager();
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager txManager1() {
return txManager1;
}
@Bean
public PlatformTransactionManager txManager2() {
return txManager2;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager1.clear();
txManager2.clear();
}
@Test
public void transactionalTest() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(1, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(0, txManager1.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(0, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(1, txManager1.rollbacks);
}
}
19
View Source File : LookUpNonexistentTxMgrTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
public clreplaced LookUpNonexistentTxMgrTests {
private static final CallCountingTransactionManager txManager = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager transactionManager() {
return txManager;
}
}
@Test
public void nonTransactionalTest() {
replacedertEquals(0, txManager.begun);
replacedertEquals(0, txManager.inflight);
replacedertEquals(0, txManager.commits);
replacedertEquals(0, txManager.rollbacks);
}
}
19
View Source File : TransactionAspectTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* @author Rod Johnson
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Sam Brannen
*/
public clreplaced TransactionAspectTests {
private final CallCountingTransactionManager txManager = new CallCountingTransactionManager();
private final TransactionalAnnotationOnlyOnClreplacedWithNoInterface annotationOnlyOnClreplacedWithNoInterface = new TransactionalAnnotationOnlyOnClreplacedWithNoInterface();
private final ClreplacedWithProtectedAnnotatedMember beanWithAnnotatedProtectedMethod = new ClreplacedWithProtectedAnnotatedMember();
private final ClreplacedWithPrivateAnnotatedMember beanWithAnnotatedPrivateMethod = new ClreplacedWithPrivateAnnotatedMember();
private final MethodAnnotationOnClreplacedWithNoInterface methodAnnotationOnly = new MethodAnnotationOnClreplacedWithNoInterface();
@Before
public void initContext() {
AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager);
}
@Test
public void testCommitOnAnnotatedClreplaced() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.echo(null);
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnAnnotatedProtectedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedProtectedMethod.doInTransaction();
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnAnnotatedPrivateMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedPrivateMethod.doSomething();
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnNonAnnotatedNonPublicMethodInTransactionalType() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.nonTransactionalMethod();
replacedertEquals(0, txManager.begun);
}
@Test
public void commitOnAnnotatedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
methodAnnotationOnly.echo(null);
replacedertEquals(1, txManager.commits);
}
@Test
public void notTransactional() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
new NotTransactional().noop();
replacedertEquals(0, txManager.begun);
}
@Test
public void defaultCommitOnAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> annotationOnlyOnClreplacedWithNoInterface.echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultRollbackOnAnnotatedClreplaced() throws Throwable {
final RuntimeException ex = new RuntimeException();
try {
testRollback(() -> annotationOnlyOnClreplacedWithNoInterface.echo(ex), true);
fail("Should have thrown RuntimeException");
} catch (RuntimeException ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultCommitOnSubclreplacedOfAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> new SubclreplacedOfClreplacedWithTransactionalAnnotation().echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultCommitOnSubclreplacedOfClreplacedWithTransactionalMethodAnnotated() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> new SubclreplacedOfClreplacedWithTransactionalMethodAnnotation().echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void noCommitOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception ex = new Exception();
testNotTransactional(() -> new ImplementsAnnotatedInterface().echo(ex), ex);
}
@Test
public void noRollbackOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception rollbackProvokingException = new RuntimeException();
testNotTransactional(() -> new ImplementsAnnotatedInterface().echo(rollbackProvokingException), rollbackProvokingException);
}
protected void testRollback(TransactionOperationCallback toc, boolean rollback) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} finally {
replacedertEquals(1, txManager.begun);
replacedertEquals(rollback ? 0 : 1, txManager.commits);
replacedertEquals(rollback ? 1 : 0, txManager.rollbacks);
}
}
protected void testNotTransactional(TransactionOperationCallback toc, Throwable expected) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} catch (Throwable ex) {
if (expected == null) {
fail("Expected " + expected);
}
replacedertSame(expected, ex);
} finally {
replacedertEquals(0, txManager.begun);
}
}
private interface TransactionOperationCallback {
Object performTransactionalOperation() throws Throwable;
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalAnnotation extends TransactionalAnnotationOnlyOnClreplacedWithNoInterface {
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalMethodAnnotation extends MethodAnnotationOnClreplacedWithNoInterface {
}
public static clreplaced ImplementsAnnotatedInterface implements ITransactional {
@Override
public Object echo(Throwable t) throws Throwable {
if (t != null) {
throw t;
}
return t;
}
}
public static clreplaced NotTransactional {
public void noop() {
}
}
}
19
View Source File : BeanFactoryTransactionTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
/**
* Test that we can set the target to a dynamic TargetSource.
*/
@Test
public void testDynamicTargetSource() {
// Install facade
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = txMan;
TestBean tb = (TestBean) factory.getBean("hotSwapped");
replacedertThat(tb.getAge()).isEqualTo(666);
int newAge = 557;
tb.setAge(newAge);
replacedertThat(tb.getAge()).isEqualTo(newAge);
TestBean target2 = new TestBean();
target2.setAge(65);
HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
ts.swap(target2);
replacedertThat(tb.getAge()).isEqualTo(target2.getAge());
tb.setAge(newAge);
replacedertThat(target2.getAge()).isEqualTo(newAge);
replacedertThat(txMan.inflight).isEqualTo(0);
replacedertThat(txMan.commits).isEqualTo(2);
replacedertThat(txMan.rollbacks).isEqualTo(0);
}
19
View Source File : EnableTransactionManagementTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void spr14322FindsOnInterfaceWithInterfaceProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.clreplaced);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
bean.saveFoo();
bean.saveBar();
replacedertThat(txManager.begun).isEqualTo(2);
replacedertThat(txManager.commits).isEqualTo(2);
replacedertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
19
View Source File : EnableTransactionManagementTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void spr11915TransactionManagerAsManualSingleton() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.clreplaced);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.clreplaced);
bean.saveQualifiedFoo();
replacedertThat(txManager.begun).isEqualTo(1);
replacedertThat(txManager.commits).isEqualTo(1);
replacedertThat(txManager.rollbacks).isEqualTo(0);
bean.saveQualifiedFooWithAttributeAlias();
replacedertThat(txManager.begun).isEqualTo(2);
replacedertThat(txManager.commits).isEqualTo(2);
replacedertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
19
View Source File : EnableTransactionManagementTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void spr14322FindsOnInterfaceWithCglibProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.clreplaced);
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
bean.saveFoo();
bean.saveBar();
replacedertThat(txManager.begun).isEqualTo(2);
replacedertThat(txManager.commits).isEqualTo(2);
replacedertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
19
View Source File : AnnotationTransactionNamespaceHandlerTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void nonPublicMethodsNotAdvised() {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
replacedertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
testBean.annotationsOnProtectedAreIgnored();
replacedertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
}
19
View Source File : AnnotationTransactionInterceptorTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public clreplaced AnnotationTransactionInterceptorTests {
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource();
private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source);
@Test
public void clreplacedLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClreplacedLevelOnly());
proxyFactory.addAdvice(this.ti);
TestClreplacedLevelOnly proxy = (TestClreplacedLevelOnly) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverride proxy = (TestWithSingleMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withRollbackOnRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
replacedertThatIllegalStateException().isThrownBy(proxy::doSomethingErroneous).satisfies(ex -> replacedertGetTransactionAndRollbackCount(1));
replacedertThatIllegalArgumentException().isThrownBy(proxy::doSomethingElseErroneous).satisfies(ex -> replacedertGetTransactionAndRollbackCount(2));
}
@Test
public void withCommitOnCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
replacedertThatExceptionOfType(Exception.clreplaced).isThrownBy(proxy::doSomethingElseWithCheckedException).satisfies(ex -> replacedertGetTransactionAndCommitCount(1));
}
@Test
public void withRollbackOnCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithExceptions());
proxyFactory.addAdvice(this.ti);
TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
replacedertThatExceptionOfType(Exception.clreplaced).isThrownBy(proxy::doSomethingElseWithCheckedExceptionAndRollbackRule).satisfies(ex -> replacedertGetTransactionAndRollbackCount(1));
}
@Test
public void withVavrTrySuccess() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withVavrTryRuntimeException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneous();
replacedertGetTransactionAndRollbackCount(1);
}
@Test
public void withVavrTryCheckedException() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneousWithCheckedException();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withVavrTryCheckedExceptionAndRollbackRule() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithVavrTry());
proxyFactory.addAdvice(this.ti);
TestWithVavrTry proxy = (TestWithVavrTry) proxyFactory.getProxy();
proxy.doSomethingErroneousWithCheckedExceptionAndRollbackRule();
replacedertGetTransactionAndRollbackCount(1);
}
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void crossClreplacedInterfaceMethodLevelOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.clreplaced);
proxyFactory.addAdvice(this.ti);
SomeService someService = (SomeService) proxyFactory.getProxy();
someService.bar();
replacedertGetTransactionAndCommitCount(1);
someService.foo();
replacedertGetTransactionAndCommitCount(2);
someService.fooBar();
replacedertGetTransactionAndCommitCount(3);
}
@Test
public void crossClreplacedInterfaceOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.clreplaced);
proxyFactory.addAdvice(this.ti);
OtherService otherService = (OtherService) proxyFactory.getProxy();
otherService.foo();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withInterfaceOnTargetJdkProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.addInterface(TestWithInterface.clreplaced);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void withInterfaceOnTargetCglibProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.setProxyTargetClreplaced(true);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
private void replacedertGetTransactionAndCommitCount(int expectedCount) {
replacedertThat(this.ptm.begun).isEqualTo(expectedCount);
replacedertThat(this.ptm.commits).isEqualTo(expectedCount);
}
private void replacedertGetTransactionAndRollbackCount(int expectedCount) {
replacedertThat(this.ptm.begun).isEqualTo(expectedCount);
replacedertThat(this.ptm.rollbacks).isEqualTo(expectedCount);
}
@Transactional
public static clreplaced TestClreplacedLevelOnly {
public void doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
public void doSomethingElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
}
@Transactional
public static clreplaced TestWithSingleMethodOverride {
public void doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
public void doSomethingCompletelyElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
}
@Transactional(readOnly = true)
public static clreplaced TestWithSingleMethodOverrideInverted {
@Transactional
public void doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
public void doSomethingElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
public void doSomethingCompletelyElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
}
@Transactional
public static clreplaced TestWithMultiMethodOverride {
@Transactional(readOnly = true)
public void doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
public void doSomethingCompletelyElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
}
@Transactional
public static clreplaced TestWithExceptions {
public void doSomethingErroneous() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
throw new IllegalStateException();
}
public void doSomethingElseErroneous() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
throw new IllegalArgumentException();
}
@Transactional
public void doSomethingElseWithCheckedException() throws Exception {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
throw new Exception();
}
@Transactional(rollbackFor = Exception.clreplaced)
public void doSomethingElseWithCheckedExceptionAndRollbackRule() throws Exception {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
throw new Exception();
}
}
@Transactional
public static clreplaced TestWithVavrTry {
public Try<String> doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
return Try.success("ok");
}
public Try<String> doSomethingErroneous() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
return Try.failure(new IllegalStateException());
}
public Try<String> doSomethingErroneousWithCheckedException() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
return Try.failure(new Exception());
}
@Transactional(rollbackFor = Exception.clreplaced)
public Try<String> doSomethingErroneousWithCheckedExceptionAndRollbackRule() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
return Try.failure(new Exception());
}
}
public interface BaseInterface {
void doSomething();
}
@Transactional
public interface TestWithInterface extends BaseInterface {
@Transactional(readOnly = true)
void doSomethingElse();
default void doSomethingDefault() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
}
public static clreplaced TestWithInterfaceImpl implements TestWithInterface {
@Override
public void doSomething() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
}
@Override
public void doSomethingElse() {
replacedertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue();
replacedertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isTrue();
}
}
public interface SomeService {
void foo();
@Transactional
void bar();
@Transactional(readOnly = true)
void fooBar();
}
public static clreplaced SomeServiceImpl implements SomeService {
@Override
public void bar() {
}
@Override
@Transactional
public void foo() {
}
@Override
@Transactional(readOnly = false)
public void fooBar() {
}
}
public interface OtherService {
void foo();
}
@Transactional
public static clreplaced OtherServiceImpl implements OtherService {
@Override
public void foo() {
}
}
}
19
View Source File : AnnotationTransactionInterceptorTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public clreplaced AnnotationTransactionInterceptorTests {
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource();
private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source);
@Test
public void clreplacedLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClreplacedLevelOnly());
proxyFactory.addAdvice(this.ti);
TestClreplacedLevelOnly proxy = (TestClreplacedLevelOnly) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverride proxy = (TestWithSingleMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithRollback());
proxyFactory.addAdvice(this.ti);
TestWithRollback proxy = (TestWithRollback) proxyFactory.getProxy();
try {
proxy.doSomethingErroneous();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ex) {
replacedertGetTransactionAndRollbackCount(1);
}
try {
proxy.doSomethingElseErroneous();
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
replacedertGetTransactionAndRollbackCount(2);
}
}
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void crossClreplacedInterfaceMethodLevelOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.clreplaced);
proxyFactory.addAdvice(this.ti);
SomeService someService = (SomeService) proxyFactory.getProxy();
someService.bar();
replacedertGetTransactionAndCommitCount(1);
someService.foo();
replacedertGetTransactionAndCommitCount(2);
someService.fooBar();
replacedertGetTransactionAndCommitCount(3);
}
@Test
public void crossClreplacedInterfaceOnJdkProxy() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.clreplaced);
proxyFactory.addAdvice(this.ti);
OtherService otherService = (OtherService) proxyFactory.getProxy();
otherService.foo();
replacedertGetTransactionAndCommitCount(1);
}
@Test
public void withInterfaceOnTargetJdkProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.addInterface(TestWithInterface.clreplaced);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
@Test
public void withInterfaceOnTargetCglibProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.setProxyTargetClreplaced(true);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
replacedertGetTransactionAndCommitCount(5);
}
private void replacedertGetTransactionAndCommitCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.commits);
}
private void replacedertGetTransactionAndRollbackCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.rollbacks);
}
@Transactional
public static clreplaced TestClreplacedLevelOnly {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithSingleMethodOverride {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional(readOnly = true)
public static clreplaced TestWithSingleMethodOverrideInverted {
@Transactional
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithMultiMethodOverride {
@Transactional(readOnly = true)
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional(rollbackFor = IllegalStateException.clreplaced)
public static clreplaced TestWithRollback {
public void doSomethingErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalStateException();
}
@Transactional(rollbackFor = IllegalArgumentException.clreplaced)
public void doSomethingElseErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalArgumentException();
}
}
public interface BaseInterface {
void doSomething();
}
@Transactional
public interface TestWithInterface extends BaseInterface {
@Transactional(readOnly = true)
void doSomethingElse();
default void doSomethingDefault() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
public static clreplaced TestWithInterfaceImpl implements TestWithInterface {
@Override
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Override
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
public interface SomeService {
void foo();
@Transactional
void bar();
@Transactional(readOnly = true)
void fooBar();
}
public static clreplaced SomeServiceImpl implements SomeService {
@Override
public void bar() {
}
@Override
@Transactional
public void foo() {
}
@Override
@Transactional(readOnly = false)
public void fooBar() {
}
}
public interface OtherService {
void foo();
}
@Transactional
public static clreplaced OtherServiceImpl implements OtherService {
@Override
public void foo() {
}
}
}
19
View Source File : TransactionAspectTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
/**
* @author Rod Johnson
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Sam Brannen
*/
public clreplaced TransactionAspectTests {
private final CallCountingTransactionManager txManager = new CallCountingTransactionManager();
private final TransactionalAnnotationOnlyOnClreplacedWithNoInterface annotationOnlyOnClreplacedWithNoInterface = new TransactionalAnnotationOnlyOnClreplacedWithNoInterface();
private final ClreplacedWithProtectedAnnotatedMember beanWithAnnotatedProtectedMethod = new ClreplacedWithProtectedAnnotatedMember();
private final ClreplacedWithPrivateAnnotatedMember beanWithAnnotatedPrivateMethod = new ClreplacedWithPrivateAnnotatedMember();
private final MethodAnnotationOnClreplacedWithNoInterface methodAnnotationOnly = new MethodAnnotationOnClreplacedWithNoInterface();
@Before
public void initContext() {
AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager);
}
@Test
public void testCommitOnAnnotatedClreplaced() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.echo(null);
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnAnnotatedProtectedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedProtectedMethod.doInTransaction();
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnAnnotatedPrivateMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedPrivateMethod.doSomething();
replacedertEquals(1, txManager.commits);
}
@Test
public void commitOnNonAnnotatedNonPublicMethodInTransactionalType() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.nonTransactionalMethod();
replacedertEquals(0, txManager.begun);
}
@Test
public void commitOnAnnotatedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
methodAnnotationOnly.echo(null);
replacedertEquals(1, txManager.commits);
}
@Test
public void notTransactional() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
new NotTransactional().noop();
replacedertEquals(0, txManager.begun);
}
@Test
public void defaultCommitOnAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> annotationOnlyOnClreplacedWithNoInterface.echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultRollbackOnAnnotatedClreplaced() throws Throwable {
final RuntimeException ex = new RuntimeException();
try {
testRollback(() -> annotationOnlyOnClreplacedWithNoInterface.echo(ex), true);
fail("Should have thrown RuntimeException");
} catch (RuntimeException ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultCommitOnSubclreplacedOfAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> new SubclreplacedOfClreplacedWithTransactionalAnnotation().echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void defaultCommitOnSubclreplacedOfClreplacedWithTransactionalMethodAnnotated() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(() -> new SubclreplacedOfClreplacedWithTransactionalMethodAnnotation().echo(ex), false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
@Test
public void noCommitOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception ex = new Exception();
testNotTransactional(() -> new ImplementsAnnotatedInterface().echo(ex), ex);
}
@Test
public void noRollbackOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception rollbackProvokingException = new RuntimeException();
testNotTransactional(() -> new ImplementsAnnotatedInterface().echo(rollbackProvokingException), rollbackProvokingException);
}
protected void testRollback(TransactionOperationCallback toc, boolean rollback) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} finally {
replacedertEquals(1, txManager.begun);
replacedertEquals(rollback ? 0 : 1, txManager.commits);
replacedertEquals(rollback ? 1 : 0, txManager.rollbacks);
}
}
protected void testNotTransactional(TransactionOperationCallback toc, Throwable expected) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} catch (Throwable t) {
if (expected == null) {
fail("Expected " + expected);
}
replacedertSame(expected, t);
} finally {
replacedertEquals(0, txManager.begun);
}
}
private interface TransactionOperationCallback {
Object performTransactionalOperation() throws Throwable;
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalAnnotation extends TransactionalAnnotationOnlyOnClreplacedWithNoInterface {
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalMethodAnnotation extends MethodAnnotationOnClreplacedWithNoInterface {
}
public static clreplaced ImplementsAnnotatedInterface implements ITransactional {
@Override
public Object echo(Throwable t) throws Throwable {
if (t != null) {
throw t;
}
return t;
}
}
public static clreplaced NotTransactional {
public void noop() {
}
}
}
19
View Source File : ScheduledAndTransactionalAnnotationIntegrationTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void succeedsWhenSubclreplacedProxyAndScheduledMethodNotPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.clreplaced, SubclreplacedProxyTxConfig.clreplaced, RepoConfigA.clreplaced);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(100);
MyRepository repository = ctx.getBean(MyRepository.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
replacedertThat("repository is not a proxy", AopUtils.isAopProxy(repository), equalTo(true));
replacedertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
replacedertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
19
View Source File : ScheduledAndTransactionalAnnotationIntegrationTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.clreplaced, JdkProxyTxConfig.clreplaced, RepoConfigB.clreplaced);
ctx.refresh();
// allow @Scheduled method to be called several times
Thread.sleep(50);
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.clreplaced);
replacedertThat("repository is not a proxy", AopUtils.isAopProxy(repository), is(true));
replacedertThat("@Scheduled method never called", repository.getInvocationCount(), greaterThan(0));
replacedertThat("no transactions were committed", txManager.commits, greaterThan(0));
}
19
View Source File : BeanFactoryTransactionTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Test that we can set the target to a dynamic TargetSource.
*/
@Test
public void testDynamicTargetSource() throws NoSuchMethodException {
// Install facade
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = txMan;
TestBean tb = (TestBean) factory.getBean("hotSwapped");
replacedertEquals(666, tb.getAge());
int newAge = 557;
tb.setAge(newAge);
replacedertEquals(newAge, tb.getAge());
TestBean target2 = new TestBean();
target2.setAge(65);
HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
ts.swap(target2);
replacedertEquals(target2.getAge(), tb.getAge());
tb.setAge(newAge);
replacedertEquals(newAge, target2.getAge());
replacedertEquals(0, txMan.inflight);
replacedertEquals(2, txMan.commits);
replacedertEquals(0, txMan.rollbacks);
}
19
View Source File : EnableTransactionManagementTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void spr11915() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.clreplaced);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.clreplaced);
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.clreplaced);
bean.saveQualifiedFoo();
replacedertThat(txManager.begun, equalTo(1));
replacedertThat(txManager.commits, equalTo(1));
replacedertThat(txManager.rollbacks, equalTo(0));
bean.saveQualifiedFooWithAttributeAlias();
replacedertThat(txManager.begun, equalTo(2));
replacedertThat(txManager.commits, equalTo(2));
replacedertThat(txManager.rollbacks, equalTo(0));
ctx.close();
}
19
View Source File : AnnotationTransactionInterceptorTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public clreplaced AnnotationTransactionInterceptorTests {
private final CallCountingTransactionManager ptm = new CallCountingTransactionManager();
private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource();
private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source);
@Test
public void clreplacedLevelOnly() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestClreplacedLevelOnly());
proxyFactory.addAdvice(this.ti);
TestClreplacedLevelOnly proxy = (TestClreplacedLevelOnly) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverride proxy = (TestWithSingleMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withMultiMethodOverride() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithMultiMethodOverride());
proxyFactory.addAdvice(this.ti);
TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void withRollback() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithRollback());
proxyFactory.addAdvice(this.ti);
TestWithRollback proxy = (TestWithRollback) proxyFactory.getProxy();
try {
proxy.doSomethingErroneous();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ex) {
replacedertGetTransactionAndRollbackCount(1);
}
try {
proxy.doSomethingElseErroneous();
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
replacedertGetTransactionAndRollbackCount(2);
}
}
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
proxyFactory.addInterface(TestWithInterface.clreplaced);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
replacedertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
replacedertGetTransactionAndCommitCount(3);
proxy.doSomething();
replacedertGetTransactionAndCommitCount(4);
}
@Test
public void crossClreplacedInterfaceMethodLevelOnJdkProxy() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new SomeServiceImpl());
proxyFactory.addInterface(SomeService.clreplaced);
proxyFactory.addAdvice(this.ti);
SomeService someService = (SomeService) proxyFactory.getProxy();
someService.bar();
replacedertGetTransactionAndCommitCount(1);
someService.foo();
replacedertGetTransactionAndCommitCount(2);
someService.fooBar();
replacedertGetTransactionAndCommitCount(3);
}
@Test
public void crossClreplacedInterfaceOnJdkProxy() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.clreplaced);
proxyFactory.addAdvice(this.ti);
OtherService otherService = (OtherService) proxyFactory.getProxy();
otherService.foo();
replacedertGetTransactionAndCommitCount(1);
}
private void replacedertGetTransactionAndCommitCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.commits);
}
private void replacedertGetTransactionAndRollbackCount(int expectedCount) {
replacedertEquals(expectedCount, this.ptm.begun);
replacedertEquals(expectedCount, this.ptm.rollbacks);
}
@Transactional
public static clreplaced TestClreplacedLevelOnly {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithSingleMethodOverride {
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional(readOnly = true)
public static clreplaced TestWithSingleMethodOverrideInverted {
@Transactional
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional
public static clreplaced TestWithMultiMethodOverride {
@Transactional(readOnly = true)
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Transactional(readOnly = true)
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
public void doSomethingCompletelyElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
@Transactional(rollbackFor = IllegalStateException.clreplaced)
public static clreplaced TestWithRollback {
public void doSomethingErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalStateException();
}
@Transactional(rollbackFor = IllegalArgumentException.clreplaced)
public void doSomethingElseErroneous() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
throw new IllegalArgumentException();
}
}
@Transactional
public static interface TestWithInterface {
public void doSomething();
@Transactional(readOnly = true)
public void doSomethingElse();
}
public static clreplaced TestWithInterfaceImpl implements TestWithInterface {
@Override
public void doSomething() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
@Override
public void doSomethingElse() {
replacedertTrue(TransactionSynchronizationManager.isActualTransactionActive());
replacedertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
}
public static interface SomeService {
void foo();
@Transactional
void bar();
@Transactional(readOnly = true)
void fooBar();
}
public static clreplaced SomeServiceImpl implements SomeService {
@Override
public void bar() {
}
@Override
@Transactional
public void foo() {
}
@Override
@Transactional(readOnly = false)
public void fooBar() {
}
}
public interface OtherService {
void foo();
}
@Transactional
public static clreplaced OtherServiceImpl implements OtherService {
@Override
public void foo() {
}
}
}
19
View Source File : TransactionAspectTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* @author Rod Johnson
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Sam Brannen
*/
@SuppressWarnings("deprecation")
public clreplaced TransactionAspectTests extends org.springframework.test.AbstractDependencyInjectionSpringContextTests {
private CallCountingTransactionManager txManager;
private TransactionalAnnotationOnlyOnClreplacedWithNoInterface annotationOnlyOnClreplacedWithNoInterface;
private ClreplacedWithProtectedAnnotatedMember beanWithAnnotatedProtectedMethod;
private ClreplacedWithPrivateAnnotatedMember beanWithAnnotatedPrivateMethod;
private MethodAnnotationOnClreplacedWithNoInterface methodAnnotationOnly = new MethodAnnotationOnClreplacedWithNoInterface();
public void setAnnotationOnlyOnClreplacedWithNoInterface(TransactionalAnnotationOnlyOnClreplacedWithNoInterface annotationOnlyOnClreplacedWithNoInterface) {
this.annotationOnlyOnClreplacedWithNoInterface = annotationOnlyOnClreplacedWithNoInterface;
}
public void setClreplacedWithAnnotatedProtectedMethod(ClreplacedWithProtectedAnnotatedMember aBean) {
this.beanWithAnnotatedProtectedMethod = aBean;
}
public void setClreplacedWithAnnotatedPrivateMethod(ClreplacedWithPrivateAnnotatedMember aBean) {
this.beanWithAnnotatedPrivateMethod = aBean;
}
public void setTransactionAspect(TransactionAspectSupport transactionAspect) {
this.txManager = (CallCountingTransactionManager) transactionAspect.getTransactionManager();
}
@Override
protected String[] getConfigPaths() {
return new String[] { "TransactionAspectTests-context.xml" };
}
public void testCommitOnAnnotatedClreplaced() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.echo(null);
replacedertEquals(1, txManager.commits);
}
public void testCommitOnAnnotatedProtectedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedProtectedMethod.doInTransaction();
replacedertEquals(1, txManager.commits);
}
public void testCommitOnAnnotatedPrivateMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
beanWithAnnotatedPrivateMethod.doSomething();
replacedertEquals(1, txManager.commits);
}
public void testNoCommitOnNonAnnotatedNonPublicMethodInTransactionalType() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
annotationOnlyOnClreplacedWithNoInterface.nonTransactionalMethod();
replacedertEquals(0, txManager.begun);
}
public void testCommitOnAnnotatedMethod() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
methodAnnotationOnly.echo(null);
replacedertEquals(1, txManager.commits);
}
public void testNotTransactional() throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
new NotTransactional().noop();
replacedertEquals(0, txManager.begun);
}
public void testDefaultCommitOnAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return annotationOnlyOnClreplacedWithNoInterface.echo(ex);
}
}, false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
public void testDefaultRollbackOnAnnotatedClreplaced() throws Throwable {
final RuntimeException ex = new RuntimeException();
try {
testRollback(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return annotationOnlyOnClreplacedWithNoInterface.echo(ex);
}
}, true);
fail("Should have thrown RuntimeException");
} catch (RuntimeException ex2) {
replacedertSame(ex, ex2);
}
}
public void testDefaultCommitOnSubclreplacedOfAnnotatedClreplaced() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return new SubclreplacedOfClreplacedWithTransactionalAnnotation().echo(ex);
}
}, false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
public void testDefaultCommitOnSubclreplacedOfClreplacedWithTransactionalMethodAnnotated() throws Throwable {
final Exception ex = new Exception();
try {
testRollback(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return new SubclreplacedOfClreplacedWithTransactionalMethodAnnotation().echo(ex);
}
}, false);
fail("Should have thrown Exception");
} catch (Exception ex2) {
replacedertSame(ex, ex2);
}
}
public void testDefaultCommitOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception ex = new Exception();
testNotTransactional(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return new ImplementsAnnotatedInterface().echo(ex);
}
}, ex);
}
/**
* Note: resolution does not occur. Thus we can't make a clreplaced transactional if
* it implements a transactionally annotated interface. This behaviour could only
* be changed in AbstractFallbackTransactionAttributeSource in Spring proper.
*/
public void testDoesNotResolveTxAnnotationOnMethodFromClreplacedImplementingAnnotatedInterface() throws Exception {
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
Method m = ImplementsAnnotatedInterface.clreplaced.getMethod("echo", Throwable.clreplaced);
TransactionAttribute ta = atas.getTransactionAttribute(m, ImplementsAnnotatedInterface.clreplaced);
replacedertNull(ta);
}
public void testDefaultRollbackOnImplementationOfAnnotatedInterface() throws Throwable {
final Exception rollbackProvokingException = new RuntimeException();
testNotTransactional(new TransactionOperationCallback() {
@Override
public Object performTransactionalOperation() throws Throwable {
return new ImplementsAnnotatedInterface().echo(rollbackProvokingException);
}
}, rollbackProvokingException);
}
protected void testRollback(TransactionOperationCallback toc, boolean rollback) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} finally {
replacedertEquals(1, txManager.begun);
replacedertEquals(rollback ? 0 : 1, txManager.commits);
replacedertEquals(rollback ? 1 : 0, txManager.rollbacks);
}
}
protected void testNotTransactional(TransactionOperationCallback toc, Throwable expected) throws Throwable {
txManager.clear();
replacedertEquals(0, txManager.begun);
try {
toc.performTransactionalOperation();
} catch (Throwable t) {
if (expected == null) {
fail("Expected " + expected);
}
replacedertSame(expected, t);
} finally {
replacedertEquals(0, txManager.begun);
}
}
private interface TransactionOperationCallback {
Object performTransactionalOperation() throws Throwable;
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalAnnotation extends TransactionalAnnotationOnlyOnClreplacedWithNoInterface {
}
public static clreplaced SubclreplacedOfClreplacedWithTransactionalMethodAnnotation extends MethodAnnotationOnClreplacedWithNoInterface {
}
public static clreplaced ImplementsAnnotatedInterface implements ITransactional {
@Override
public Object echo(Throwable t) throws Throwable {
if (t != null) {
throw t;
}
return t;
}
}
public static clreplaced NotTransactional {
public void noop() {
}
}
}
18
View Source File : EnableTransactionManagementIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void explicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ExplicitTxManagerConfig.clreplaced);
ctx.refresh();
FooRepository fooRepository = ctx.getBean(FooRepository.clreplaced);
fooRepository.findAll();
CallCountingTransactionManager txManager1 = ctx.getBean("txManager1", CallCountingTransactionManager.clreplaced);
replacedertThat(txManager1.begun, equalTo(1));
replacedertThat(txManager1.commits, equalTo(1));
replacedertThat(txManager1.rollbacks, equalTo(0));
CallCountingTransactionManager txManager2 = ctx.getBean("txManager2", CallCountingTransactionManager.clreplaced);
replacedertThat(txManager2.begun, equalTo(0));
replacedertThat(txManager2.commits, equalTo(0));
replacedertThat(txManager2.rollbacks, equalTo(0));
}
18
View Source File : AdvisorAutoProxyCreatorIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
replacedertTrue(bean instanceof CallCountingTransactionManager);
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
Rollback rb = (Rollback) bf.getBean("rollback");
replacedertEquals(0, txMan.commits);
rb.rollbackOnly(false);
replacedertEquals("Transaction counts match", 1, txMan.commits);
replacedertEquals(0, txMan.rollbacks);
// Will cause rollback only
rb.rollbackOnly(true);
replacedertEquals(1, txMan.rollbacks);
}
18
View Source File : TxNamespaceHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void invokeTransactional() {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
replacedertEquals("Should not have any started transactions", 0, ptm.begun);
testBean.getName();
replacedertTrue(ptm.lastDefinition.isReadOnly());
replacedertEquals("Should have 1 started transaction", 1, ptm.begun);
replacedertEquals("Should have 1 committed transaction", 1, ptm.commits);
// try with non-transaction
testBean.haveBirthday();
replacedertEquals("Should not have started another transaction", 1, ptm.begun);
// try with exceptional
try {
testBean.exceptional(new IllegalArgumentException("foo"));
fail("Should NEVER get here");
} catch (Throwable throwable) {
replacedertEquals("Should have another started transaction", 2, ptm.begun);
replacedertEquals("Should have 1 rolled back transaction", 1, ptm.rollbacks);
}
}
18
View Source File : BeanFactoryTransactionTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testCglibTransactionProxyImplementsNoInterfaces() {
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
replacedertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
replacedertTrue(ini instanceof TransactionalProxy);
String newName = "Gordon";
// Install facade
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = ptm;
ini.setName(newName);
replacedertEquals(newName, ini.getName());
replacedertEquals(2, ptm.commits);
}
18
View Source File : TransactionManagerConfiguration.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Bean
@NoSynch
public PlatformTransactionManager transactionManager2() {
CallCountingTransactionManager tm = new CallCountingTransactionManager();
tm.setTransactionSynchronization(CallCountingTransactionManager.SYNCHRONIZATION_NEVER);
return tm;
}
18
View Source File : AnnotationDrivenTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
private void doTestWithMultipleTransactionManagers(ApplicationContext context) {
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.clreplaced);
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.clreplaced);
TransactionalService service = context.getBean("service", TransactionalService.clreplaced);
replacedertTrue(AopUtils.isCglibProxy(service));
service.setSomething("someName");
replacedertEquals(1, tm1.commits);
replacedertEquals(0, tm2.commits);
service.doSomething();
replacedertEquals(1, tm1.commits);
replacedertEquals(1, tm2.commits);
service.setSomething("someName");
replacedertEquals(2, tm1.commits);
replacedertEquals(1, tm2.commits);
service.doSomething();
replacedertEquals(2, tm1.commits);
replacedertEquals(2, tm2.commits);
}
18
View Source File : AnnotationTransactionNamespaceHandlerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void invokeTransactional() throws Exception {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
replacedertEquals("Should not have any started transactions", 0, ptm.begun);
testBean.findAllFoos();
replacedertEquals("Should have 1 started transaction", 1, ptm.begun);
replacedertEquals("Should have 1 committed transaction", 1, ptm.commits);
// try with non-transaction
testBean.doSomething();
replacedertEquals("Should not have started another transaction", 1, ptm.begun);
// try with exceptional
try {
testBean.exceptional(new IllegalArgumentException("foo"));
fail("Should NEVER get here");
} catch (Throwable throwable) {
replacedertEquals("Should have another started transaction", 2, ptm.begun);
replacedertEquals("Should have 1 rolled back transaction", 1, ptm.rollbacks);
}
}
18
View Source File : AnnotationTransactionAttributeSourceTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.clreplaced);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
replacedertEquals(1, ptm.commits);
ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
replacedertEquals(2, serializedPtm.commits);
}
18
View Source File : LookUpTxMgrByTypeTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@Transactional
public clreplaced LookUpTxMgrByTypeTests {
private static final CallCountingTransactionManager txManager = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager txManager() {
return txManager;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager.clear();
}
@Test
public void transactionalTest() {
replacedertEquals(1, txManager.begun);
replacedertEquals(1, txManager.inflight);
replacedertEquals(0, txManager.commits);
replacedertEquals(0, txManager.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager.begun);
replacedertEquals(0, txManager.inflight);
replacedertEquals(0, txManager.commits);
replacedertEquals(1, txManager.rollbacks);
}
}
18
View Source File : LookUpTxMgrByTypeAndDefaultNameTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9645">SPR-9645</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@Transactional
public clreplaced LookUpTxMgrByTypeAndDefaultNameTests {
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager();
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager();
@Configuration
static clreplaced Config {
@Bean
public PlatformTransactionManager transactionManager() {
return txManager1;
}
@Bean
public PlatformTransactionManager txManager2() {
return txManager2;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager1.clear();
txManager2.clear();
}
@Test
public void transactionalTest() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(1, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(0, txManager1.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(0, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(1, txManager1.rollbacks);
}
}
18
View Source File : LookUpTxMgrViaTransactionManagementConfigurerTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Integration tests that verify the behavior requested in
* <a href="https://jira.spring.io/browse/SPR-9604">SPR-9604</a>.
*
* @author Sam Brannen
* @since 3.2
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration
@Transactional
public clreplaced LookUpTxMgrViaTransactionManagementConfigurerTests {
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager();
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager();
@Configuration
static clreplaced Config implements TransactionManagementConfigurer {
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return txManager1();
}
@Bean
public PlatformTransactionManager txManager1() {
return txManager1;
}
@Bean
public PlatformTransactionManager txManager2() {
return txManager2;
}
}
@BeforeTransaction
public void beforeTransaction() {
txManager1.clear();
txManager2.clear();
}
@Test
public void transactionalTest() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(1, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(0, txManager1.rollbacks);
replacedertEquals(0, txManager2.begun);
replacedertEquals(0, txManager2.inflight);
replacedertEquals(0, txManager2.commits);
replacedertEquals(0, txManager2.rollbacks);
}
@AfterTransaction
public void afterTransaction() {
replacedertEquals(1, txManager1.begun);
replacedertEquals(0, txManager1.inflight);
replacedertEquals(0, txManager1.commits);
replacedertEquals(1, txManager1.rollbacks);
replacedertEquals(0, txManager2.begun);
replacedertEquals(0, txManager2.inflight);
replacedertEquals(0, txManager2.commits);
replacedertEquals(0, txManager2.rollbacks);
}
}
18
View Source File : JtaTransactionAspectsTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* @author Stephane Nicoll
*/
@RunWith(SpringJUnit4ClreplacedRunner.clreplaced)
@ContextConfiguration(clreplacedes = JtaTransactionAspectsTests.Config.clreplaced)
public clreplaced JtaTransactionAspectsTests {
@Autowired
private CallCountingTransactionManager txManager;
@Before
public void setUp() {
this.txManager.clear();
}
@Test
public void commitOnAnnotatedPublicMethod() throws Throwable {
replacedertEquals(0, this.txManager.begun);
new JtaAnnotationPublicAnnotatedMember().echo(null);
replacedertEquals(1, this.txManager.commits);
}
@Test
public void matchingRollbackOnApplied() throws Throwable {
replacedertEquals(0, this.txManager.begun);
InterruptedException test = new InterruptedException();
try {
new JtaAnnotationPublicAnnotatedMember().echo(test);
fail("Should have thrown an exception");
} catch (Throwable throwable) {
replacedertEquals("wrong exception", test, throwable);
}
replacedertEquals(1, this.txManager.rollbacks);
replacedertEquals(0, this.txManager.commits);
}
@Test
public void nonMatchingRollbackOnApplied() throws Throwable {
replacedertEquals(0, this.txManager.begun);
IOException test = new IOException();
try {
new JtaAnnotationPublicAnnotatedMember().echo(test);
fail("Should have thrown an exception");
} catch (Throwable throwable) {
replacedertEquals("wrong exception", test, throwable);
}
replacedertEquals(1, this.txManager.commits);
replacedertEquals(0, this.txManager.rollbacks);
}
@Test
public void commitOnAnnotatedProtectedMethod() {
replacedertEquals(0, this.txManager.begun);
new JtaAnnotationProtectedAnnotatedMember().doInTransaction();
replacedertEquals(1, this.txManager.commits);
}
@Test
public void nonAnnotatedMethodCallingProtectedMethod() {
replacedertEquals(0, this.txManager.begun);
new JtaAnnotationProtectedAnnotatedMember().doSomething();
replacedertEquals(1, this.txManager.commits);
}
@Test
public void commitOnAnnotatedPrivateMethod() {
replacedertEquals(0, this.txManager.begun);
new JtaAnnotationPrivateAnnotatedMember().doInTransaction();
replacedertEquals(1, this.txManager.commits);
}
@Test
public void nonAnnotatedMethodCallingPrivateMethod() {
replacedertEquals(0, this.txManager.begun);
new JtaAnnotationPrivateAnnotatedMember().doSomething();
replacedertEquals(1, this.txManager.commits);
}
@Test
public void notTransactional() {
replacedertEquals(0, this.txManager.begun);
new TransactionAspectTests.NotTransactional().noop();
replacedertEquals(0, this.txManager.begun);
}
public static clreplaced JtaAnnotationPublicAnnotatedMember {
@Transactional(rollbackOn = InterruptedException.clreplaced)
public void echo(Throwable t) throws Throwable {
if (t != null) {
throw t;
}
}
}
protected static clreplaced JtaAnnotationProtectedAnnotatedMember {
public void doSomething() {
doInTransaction();
}
@Transactional
protected void doInTransaction() {
}
}
protected static clreplaced JtaAnnotationPrivateAnnotatedMember {
public void doSomething() {
doInTransaction();
}
@Transactional
private void doInTransaction() {
}
}
@Configuration
protected static clreplaced Config {
@Bean
public CallCountingTransactionManager transactionManager() {
return new CallCountingTransactionManager();
}
@Bean
public JtaAnnotationTransactionAspect transactionAspect() {
JtaAnnotationTransactionAspect aspect = JtaAnnotationTransactionAspect.aspectOf();
aspect.setTransactionManager(transactionManager());
return aspect;
}
}
}
18
View Source File : TxNamespaceHandlerTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void invokeTransactional() {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
replacedertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
testBean.getName();
replacedertThat(ptm.lastDefinition.isReadOnly()).isTrue();
replacedertThat(ptm.begun).as("Should have 1 started transaction").isEqualTo(1);
replacedertThat(ptm.commits).as("Should have 1 committed transaction").isEqualTo(1);
// try with non-transaction
testBean.haveBirthday();
replacedertThat(ptm.begun).as("Should not have started another transaction").isEqualTo(1);
// try with exceptional
replacedertThatExceptionOfType(Throwable.clreplaced).isThrownBy(() -> testBean.exceptional(new IllegalArgumentException("foo")));
replacedertThat(ptm.begun).as("Should have another started transaction").isEqualTo(2);
replacedertThat(ptm.rollbacks).as("Should have 1 rolled back transaction").isEqualTo(1);
}
18
View Source File : BeanFactoryTransactionTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void testCglibTransactionProxyImplementsNoInterfaces() {
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
replacedertThat(AopUtils.isCglibProxy(ini)).as("testBean is CGLIB advised").isTrue();
boolean condition = ini instanceof TransactionalProxy;
replacedertThat(condition).isTrue();
String newName = "Gordon";
// Install facade
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = ptm;
ini.setName(newName);
replacedertThat(ini.getName()).isEqualTo(newName);
replacedertThat(ptm.commits).isEqualTo(2);
}
18
View Source File : AnnotationDrivenTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
private void doTestWithMultipleTransactionManagers(ApplicationContext context) {
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.clreplaced);
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.clreplaced);
TransactionalService service = context.getBean("service", TransactionalService.clreplaced);
replacedertThat(AopUtils.isCglibProxy(service)).isTrue();
service.setSomething("someName");
replacedertThat(tm1.commits).isEqualTo(1);
replacedertThat(tm2.commits).isEqualTo(0);
service.doSomething();
replacedertThat(tm1.commits).isEqualTo(1);
replacedertThat(tm2.commits).isEqualTo(1);
service.setSomething("someName");
replacedertThat(tm1.commits).isEqualTo(2);
replacedertThat(tm2.commits).isEqualTo(1);
service.doSomething();
replacedertThat(tm1.commits).isEqualTo(2);
replacedertThat(tm2.commits).isEqualTo(2);
}
18
View Source File : AnnotationTransactionNamespaceHandlerTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void invokeTransactional() throws Exception {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
replacedertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
testBean.findAllFoos();
replacedertThat(ptm.begun).as("Should have 1 started transaction").isEqualTo(1);
replacedertThat(ptm.commits).as("Should have 1 committed transaction").isEqualTo(1);
// try with non-transaction
testBean.doSomething();
replacedertThat(ptm.begun).as("Should not have started another transaction").isEqualTo(1);
// try with exceptional
replacedertThatExceptionOfType(Throwable.clreplaced).isThrownBy(() -> testBean.exceptional(new IllegalArgumentException("foo"))).satisfies(ex -> {
replacedertThat(ptm.begun).as("Should have another started transaction").isEqualTo(2);
replacedertThat(ptm.rollbacks).as("Should have 1 rolled back transaction").isEqualTo(1);
});
}
18
View Source File : AnnotationTransactionAttributeSourceTests.java
License : Apache License 2.0
Project Creator : q920447939
License : Apache License 2.0
Project Creator : q920447939
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.clreplaced);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
replacedertThat(ptm.commits).isEqualTo(1);
ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
replacedertThat(serializedPtm.commits).isEqualTo(2);
}
18
View Source File : TxNamespaceHandlerTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void invokeTransactional() throws Exception {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
replacedertEquals("Should not have any started transactions", 0, ptm.begun);
testBean.getName();
replacedertTrue(ptm.lastDefinition.isReadOnly());
replacedertEquals("Should have 1 started transaction", 1, ptm.begun);
replacedertEquals("Should have 1 committed transaction", 1, ptm.commits);
// try with non-transaction
testBean.haveBirthday();
replacedertEquals("Should not have started another transaction", 1, ptm.begun);
// try with exceptional
try {
testBean.exceptional(new IllegalArgumentException("foo"));
fail("Should NEVER get here");
} catch (Throwable throwable) {
replacedertEquals("Should have another started transaction", 2, ptm.begun);
replacedertEquals("Should have 1 rolled back transaction", 1, ptm.rollbacks);
}
}
18
View Source File : BeanFactoryTransactionTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMethodException {
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
replacedertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
replacedertTrue(ini instanceof TransactionalProxy);
String newName = "Gordon";
// Install facade
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
PlatformTransactionManagerFacade.delegate = ptm;
ini.setName(newName);
replacedertEquals(newName, ini.getName());
replacedertEquals(2, ptm.commits);
}
See More Examples