Skip to content

Commit 01db420

Browse files
authored
GH-10045: Enable JDBC test cases with TestContainers approach
Fixes: #10045 Signed-off-by: Jiandong Ma <[email protected]>
1 parent 8ff3fbd commit 01db420

16 files changed

+97
-68
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
<tx:annotation-driven/>
2020
<int:annotation-config/>
2121

22-
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
23-
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
24-
<property name="url" value="jdbc:mysql://localhost:3306/int30"/>
25-
<property name="username" value="root"/>
26-
<property name="password" value="root"/>
27-
<property name="maxActive" value="10"/>
28-
<property name="defaultAutoCommit" value="false"/>
29-
</bean>
22+
<bean id="dataSource" class="org.springframework.integration.jdbc.mysql.MySqlContainerTest"
23+
factory-method="dataSource"/>
24+
25+
<jdbc:initialize-database>
26+
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-drop-mysql.sql" />
27+
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-mysql.sql" />
28+
</jdbc:initialize-database>
3029

3130
<int-jdbc:message-store id="messageStore" data-source="dataSource" region="MessageStoreMultipleChannelTests"/>
3231

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreMultipleChannelTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.commons.logging.LogFactory;
2929
import org.junit.jupiter.api.AfterEach;
3030
import org.junit.jupiter.api.BeforeEach;
31-
import org.junit.jupiter.api.Disabled;
3231
import org.junit.jupiter.api.Test;
3332

