Skip to content

Commit 27318c7

Browse files
artembilangaryrussell
authored andcommitted
INT-4445: Fix JDBC tests for Derby
JIRA: https://jira.spring.io/browse/INT-4445 Looks like `/dataSource` temporary directory is busy in between different tests. The thought is like a high-frequently polling endpoint keeps DB resource from removing. * Explicitly `stop()` endpoint in the `JdbcMessageStoreChannelTests` * Optimize `JdbcMessageStoreChannelTests.testSendAndActivateTransactionalSend()` to rely on the short `1` millisecond TX timeout. This safes for us 10 seconds of the tests executions. * Configure all the embedded DB beans for the `ignore-failures="ALL"` as a fallback option if polling endpoint is not a cause of the concurrent resource access. **Cherry-pick to 5.0.x**
1 parent af58fa4 commit 27318c7

8 files changed

+49
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<jdbc:embedded-database id="dataSource" type="DERBY"/>
2222

2323
<jdbc:initialize-database data-source="dataSource"
24-
ignore-failures="DROPS">
24+
ignore-failures="ALL">
2525
<jdbc:script location="${int.drop.script}"/>
2626
<jdbc:script location="${int.schema.script}"/>
2727
</jdbc:initialize-database>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<jdbc:embedded-database id="dataSource" type="DERBY"/>
1111

12-
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
12+
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
1313
<jdbc:script location="${int.drop.script}"/>
1414
<jdbc:script location="${int.schema.script}"/>
1515
</jdbc:initialize-database>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<jdbc:embedded-database id="dataSource" type="DERBY"/>
1818

19-
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
19+
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
2020
<jdbc:script location="${int.drop.script}"/>
2121
<jdbc:script location="${int.schema.script}"/>
2222
</jdbc:initialize-database>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<jdbc:embedded-database id="dataSource" type="DERBY" />
1717

1818
<jdbc:initialize-database data-source="dataSource"
19-
ignore-failures="DROPS">
19+
ignore-failures="ALL">
2020
<jdbc:script location="${int.drop.script}" />
2121
<jdbc:script location="${int.schema.script}" />
2222
</jdbc:initialize-database>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<jdbc:embedded-database id="dataSource" type="DERBY" />
1616

17-
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
17+
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
1818
<jdbc:script location="${int.drop.script}" />
1919
<jdbc:script location="${int.schema.script}" />
2020
</jdbc:initialize-database>

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

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -24,10 +24,14 @@
2424
import java.util.concurrent.CountDownLatch;
2525
import java.util.concurrent.TimeUnit;
2626

27+
import org.junit.After;
28+
import org.junit.Before;
2729
import org.junit.Test;
2830
import org.junit.runner.RunWith;
2931

3032
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.beans.factory.annotation.Qualifier;
34+
import org.springframework.integration.endpoint.AbstractEndpoint;
3135
import org.springframework.integration.store.MessageGroup;
3236
import org.springframework.messaging.MessageChannel;
3337
import org.springframework.messaging.support.GenericMessage;
@@ -38,6 +42,14 @@
3842
import org.springframework.test.context.transaction.BeforeTransaction;
3943
import org.springframework.transaction.annotation.Transactional;
4044

45+
/**
46+
* @author Dave Syer
47+
* @author Mark Fisher
48+
* @author Oleg Zhurakousky
49+
* @author Gary Russell
50+
* @author Artem Bilan
51+
*/
52+
4153
@ContextConfiguration
4254
@RunWith(SpringJUnit4ClassRunner.class)
4355
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@@ -49,6 +61,21 @@ public class JdbcMessageStoreChannelTests {
4961
@Autowired
5062
private JdbcMessageStore messageStore;
5163

64+
@Autowired
65+
@Qualifier("service-activator")
66+
private AbstractEndpoint serviceActivator;
67+
68+
@Before
69+
public void init() {
70+
Service.reset(1);
71+
this.serviceActivator.start();
72+
}
73+
74+
@After
75+
public void tearDown() {
76+
this.serviceActivator.stop();
77+
}
78+
5279
@BeforeTransaction
5380
public void clear() {
5481
for (MessageGroup group : messageStore) {
@@ -58,32 +85,29 @@ public void clear() {
5885

5986
@Test
6087
public void testSendAndActivate() throws Exception {
61-
Service.reset(1);
62-
input.send(new GenericMessage<String>("foo"));
88+
input.send(new GenericMessage<>("foo"));
6389
Service.await(10000);
6490
assertEquals(1, Service.messages.size());
6591
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
6692
}
6793

6894
@Test
6995
public void testSendAndActivateWithRollback() throws Exception {
70-
Service.reset(1);
7196
Service.fail = true;
72-
input.send(new GenericMessage<String>("foo"));
97+
input.send(new GenericMessage<>("foo"));
7398
Service.await(10000);
7499
assertEquals(1, Service.messages.size());
75100
// After a rollback in the poller the message is still waiting to be delivered
76101
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
77102
}
78103

79104
@Test
80-
@Transactional
105+
@Transactional(timeout = 1)
81106
public void testSendAndActivateTransactionalSend() throws Exception {
82-
Service.reset(1);
83-
input.send(new GenericMessage<String>("foo"));
107+
input.send(new GenericMessage<>("foo"));
84108
// This will time out because the transaction has not committed yet
85109
try {
86-
Service.await(10000);
110+
Service.await(10);
87111
fail("Expected timeout");
88112
}
89113
catch (IllegalStateException e) {
@@ -96,21 +120,28 @@ public void testSendAndActivateTransactionalSend() throws Exception {
96120
}
97121

98122
public static class Service {
123+
99124
private static boolean fail = false;
125+
100126
private static boolean alreadyFailed = false;
101-
private static List<String> messages = new CopyOnWriteArrayList<String>();
127+
128+
private static List<String> messages = new CopyOnWriteArrayList<>();
129+
102130
private static CountDownLatch latch = new CountDownLatch(0);
131+
103132
public static void reset(int count) {
104133
fail = false;
105134
alreadyFailed = false;
106135
messages.clear();
107136
latch = new CountDownLatch(count);
108137
}
138+
109139
public static void await(long timeout) throws InterruptedException {
110140
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
111141
throw new IllegalStateException("Timed out waiting for message");
112142
}
113143
}
144+
114145
public String echo(String input) {
115146
if (!alreadyFailed) {
116147
messages.add(input);
@@ -122,6 +153,7 @@ public String echo(String input) {
122153
}
123154
return input;
124155
}
156+
125157
}
126158

127159
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<jdbc:embedded-database id="dataSource" type="DERBY"/>
1111

12-
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
12+
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
1313
<jdbc:script location="${int.drop.script}"/>
1414
<jdbc:script location="${int.schema.script}"/>
1515
</jdbc:initialize-database>

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DataSource-derby-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/> <property name="username" value="int" /> <property name="password" value="int"
1717
/> </bean> -->
1818

19-
<jdbc:initialize-database data-source="dataSource">
19+
<jdbc:initialize-database data-source="dataSource" ignore-failures="ALL">
2020
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-derby.sql" />
2121
</jdbc:initialize-database>
2222

0 commit comments

Comments
 (0)