INT-2727 PseudoTX Refactoring
Remove the need for pseudo-transactional element INT-2727 PseudoTX Add PseudoTransactionalTransactionManager INT-2727 addressed PR comments cherry picked previous code for mail module to eliminate breaking change INT-2727 initial refactoring pseudo-tx support to use common configuration INT-2727 finalizing pseudo-tx synchronization support INT-2727 polishing INT-2727 polishing based on PR comments INT-2727 addressed PR comments INT-2727 polishing INT-2727 Remove PseudoTransactionalMessageSource Instead of getResource, bind the resource holder before receive() and then add attributes to the holder. INT-2727 polishing INT-2727 Polishing Remove bind of #resource; add beforeCommit() test; add TransactionTemplate tests.
This commit is contained in:
committed by
Gary Russell
parent
5828f70321
commit
94cc5a73e2
@@ -14,10 +14,7 @@
|
||||
<int-file:inbound-channel-adapter id="pseudoTx"
|
||||
channel="input" auto-startup="false" directory="${java.io.tmpdir}/si-test1">
|
||||
<int:poller fixed-rate="500">
|
||||
<int:pseudo-transactional
|
||||
on-success-expression="payload.delete()" on-success-result-channel="successChannel"
|
||||
on-failure-expression="'foo'" on-failure-result-channel="failureChannel"
|
||||
send-timeout="500" />
|
||||
<int:transactional synchronization-factory="syncFactoryA"/>
|
||||
</int:poller>
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
@@ -36,15 +33,34 @@
|
||||
<int-file:inbound-channel-adapter id="realTx" channel="txInput" auto-startup="false"
|
||||
directory="${java.io.tmpdir}/si-test2">
|
||||
<int:poller fixed-rate="500">
|
||||
<int:transactional transaction-manager="txManager" />
|
||||
<int:transaction-synchronization on-success-expression="@txManager.committed"
|
||||
on-success-result-channel="successChannel"
|
||||
on-failure-expression="@txManager.rolledBack"
|
||||
on-failure-result-channel="failureChannel"
|
||||
send-timeout="5000" />
|
||||
<int:transactional transaction-manager="txManager" synchronization-factory="syncFactoryB"/>
|
||||
</int:poller>
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<bean id="txManager" class="org.springframework.integration.file.FileInboundTransactionTests$DummyTxManager" />
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>
|
||||
|
||||
<bean id="syncFactoryA" class="org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor">
|
||||
<property name="afterCommitExpression" value="#{new org.springframework.expression.spel.standard.SpelExpressionParser().parseExpression('payload.delete()')}"/>
|
||||
<property name="afterCommitChannel" ref="successChannel"/>
|
||||
<property name="afterRollbackExpression" value="#{new org.springframework.expression.common.LiteralExpression('foo')}"/>
|
||||
<property name="afterRollbackChannel" ref="failureChannel"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="syncFactoryB" class="org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor">
|
||||
<property name="afterCommitExpression" value="#{new org.springframework.expression.spel.standard.SpelExpressionParser().parseExpression('@txManager.committed')}"/>
|
||||
<property name="afterCommitChannel" ref="successChannel"/>
|
||||
<property name="afterRollbackExpression" value="#{new org.springframework.expression.spel.standard.SpelExpressionParser().parseExpression('@txManager.rolledBack')}"/>
|
||||
<property name="afterRollbackChannel" ref="failureChannel"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -26,10 +26,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
@@ -95,7 +95,7 @@ public class FileInboundTransactionTests {
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(10000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getHeaders().get(MessageHeaders.DISPOSITION_RESULT));
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
System.out.println(result);
|
||||
assertFalse(file.delete());
|
||||
crash.set(true);
|
||||
@@ -105,7 +105,7 @@ public class FileInboundTransactionTests {
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
assertTrue(file.delete());
|
||||
assertEquals("foo", result.getHeaders().get(MessageHeaders.DISPOSITION_RESULT));
|
||||
assertEquals("foo", result.getPayload());
|
||||
pseudoTx.stop();
|
||||
assertFalse(transactionManager.getCommitted());
|
||||
assertFalse(transactionManager.getRolledBack());
|
||||
@@ -131,7 +131,7 @@ public class FileInboundTransactionTests {
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(10000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getHeaders().get(MessageHeaders.DISPOSITION_RESULT));
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertTrue(file.delete());
|
||||
System.out.println(result);
|
||||
assertTrue(transactionManager.getCommitted());
|
||||
@@ -142,7 +142,7 @@ public class FileInboundTransactionTests {
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
assertTrue(file.delete());
|
||||
assertEquals(Boolean.TRUE, result.getHeaders().get(MessageHeaders.DISPOSITION_RESULT));
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
realTx.stop();
|
||||
assertTrue(transactionManager.getRolledBack());
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
</bean>
|
||||
|
||||
<si:poller default="true" fixed-rate="10">
|
||||
<si:pseudo-transactional on-success-expression="payload.delete()"
|
||||
on-success-result-channel="resultChannel" />
|
||||
<si:transactional synchronization-factory="syncFactory"/>
|
||||
</si:poller>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
@@ -45,4 +44,15 @@
|
||||
<si:channel id="resultChannel">
|
||||
<si:queue />
|
||||
</si:channel>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>
|
||||
|
||||
<bean id="syncFactory" class="org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor">
|
||||
<property name="afterCommitExpression" value="#{new org.springframework.expression.spel.standard.SpelExpressionParser().parseExpression('payload.delete()')}"/>
|
||||
<property name="afterCommitChannel" ref="resultChannel"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
@@ -25,9 +25,9 @@ import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -47,7 +47,7 @@ public class FileToChannelIntegrationTests {
|
||||
@Autowired
|
||||
PollableChannel resultChannel;
|
||||
|
||||
@Test(timeout = 2000)
|
||||
@Test//(timeout = 2000)
|
||||
public void fileMessageToChannel() throws Exception {
|
||||
File file = File.createTempFile("test", null, inputDirectory);
|
||||
file.setLastModified(System.currentTimeMillis() - 1000);
|
||||
@@ -59,7 +59,7 @@ public class FileToChannelIntegrationTests {
|
||||
assertNotNull(received.getPayload());
|
||||
Message<?> result = resultChannel.receive(10000);
|
||||
assertNotNull(result);
|
||||
assertEquals(Boolean.TRUE, result.getHeaders().get(MessageHeaders.DISPOSITION_RESULT));
|
||||
assertEquals(Boolean.TRUE, result.getPayload());
|
||||
assertTrue(!file.exists());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
comparator="testComparator"
|
||||
auto-startup="false">
|
||||
<integration:poller fixed-rate="5000">
|
||||
<integration:pseudo-transactional on-success-expression="payload.delete()"
|
||||
on-success-result-channel="successChannel"
|
||||
on-failure-expression="'foo'"
|
||||
on-failure-result-channel="nullChannel"
|
||||
send-timeout="5000" />
|
||||
<integration:transactional synchronization-factory="syncFactory"/>
|
||||
</integration:poller>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
@@ -38,5 +34,18 @@
|
||||
|
||||
<beans:bean id="testComparator"
|
||||
class="org.springframework.integration.file.config.FileInboundChannelAdapterParserTests$TestComparator"/>
|
||||
|
||||
<beans:bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>
|
||||
|
||||
<beans:bean id="syncFactory" class="org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory">
|
||||
<beans:constructor-arg>
|
||||
<beans:bean class="org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor">
|
||||
<beans:property name="afterCommitExpression" value="#{new org.springframework.expression.spel.standard.SpelExpressionParser().parseExpression('payload.delete()')}"/>
|
||||
<beans:property name="afterCommitChannel" ref="successChannel"/>
|
||||
<beans:property name="afterRollbackExpression" value="#{new org.springframework.expression.common.LiteralExpression('foo')}"/>
|
||||
<beans:property name="afterRollbackChannel" ref="nullChannel"/>
|
||||
</beans:bean>
|
||||
</beans:constructor-arg>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
Reference in New Issue
Block a user