3433
import org.springframework.beans.factory.annotation.Autowired;
@@ -55,8 +54,7 @@
5554
*/
5655
@SpringJUnitConfig
5756
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
58-
@Disabled
59-
public class MySqlJdbcMessageStoreMultipleChannelTests {
57+
public class MySqlJdbcMessageStoreMultipleChannelTests implements MySqlContainerTest {
6058

6159
private static final Log LOG = LogFactory.getLog(MySqlJdbcMessageStoreMultipleChannelTests.class);
6260

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -545,8 +545,7 @@ PlatformTransactionManager transactionManager() {
545545
DataSourceInitializer dataSourceInitializer() {
546546
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
547547
dataSourceInitializer.setDataSource(dataSource());
548-
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(this.createSchemaScript));
549-
dataSourceInitializer.setDatabaseCleaner(new ResourceDatabasePopulator(this.dropSchemaScript));
548+
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(this.dropSchemaScript, this.createSchemaScript));
550549
return dataSourceInitializer;
551550
}
552551

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlMetadataStoreTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 the original author or authors.
2+
* Copyright 2024-2025 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.
@@ -75,6 +75,9 @@ static class TestConfiguration {
7575
@Value("org/springframework/integration/jdbc/schema-mysql.sql")
7676
Resource createSchemaScript;
7777

78+
@Value("org/springframework/integration/jdbc/schema-drop-mysql.sql")
79+
Resource dropSchemaScript;
80+
7881
@Bean
7982
DataSource dataSource() {
8083
return MySqlContainerTest.dataSource();
@@ -84,7 +87,7 @@ DataSource dataSource() {
8487
DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
8588
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
8689
dataSourceInitializer.setDataSource(dataSource);
87-
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(this.createSchemaScript));
90+
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(this.dropSchemaScript, this.createSchemaScript));
8891
return dataSourceInitializer;
8992
}
9093

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/postgres/PostgresContainerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 the original author or authors.
2+
* Copyright 2022-2025 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.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.integration.jdbc.postgres;
1818

19+
import javax.sql.DataSource;
20+
21+
import org.apache.commons.dbcp2.BasicDataSource;
1922
import org.junit.jupiter.api.BeforeAll;
2023
import org.testcontainers.containers.PostgreSQLContainer;
2124
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -60,4 +63,13 @@ static String getPassword() {
6063
return POSTGRES_CONTAINER.getPassword();
6164
}
6265

66+
static DataSource dataSource() {
67+
BasicDataSource dataSource = new BasicDataSource();
68+
dataSource.setDriverClassName(POSTGRES_CONTAINER.getDriverClassName());
69+
dataSource.setUrl(POSTGRES_CONTAINER.getJdbcUrl());
70+
dataSource.setUsername(POSTGRES_CONTAINER.getUsername());
71+
dataSource.setPassword(POSTGRES_CONTAINER.getPassword());
72+
return dataSource;
73+
}
74+
6375
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
@DirtiesContext // close at the end after class
6464
public abstract class AbstractTxTimeoutMessageStoreTests {
6565

66-
private static final Log log = LogFactory.getLog(AbstractTxTimeoutMessageStoreTests.class);
66+
protected final Log log = LogFactory.getLog(this.getClass());
6767

6868
@Autowired
6969
protected DataSource dataSource;

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
54
xsi:schemaLocation="
6-
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd
75
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
86

97
<import resource="classpath:org/springframework/integration/jdbc/store/channel/DataSource-common-context.xml" />
108

11-
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
12-
<property name="connectionCachingEnabled" value="true" />
13-
<property name="URL" value="jdbc:oracle:thin:@//[HOST]:1521/XE" />
14-
<property name="user" value="[USER]" />
15-
<property name="password" value="[PASSWORD]" />
16-
<property name="connectionCacheProperties">
17-
<props merge="default">
18-
<prop key="MinLimit">3</prop>
19-
<prop key="MaxLimit">20</prop>
20-
</props>
21-
</property>
22-
</bean>
9+
<bean id="dataSource" class="org.springframework.integration.jdbc.oracle.OracleContainerTest"
10+
factory-method="dataSource"/>
2311

2412
<bean id="queryProvider" class="org.springframework.integration.jdbc.store.channel.OracleChannelMessageStoreQueryProvider"/>
2513

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
5-
xsi:schemaLocation="
6-
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd
7-
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
87

98
<import resource="classpath:org/springframework/integration/jdbc/store/channel/DataSource-common-context.xml" />
109

11-
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
12-
destroy-method="close">
13-
<property name="driverClassName" value="org.postgresql.Driver" />
14-
<property name="initialSize" value="10"/>
15-
<property name="url"
16-
value="jdbc:postgresql:integration" />
17-
<property name="username" value="postgres" />
18-
<property name="password" value="postgres" />
19-
</bean>
10+
<bean id="dataSource" class="org.springframework.integration.jdbc.postgres.PostgresContainerTest"
11+
factory-method="dataSource" />
12+
13+
<jdbc:initialize-database>
14+
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-drop-postgresql.sql" />
15+
<jdbc:script location="classpath:org/springframework/integration/jdbc/schema-postgresql.sql" />
16+
</jdbc:initialize-database>
2017

2118
<bean id="queryProvider" class="org.springframework.integration.jdbc.store.channel.PostgresChannelMessageStoreQueryProvider"/>
2219

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
7+
8+
<util:properties id="props">
9+
<prop key="concurrentPoll.fixedRate">2000</prop>
10+
<prop key="concurrentPoll.fixedDelay">1000</prop>
11+
</util:properties>
512

613
<import resource="classpath:org/springframework/integration/jdbc/store/channel/DataSource-hsql-context.xml"/>
714

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,9 +16,7 @@
1616

1717
package org.springframework.integration.jdbc.store.channel;
1818

19-
import org.junit.Rule;
20-
21-
import org.springframework.integration.test.support.LongRunningIntegrationTest;
19+
import org.springframework.integration.test.condition.LongRunningTest;
2220
import org.springframework.test.context.ContextConfiguration;
2321

2422
/**
@@ -27,10 +25,8 @@
2725
* @author Artem Bilan
2826
*
2927
*/
28+
@LongRunningTest
3029
@ContextConfiguration
3130
public class HsqlTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests {
3231

33-
@Rule
34-
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
35-
3632
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
57

68
<import resource="classpath:org/springframework/integration/jdbc/store/channel/DataSource-mysql-context.xml"/>
79

810
<import resource="classpath:org/springframework/integration/jdbc/store/channel/TxTimeoutMessageStoreTests-context.xml"/>
911

12+
<util:properties id="props">
13+
<prop key="concurrentPoll.fixedRate">2000</prop>
14+
<prop key="concurrentPoll.fixedDelay">1000</prop>
15+
</util:properties>
16+
1017
</beans>
1118

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.jdbc.store.channel;
1818

19-
import org.junit.jupiter.api.Disabled;
20-
19+
import org.springframework.integration.jdbc.mysql.MySqlContainerTest;
2120
import org.springframework.test.context.ContextConfiguration;
2221

2322
/**
@@ -26,8 +25,7 @@
2625
* @author Artem Bilan
2726
*
2827
*/
29-
@Disabled
3028
@ContextConfiguration
31-
public class MySqlTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests {
29+
public class MySqlTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests implements MySqlContainerTest {
3230

3331
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
57

68
<import resource="classpath:org/springframework/integration/jdbc/store/channel/DataSource-oracle-context.xml"/>
79

810
<import resource="classpath:org/springframework/integration/jdbc/store/channel/TxTimeoutMessageStoreTests-context.xml"/>
911

12+
<util:properties id="props">
13+
<prop key="concurrentPoll.fixedRate">2000</prop>
14+
<prop key="concurrentPoll.fixedDelay">1000</prop>
15+
</util:properties>
16+
1017
</beans>
1118

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@
1616

1717
package org.springframework.integration.jdbc.store.channel;
1818

19-
import org.junit.jupiter.api.Disabled;
19+
import org.junit.jupiter.api.AfterEach;
2020

21+
import org.springframework.integration.jdbc.oracle.OracleContainerTest;
22+
import org.springframework.jdbc.core.JdbcTemplate;
2123
import org.springframework.test.context.ContextConfiguration;
24+
import org.springframework.transaction.support.TransactionTemplate;
2225

2326
/**
2427
*
2528
* @author Gunnar Hillert
2629
* @author Artem Bilan
2730
*
2831
*/
29-
@Disabled
3032
@ContextConfiguration
31-
public class OracleTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests {
33+
public class OracleTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests implements OracleContainerTest {
34+
35+
@AfterEach
36+
public void cleanTable() {
37+
final JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
38+
new TransactionTemplate(this.transactionManager).execute(status -> {
39+
final int deletedChannelMessageRows = jdbcTemplate.update("delete from INT_CHANNEL_MESSAGE");
40+
log.info(String.format("Cleaning Database - Deleted Channel Messages: %s ",
41+
deletedChannelMessageRows));
42+
return null;
43+
});
44+
}
3245

3346
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.jdbc.store.channel;
1818

19-
import org.junit.jupiter.api.Disabled;
20-
19+
import org.springframework.integration.jdbc.postgres.PostgresContainerTest;
2120
import org.springframework.test.context.ContextConfiguration;
2221

2322
/**
@@ -26,8 +25,7 @@
2625
* @author Artem Bilan
2726
*
2827
*/
29-
@Disabled
3028
@ContextConfiguration
31-
public class PostgresTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests {
29+
public class PostgresTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests implements PostgresContainerTest {
3230

3331
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:task="http://www.springframework.org/schema/task"
55
xmlns:int="http://www.springframework.org/schema/integration"
6+
xmlns:util="http://www.springframework.org/schema/util"
67
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
78
http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd
8-
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
9+
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
10+
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
11+
12+
<util:properties id="props">
13+
<prop key="concurrentPoll.fixedRate">200</prop>
14+
<prop key="concurrentPoll.fixedDelay">100</prop>
15+
</util:properties>
916

1017
<int:transaction-synchronization-factory id="syncFactory">
1118
<int:before-commit expression="@store.removeFromIdCache(headers.id.toString())"/>
@@ -69,7 +76,7 @@
6976
</int:channel>
7077

7178
<int:bridge input-channel="first" output-channel="second">
72-
<int:poller fixed-rate="200" task-executor="threadPoolTaskExecutor" max-messages-per-poll="3">
79+
<int:poller fixed-rate="#{props['concurrentPoll.fixedRate']}" task-executor="threadPoolTaskExecutor" max-messages-per-poll="3">
7380
<int:transactional transaction-manager="transactionManager"/>
7481
</int:poller>
7582
</int:bridge>
@@ -79,7 +86,7 @@
7986
</bean>
8087

8188
<int:outbound-channel-adapter channel="second" expression="@successfulLatch.countDown()">
82-
<int:poller fixed-delay="100">
89+
<int:poller fixed-delay="#{props['concurrentPoll.fixedDelay']}">
8390
<int:transactional transaction-manager="transactionManager"/>
8491
</int:poller>
8592
</int:outbound-channel-adapter>

0 commit comments

Comments
 (0)