Fix JdbcMessageStoreChannelTests imports
https://build.spring.io/browse/INT-SI43X-259
This commit is contained in:
@@ -10,26 +10,23 @@
|
||||
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">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2" />
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql"/>
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="${int.drop.script}" />
|
||||
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<int-jdbc:message-store id="messageStore" data-source="dataSource" />
|
||||
<int-jdbc:message-store id="messageStore" data-source="dataSource"/>
|
||||
|
||||
<int:channel id="input">
|
||||
<int:queue ref="queue"/>
|
||||
</int:channel>
|
||||
|
||||
<bean id="queue" class="org.springframework.integration.store.MessageGroupQueue">
|
||||
<constructor-arg ref="messageStore" />
|
||||
<constructor-arg value="JdbcMessageStoreChannelTests" />
|
||||
<constructor-arg ref="messageStore"/>
|
||||
<constructor-arg value="JdbcMessageStoreChannelTests"/>
|
||||
</bean>
|
||||
|
||||
<int:service-activator id="service-activator" input-channel="input" output-channel="nullChannel">
|
||||
<beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service" />
|
||||
<beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service"/>
|
||||
<int:poller fixed-rate="2000">
|
||||
<int:transactional synchronization-factory="transactionSynchronizationFactory"/>
|
||||
</int:poller>
|
||||
@@ -44,7 +41,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,12 +25,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -38,6 +43,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@@ -85,9 +98,8 @@ public class JdbcMessageStoreChannelTests {
|
||||
|
||||
@Test
|
||||
public void testSendAndActivateWithRollback() throws Exception {
|
||||
Service.reset(1);
|
||||
Service.fail = true;
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
input.send(new GenericMessage<>("foo"));
|
||||
Service.await(10000);
|
||||
assertEquals(1, Service.messages.size());
|
||||
// After a rollback in the poller the message is still waiting to be delivered
|
||||
@@ -95,13 +107,12 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Transactional(timeout = 1)
|
||||
public void testSendAndActivateTransactionalSend() throws Exception {
|
||||
Service.reset(1);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
input.send(new GenericMessage<>("foo"));
|
||||
// This will time out because the transaction has not committed yet
|
||||
try {
|
||||
Service.await(10000);
|
||||
Service.await(10);
|
||||
fail("Expected timeout");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -114,21 +125,28 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
|
||||
public static class Service {
|
||||
|
||||
private static boolean fail = false;
|
||||
|
||||
private static boolean alreadyFailed = false;
|
||||
private static List<String> messages = new CopyOnWriteArrayList<String>();
|
||||
|
||||
private static List<String> messages = new CopyOnWriteArrayList<>();
|
||||
|
||||
private static CountDownLatch latch = new CountDownLatch(0);
|
||||
|
||||
public static void reset(int count) {
|
||||
fail = false;
|
||||
alreadyFailed = false;
|
||||
messages.clear();
|
||||
latch = new CountDownLatch(count);
|
||||
}
|
||||
|
||||
public static void await(long timeout) throws InterruptedException {
|
||||
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
|
||||
throw new IllegalStateException("Timed out waiting for message");
|
||||
}
|
||||
}
|
||||
|
||||
public String echo(String input) {
|
||||
if (!alreadyFailed) {
|
||||
messages.add(input);
|
||||
@@ -140,6 +158,7 @@ public class JdbcMessageStoreChannelTests {
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user