Fix JdbcMessageStoreChannelTests race condition
The message in the `QueueChannel` appears for consuming a bit earlier than TX is committed * Introduce `afterCommitLatch` into the test verify the state when TX is really committed and data is removed from DB **Cherry-pick to 5.0.x and 4.3.x**
This commit is contained in:
@@ -5,45 +5,42 @@
|
|||||||
xmlns:int="http://www.springframework.org/schema/integration"
|
xmlns:int="http://www.springframework.org/schema/integration"
|
||||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
|
||||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
|
|
||||||
<jdbc:embedded-database id="dataSource" type="DERBY" />
|
<jdbc:embedded-database id="dataSource" type="H2" />
|
||||||
|
|
||||||
<jdbc:initialize-database data-source="dataSource">
|
<jdbc:initialize-database data-source="dataSource">
|
||||||
<jdbc:script location="${int.schema.script}" />
|
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql" />
|
||||||
</jdbc:initialize-database>
|
</jdbc:initialize-database>
|
||||||
|
|
||||||
<int-jdbc:message-store id="messageStore" data-source="dataSource" />
|
<int-jdbc:message-store id="messageStore" data-source="dataSource" />
|
||||||
|
|
||||||
<channel id="input" xmlns="http://www.springframework.org/schema/integration">
|
<int:channel id="input">
|
||||||
<queue ref="queue"/>
|
<int:queue ref="queue"/>
|
||||||
</channel>
|
</int:channel>
|
||||||
|
|
||||||
<int:channel id="output"/>
|
|
||||||
|
|
||||||
<int:logging-channel-adapter channel="output"/>
|
|
||||||
|
|
||||||
<bean id="queue" class="org.springframework.integration.store.MessageGroupQueue">
|
<bean id="queue" class="org.springframework.integration.store.MessageGroupQueue">
|
||||||
<constructor-arg ref="messageStore" />
|
<constructor-arg ref="messageStore" />
|
||||||
<constructor-arg value="JdbcMessageStoreChannelTests" />
|
<constructor-arg value="JdbcMessageStoreChannelTests" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<service-activator id="service-activator" input-channel="input" output-channel="output" xmlns="http://www.springframework.org/schema/integration">
|
<int:service-activator id="service-activator" input-channel="input" output-channel="nullChannel">
|
||||||
<beans:bean class="org.springframework.integration.jdbc.store.JdbcMessageStoreChannelTests$Service" />
|
<beans:bean class="org.springframework.integration.jdbc.store.JdbcMessageStoreChannelTests$Service" />
|
||||||
<poller fixed-rate="2000">
|
<int:poller fixed-rate="2000">
|
||||||
<transactional />
|
<int:transactional synchronization-factory="transactionSynchronizationFactory"/>
|
||||||
</poller>
|
</int:poller>
|
||||||
</service-activator>
|
</int:service-activator>
|
||||||
|
|
||||||
<context:property-placeholder location="int-${ENVIRONMENT:derby}.properties"
|
<int:transaction-synchronization-factory id="transactionSynchronizationFactory">
|
||||||
system-properties-mode="OVERRIDE"
|
<int:after-commit expression="@afterCommitLatch.countDown()"/>
|
||||||
ignore-unresolvable="true"
|
</int:transaction-synchronization-factory>
|
||||||
order="1"/>
|
|
||||||
|
<bean id="afterCommitLatch" class="java.util.concurrent.CountDownLatch">
|
||||||
|
<constructor-arg value="1"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||||
<property name="dataSource" ref="dataSource" />
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.integration.jdbc.store;
|
package org.springframework.integration.jdbc.store;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -58,6 +59,9 @@ public class JdbcMessageStoreChannelTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MessageChannel input;
|
private MessageChannel input;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CountDownLatch afterCommitLatch;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcMessageStore messageStore;
|
private JdbcMessageStore messageStore;
|
||||||
|
|
||||||
@@ -65,6 +69,7 @@ public class JdbcMessageStoreChannelTests {
|
|||||||
@Qualifier("service-activator")
|
@Qualifier("service-activator")
|
||||||
private AbstractEndpoint serviceActivator;
|
private AbstractEndpoint serviceActivator;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
Service.reset(1);
|
Service.reset(1);
|
||||||
@@ -84,9 +89,9 @@ public class JdbcMessageStoreChannelTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendAndActivate() throws Exception {
|
public void testSendAndActivate() throws InterruptedException {
|
||||||
input.send(new GenericMessage<>("foo"));
|
this.input.send(new GenericMessage<>("foo"));
|
||||||
Service.await(10000);
|
assertTrue(this.afterCommitLatch.await(10, TimeUnit.SECONDS));
|
||||||
assertEquals(1, Service.messages.size());
|
assertEquals(1, Service.messages.size());
|
||||||
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
|
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user