INT-1371, added test for advice chain within the chain with TX, made spring-tx an optional depenency in template.mf

This commit is contained in:
Oleg Zhurakousky
2010-09-15 11:06:16 -04:00
parent 1b87db30ba
commit 2e18ed6b11
3 changed files with 73 additions and 28 deletions

View File

@@ -20,12 +20,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.List;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.util.TestTransactionManager;
import org.springframework.transaction.IllegalTransactionStateException;
@@ -53,6 +60,27 @@ public class PollingTransactionTests {
assertEquals(0, txManager.getRollbackCount());
context.stop();
}
@Test
public void transactionWithCommitAndAdvices() throws InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"transactionTests.xml", this.getClass());
PollingConsumer advicedPoller = context.getBean("advicedSa", PollingConsumer.class);
List<Advice> adviceChain = (List<Advice>) new DirectFieldAccessor(advicedPoller).getPropertyValue("adviceChain");
assertEquals(2, adviceChain.size());
TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
MessageChannel input = (MessageChannel) context.getBean("goodInputWithAdvice");
PollableChannel output = (PollableChannel) context.getBean("output");
assertEquals(0, txManager.getCommitCount());
assertEquals(0, txManager.getRollbackCount());
input.send(new GenericMessage<String>("test"));
txManager.waitForCompletion(10000);
Message<?> message = output.receive(0);
assertNotNull(message);
assertEquals(1, txManager.getCommitCount());
assertEquals(0, txManager.getRollbackCount());
context.stop();
}
@Test
public void transactionWithRollback() throws InterruptedException {
@@ -157,4 +185,9 @@ public class PollingTransactionTests {
context.stop();
}
public static class SampleAdvice implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable {
return invocation.proceed();
}
}
}

View File

@@ -1,46 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<channel id="badInput">
<queue capacity="1"/>
<queue capacity="1" />
</channel>
<channel id="goodInput">
<queue capacity="1"/>
<queue capacity="1" />
</channel>
<channel id="goodInputWithAdvice">
<queue capacity="1" />
</channel>
<channel id="output">
<queue capacity="1"/>
<queue capacity="1" />
</channel>
<service-activator input-channel="badInput"
ref="testBean"
method="bad"
output-channel="output">
<poller max-messages-per-poll="1">
<interval-trigger interval="10000"/>
<transactional transaction-manager="txManager"/>
</poller>
</service-activator>
<service-activator input-channel="goodInput"
ref="testBean"
method="good"
output-channel="output">
<poller max-messages-per-poll="1">
<interval-trigger interval="10000"/>
<transactional transaction-manager="txManager"/>
</poller>
<service-activator input-channel="badInput" ref="testBean"
method="bad" output-channel="output">
<poller max-messages-per-poll="1" fixed-rate="10000">
<transactional transaction-manager="txManager" />
</poller>
</service-activator>
<beans:bean id="testBean" class="org.springframework.integration.dispatcher.TestBean"/>
<service-activator input-channel="goodInput" ref="testBean"
method="good" output-channel="output">
<poller max-messages-per-poll="1" fixed-rate="10000">
<transactional transaction-manager="txManager" />
</poller>
</service-activator>
<service-activator id="advicedSa" input-channel="goodInputWithAdvice" ref="testBean"
method="good" output-channel="output">
<poller max-messages-per-poll="1" fixed-rate="10000">
<transactional transaction-manager="txManager" />
<advice-chain>
<ref bean="adviceA" />
<beans:bean class="org.springframework.integration.dispatcher.PollingTransactionTests.SampleAdvice"/>
</advice-chain>
</poller>
</service-activator>
<beans:bean id="adviceA" class="org.springframework.integration.dispatcher.PollingTransactionTests.SampleAdvice"/>
<beans:bean id="txManager" class="org.springframework.integration.util.TestTransactionManager"/>
<beans:bean id="testBean"
class="org.springframework.integration.dispatcher.TestBean" />
<beans:bean id="txManager"
class="org.springframework.integration.util.TestTransactionManager" />
</beans:beans>

View File

@@ -5,6 +5,7 @@ Bundle-ManifestVersion: 2
Import-Template:
org.springframework.commons.*;version="[1.0.0, 2.0.0)";resolution:=optional,
org.springframework.*;version="[3.0.3, 4.0.0)",
org.springframework.transaction;version="[3.0.3, 4.0.0)";resolution:=optional,
org.apache.commons.logging;version="[1.1.1, 2.0.0)",
org.aopalliance.*;version="[1.0.0, 2.0.0)",
org.codehaus.jackson.*;version="[1.0.0, 2.0.0)";resolution:=optional,