Upgrade to SD-Hopper and other fixes
Fixes https://build.spring.io/browse/INT-MJATS41-593 * Fix `LoggingHandler` JavaDoc * Fix `JdbcOutboundGatewayParserTests` timing and race condition issues * Add `mock(BeanFactory.class)` to the `JpaOutboundChannelAdapterTests` for `JpaExecutor` * Fix `JpaOutboundChannelAdapterTests` for the incorrect transaction usage
This commit is contained in:
committed by
Gary Russell
parent
ba2a713c75
commit
13d11e5035
@@ -33,7 +33,6 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
@@ -73,21 +72,23 @@ public class JdbcOutboundGatewayParserTests {
|
||||
@Test
|
||||
public void testMapPayloadMapReply() {
|
||||
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
assertTrue(context.containsBean("jdbcGateway"));
|
||||
assertTrue(this.context.containsBean("jdbcGateway"));
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
assertEquals("bar", payload.get("name"));
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
|
||||
JdbcOutboundGateway gateway = context.getBean("jdbcGateway.handler", JdbcOutboundGateway.class);
|
||||
assertEquals(23, TestUtils.getPropertyValue(gateway, "order"));
|
||||
Assert.assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
|
||||
Object gw = context.getBean("jdbcGateway");
|
||||
assertEquals(1, adviceCalled);
|
||||
}
|
||||
|
||||
@@ -96,12 +97,16 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testKeyGeneration() {
|
||||
setUp("handlingKeyGenerationJdbcOutboundGatewayTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
Object id = payload.get("SCOPE_IDENTITY()");
|
||||
assertNotNull(id);
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BARS");
|
||||
assertEquals("Wrong id", id, map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
@@ -110,7 +115,7 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
MessageChannel setterRequest = this.context.getBean("setterRequest", MessageChannel.class);
|
||||
setterRequest.send(new GenericMessage<String>("bar2"));
|
||||
reply = messagingTemplate.receive();
|
||||
reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
|
||||
payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -125,8 +130,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testCountUpdates() {
|
||||
setUp("handlingCountUpdatesJdbcOutboundGatewayTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -137,37 +144,33 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testWithPoller() throws Exception {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
MessageChannel target = context.getBean("target", MessageChannel.class);
|
||||
PollableChannel output = context.getBean("output", PollableChannel.class);
|
||||
target.send(message);
|
||||
Thread.sleep(1000);
|
||||
Map<String, Object> map = (context.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from BAZZ");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
Message<?> reply = output.receive(1000);
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
assertEquals("bar", payload.get("name"));
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BAZZ");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSelectQueryOnly() throws Exception {
|
||||
this.context = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithSelectTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Integer.valueOf(100)).build();
|
||||
MessageChannel requestChannel = context.getBean("request", MessageChannel.class);
|
||||
PollableChannel replyChannel = context.getBean("reply", PollableChannel.class);
|
||||
setUp("JdbcOutboundGatewayWithSelectTest-context.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(100).build();
|
||||
|
||||
requestChannel.send(message);
|
||||
Thread.sleep(1000);
|
||||
this.channel.send(message);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<Map<String, Object>> reply = (Message<Map<String, Object>>) replyChannel.receive(500);
|
||||
Message<Map<String, Object>> reply = (Message<Map<String, Object>>) this.messagingTemplate.receive();
|
||||
|
||||
String id = (String) reply.getPayload().get("id");
|
||||
Integer status = (Integer) reply.getPayload().get("status");
|
||||
String name = (String) reply.getPayload().get("name");
|
||||
ApplicationContext ac = this.context;
|
||||
|
||||
assertEquals("100", id);
|
||||
assertEquals(Integer.valueOf(3), status);
|
||||
@@ -175,7 +178,7 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyTimeoutIsSet() throws Exception {
|
||||
public void testReplyTimeoutIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
|
||||
|
||||
PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
|
||||
@@ -195,11 +198,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
public void testDefaultMaxMessagesPerPollIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
@@ -212,11 +214,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
public void testMaxMessagesPerPollIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPoller2Test-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
@@ -225,25 +226,24 @@ public class JdbcOutboundGatewayParserTests {
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
|
||||
assertEquals("maxRowsPerPoll should default to 10", Integer.valueOf(10), maxRowsPerPoll);
|
||||
|
||||
}
|
||||
|
||||
@Test //INT-1029
|
||||
public void testOutboundGatewayInsideChain() {
|
||||
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
|
||||
JdbcOutboundGateway jdbcMessageHandler =
|
||||
context.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child.jdbc-outbound-gateway-within-chain.handler",
|
||||
JdbcOutboundGateway.class);
|
||||
String beanName = "org.springframework.integration.handler.MessageHandlerChain#" +
|
||||
"0$child.jdbc-outbound-gateway-within-chain.handler";
|
||||
JdbcOutboundGateway jdbcMessageHandler = this.context.getBean(beanName, JdbcOutboundGateway.class);
|
||||
|
||||
MessageChannel channel = context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
|
||||
MessageChannel channel = this.context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
|
||||
|
||||
assertFalse(TestUtils.getPropertyValue(jdbcMessageHandler, "requiresReply", Boolean.class));
|
||||
|
||||
channel.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build());
|
||||
|
||||
PollableChannel outbound = context.getBean("replyChannel", PollableChannel.class);
|
||||
Message<?> reply = outbound.receive();
|
||||
PollableChannel outbound = this.context.getBean("replyChannel", PollableChannel.class);
|
||||
Message<?> reply = outbound.receive(10000);
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -253,8 +253,8 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,13 +262,13 @@ public class JdbcOutboundGatewayParserTests {
|
||||
PollableChannel pollableChannel = this.context.getBean("output", PollableChannel.class);
|
||||
this.messagingTemplate = new MessagingTemplate();
|
||||
this.messagingTemplate.setDefaultDestination(pollableChannel);
|
||||
this.messagingTemplate.setReceiveTimeout(500);
|
||||
this.messagingTemplate.setReceiveTimeout(10000);
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls) {
|
||||
context = new ClassPathXmlApplicationContext(name, cls);
|
||||
jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource", DataSource.class));
|
||||
channel = this.context.getBean("target", MessageChannel.class);
|
||||
this.context = new ClassPathXmlApplicationContext(name, cls);
|
||||
this.jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource", DataSource.class));
|
||||
this.channel = this.context.getBean("target", MessageChannel.class);
|
||||
setupMessagingTemplate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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
|
||||
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
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
|
||||
<int:channel id="target">
|
||||
@@ -15,26 +15,28 @@
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="output">
|
||||
<int:queue />
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway" query="select * from bazz where id=:headers[id]" update="insert into bazz (id, status, name) values (:headers[id], 0, :payload[foo])"
|
||||
request-channel="target" reply-channel="output" data-source="dataSource" auto-startup="true" reply-timeout="444">
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway"
|
||||
query="select * from bazz where id=:headers[id]"
|
||||
update="insert into bazz (id, status, name) values (:headers[id], 0, :payload[foo])"
|
||||
request-channel="target"
|
||||
reply-channel="output"
|
||||
data-source="dataSource"
|
||||
auto-startup="true"
|
||||
reply-timeout="444">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</int-jdbc:outbound-gateway>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchema.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchema.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,36 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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
|
||||
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
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
|
||||
<int:channel id="request"/>
|
||||
<int:channel id="reply">
|
||||
<int:channel id="target"/>
|
||||
|
||||
<int:channel id="output">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway" query="select * from bazz where id=:payload"
|
||||
request-channel="request" reply-channel="reply" data-source="dataSource" auto-startup="true" reply-timeout="444">
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway"
|
||||
query="select * from bazz where id=:payload"
|
||||
request-channel="target"
|
||||
reply-channel="output"
|
||||
data-source="dataSource"
|
||||
auto-startup="true"
|
||||
reply-timeout="444">
|
||||
</int-jdbc:outbound-gateway>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchemaWithData.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchemaWithData.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
<constructor-arg ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user