INT-1231: add support for max-rows-per-poll

This commit is contained in:
David Syer
2010-07-10 16:44:38 +00:00
parent dd102fa2e0
commit 79b72a3794
6 changed files with 128 additions and 33 deletions

View File

@@ -19,7 +19,11 @@ import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@Transactional
public class JdbcPollingChannelAdapterParserTests {
@@ -32,6 +36,8 @@ public class JdbcPollingChannelAdapterParserTests {
private MessageChannelTemplate channelTemplate;
private ConfigurableApplicationContext appCtx;
private PlatformTransactionManager transactionManager;
@Test
public void testSimpleInboundChannelAdapter(){
@@ -90,6 +96,24 @@ public class JdbcPollingChannelAdapterParserTests {
assertNotNull(message);
}
@Test
public void testMaxRowsInboundChannelAdapter(){
setUp("pollingWithMaxRowsJdbcInboundChannelAdapterTest.xml", getClass());
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
public Void doInTransaction(TransactionStatus status) {
jdbcTemplate.update("insert into item values(1,'',2)");
jdbcTemplate.update("insert into item values(2,'',2)");
jdbcTemplate.update("insert into item values(3,'',2)");
jdbcTemplate.update("insert into item values(4,'',2)");
return null;
}
});
@SuppressWarnings("unchecked")
Message<List<?>> message = (Message<List<?>>) channelTemplate.receive();
assertNotNull(message);
assertEquals(2, message.getPayload().size());
}
@After
public void tearDown(){
if(appCtx != null){
@@ -100,6 +124,8 @@ public class JdbcPollingChannelAdapterParserTests {
public void setUp(String name, Class<?> cls){
appCtx = new ClassPathXmlApplicationContext(name, cls);
setupJdbcTemplate();
jdbcTemplate.update("delete from item");
setupTransactionManager();
setupMessageChannelTemplate();
}
@@ -114,6 +140,10 @@ public class JdbcPollingChannelAdapterParserTests {
this.jdbcTemplate = new SimpleJdbcTemplate(this.appCtx.getBean("dataSource",DataSource.class));
}
protected void setupTransactionManager(){
this.transactionManager = this.appCtx.getBean("transactionManager",PlatformTransactionManager.class);
}
public static class TestSqlParameterSource extends AbstractSqlParameterSource {
public Object getValue(String paramName)

View File

@@ -10,7 +10,7 @@
<si:queue />
</si:channel>
<si:poller default="true">
<si:poller default="true" task-executor="taskExecutor">
<si:interval-trigger interval="100" />
</si:poller>
@@ -18,6 +18,10 @@
<jdbc:script location="org/springframework/integration/jdbc/config/inboundSchema.sql" />
</jdbc:embedded-database>
<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor">
<property name="concurrencyLimit" value="1"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/jdbc"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/jdbc
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
<inbound-channel-adapter query="select * from item where status=2"
channel="target" data-source="dataSource" max-rows-per-poll="2"
update="update item set status=10 where id in (:idList)" />
<beans:import resource="jdbcInboundChannelAdapterCommonConfig.xml" />
</beans:beans>