Skip to content

Commit 0119e6e

Browse files
committed
Fix JdbcMessageStoreChannelTests imports
https://build.spring.io/browse/INT-SI43X-259
1 parent fa3935d commit 0119e6e

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@
1010
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
1111
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
1212

13-
<jdbc:embedded-database id="dataSource" type="H2" />
13+
<jdbc:embedded-database id="dataSource" type="H2">
14+
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql"/>
15+
</jdbc:embedded-database>
1416

15-
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
16-
<jdbc:script location="${int.drop.script}" />
17-
<jdbc:script location="org/springframework/integration/jdbc/schema-h2.sql" />
18-
</jdbc:initialize-database>
19-
20-
<int-jdbc:message-store id="messageStore" data-source="dataSource" />
17+
<int-jdbc:message-store id="messageStore" data-source="dataSource"/>
2118

2219
<int:channel id="input">
2320
<int:queue ref="queue"/>
2421
</int:channel>
2522

2623
<bean id="queue" class="org.springframework.integration.store.MessageGroupQueue">
27-
<constructor-arg ref="messageStore" />
28-
<constructor-arg value="JdbcMessageStoreChannelTests" />
24+
<constructor-arg ref="messageStore"/>
25+
<constructor-arg value="JdbcMessageStoreChannelTests"/>
2926
</bean>
3027

3128
<int:service-activator id="service-activator" input-channel="input" output-channel="nullChannel">
32-
<beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service" />
29+
<beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service"/>
3330
<int:poller fixed-rate="2000">
3431
<int:transactional synchronization-factory="transactionSynchronizationFactory"/>
3532
</int:poller>
@@ -44,7 +41,7 @@
4441
</bean>
4542

4643
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
47-
<property name="dataSource" ref="dataSource" />
44+
<property name="dataSource" ref="dataSource"/>
4845
</bean>
4946

5047
</beans>

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,19 +25,32 @@
2525
import java.util.concurrent.CountDownLatch;
2626
import java.util.concurrent.TimeUnit;
2727

28+
import org.junit.After;
29+
import org.junit.Before;
2830
import org.junit.Test;
2931
import org.junit.runner.RunWith;
32+
3033
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.beans.factory.annotation.Qualifier;
35+
import org.springframework.integration.endpoint.AbstractEndpoint;
36+
import org.springframework.integration.store.MessageGroup;
3137
import org.springframework.messaging.MessageChannel;
3238
import org.springframework.messaging.support.GenericMessage;
33-
import org.springframework.integration.store.MessageGroup;
3439
import org.springframework.test.annotation.DirtiesContext;
3540
import org.springframework.test.annotation.DirtiesContext.ClassMode;
3641
import org.springframework.test.context.ContextConfiguration;
3742
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3843
import org.springframework.test.context.transaction.BeforeTransaction;
3944
import org.springframework.transaction.annotation.Transactional;
4045

46+
/**
47+
* @author Dave Syer
48+
* @author Mark Fisher
49+
* @author Oleg Zhurakousky
50+
* @author Gary Russell
51+
* @author Artem Bilan
52+
*/
53+
4154
@ContextConfiguration
4255
@RunWith(SpringJUnit4ClassRunner.class)
4356
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@@ -85,23 +98,21 @@ public void testSendAndActivate() throws InterruptedException {
8598

8699
@Test
87100
public void testSendAndActivateWithRollback() throws Exception {
88-
Service.reset(1);
89101
Service.fail = true;
90-
input.send(new GenericMessage<String>("foo"));
102+
input.send(new GenericMessage<>("foo"));
91103
Service.await(10000);
92104
assertEquals(1, Service.messages.size());
93105
// After a rollback in the poller the message is still waiting to be delivered
94106
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
95107
}
96108

97109
@Test
98-
@Transactional
110+
@Transactional(timeout = 1)
99111
public void testSendAndActivateTransactionalSend() throws Exception {
100-
Service.reset(1);
101-
input.send(new GenericMessage<String>("foo"));
112+
input.send(new GenericMessage<>("foo"));
102113
// This will time out because the transaction has not committed yet
103114
try {
104-
Service.await(10000);
115+
Service.await(10);
105116
fail("Expected timeout");
106117
}
107118
catch (IllegalStateException e) {
@@ -114,21 +125,28 @@ public void testSendAndActivateTransactionalSend() throws Exception {
114125
}
115126

116127
public static class Service {
128+
117129
private static boolean fail = false;
130+
118131
private static boolean alreadyFailed = false;
119-
private static List<String> messages = new CopyOnWriteArrayList<String>();
132+
133+
private static List<String> messages = new CopyOnWriteArrayList<>();
134+
120135
private static CountDownLatch latch = new CountDownLatch(0);
136+
121137
public static void reset(int count) {
122138
fail = false;
123139
alreadyFailed = false;
124140
messages.clear();
125141
latch = new CountDownLatch(count);
126142
}
143+
127144
public static void await(long timeout) throws InterruptedException {
128145
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
129146
throw new IllegalStateException("Timed out waiting for message");
130147
}
131148
}
149+
132150
public String echo(String input) {
133151
if (!alreadyFailed) {
134152
messages.add(input);
@@ -140,6 +158,7 @@ public String echo(String input) {
140158
}
141159
return input;
142160
}
161+
143162
}
144163

145164
}

0 commit comments

Comments
 (0)