Skip to content

Commit 293da56

Browse files
committed
Rationalize JDBC integration tests
This commit reduces the JDBC integration tests to only single (latest) version per RDBMS vendor, due to a growing number of integration tests. Additionally, the configuration of most containers is simplified due to improved defaults within the Testcontainers library.
1 parent e2bab51 commit 293da56

16 files changed

+62
-417
lines changed
Lines changed: 24 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 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.
@@ -17,7 +17,6 @@
1717
package org.springframework.session.jdbc;
1818

1919
import java.time.Duration;
20-
import java.time.temporal.ChronoUnit;
2120

2221
import org.testcontainers.containers.Db2Container;
2322
import org.testcontainers.containers.JdbcDatabaseContainer;
@@ -38,169 +37,42 @@ final class DatabaseContainers {
3837
private DatabaseContainers() {
3938
}
4039

41-
static Db211Container db211() {
42-
return new Db211Container();
40+
static Db2Container db2() {
41+
return new Db2Container("ibmcom/db2:11.5.4.0");
4342
}
4443

45-
static MariaDBContainer mariaDb5() {
46-
return new MariaDb5Container();
44+
static MariaDBContainer<?> mariaDb() {
45+
return new MariaDBContainer<>("mariadb:10.5.7");
4746
}
4847

49-
static MariaDBContainer mariaDb10() {
50-
return new MariaDb10Container();
48+
static MySQLContainer<?> mySql() {
49+
return new MySQLContainer<>("mysql:8.0.22");
5150
}
5251

53-
static MySQLContainer mySql5() {
54-
return new MySql5Container();
55-
}
56-
57-
static MySQLContainer mySql8() {
58-
return new MySql8Container();
59-
}
60-
61-
static OracleXeContainer oracleXe() {
62-
return new OracleXeContainer();
63-
}
64-
65-
static PostgreSQLContainer postgreSql9() {
66-
return new PostgreSql9Container();
67-
}
68-
69-
static PostgreSQLContainer postgreSql10() {
70-
return new PostgreSql10Container();
71-
}
72-
73-
static PostgreSQLContainer postgreSql11() {
74-
return new PostgreSql11Container();
75-
}
76-
77-
static MSSQLServerContainer sqlServer2017() {
78-
return new SqlServer2017Container();
79-
}
80-
81-
private static class Db211Container extends Db2Container {
82-
83-
Db211Container() {
84-
super("ibmcom/db2:11.5.0.0a");
85-
}
86-
87-
}
88-
89-
private static class MariaDb5Container extends MariaDBContainer<MariaDb5Container> {
90-
91-
MariaDb5Container() {
92-
super("mariadb:5.5.64");
93-
}
94-
95-
@Override
96-
protected void configure() {
97-
super.configure();
98-
setCommand("mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci",
99-
"--innodb_large_prefix", "--innodb_file_format=barracuda", "--innodb-file-per-table");
100-
}
101-
102-
}
103-
104-
private static class MariaDb10Container extends MariaDBContainer<MariaDb10Container> {
105-
106-
MariaDb10Container() {
107-
super("mariadb:10.4.8");
108-
}
109-
110-
@Override
111-
protected void configure() {
112-
super.configure();
113-
setCommand("mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci");
114-
}
115-
116-
}
117-
118-
private static class MySql5Container extends MySQLContainer<MySql5Container> {
119-
120-
MySql5Container() {
121-
super("mysql:5.7.27");
122-
}
123-
124-
@Override
125-
protected void configure() {
126-
super.configure();
127-
setCommand("mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci");
128-
}
129-
130-
@Override
131-
public String getDriverClassName() {
132-
return "com.mysql.cj.jdbc.Driver";
133-
}
134-
135-
}
136-
137-
private static class MySql8Container extends MySQLContainer<MySql8Container> {
138-
139-
MySql8Container() {
140-
super("mysql:8.0.17");
141-
}
142-
143-
@Override
144-
protected void configure() {
145-
super.configure();
146-
setCommand("mysqld", "--default-authentication-plugin=mysql_native_password");
147-
}
148-
149-
@Override
150-
public String getDriverClassName() {
151-
return "com.mysql.cj.jdbc.Driver";
152-
}
153-
154-
}
52+
static OracleContainer oracle() {
53+
return new OracleContainer() {
15554

156-
private static class OracleXeContainer extends OracleContainer {
55+
@Override
56+
protected void configure() {
57+
this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*DATABASE IS READY TO USE!.*\\s")
58+
.withStartupTimeout(Duration.ofMinutes(10));
59+
addEnv("ORACLE_PWD", getPassword());
60+
}
15761

158-
@Override
159-
protected void configure() {
160-
super.configure();
161-
this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*DATABASE IS READY TO USE!.*\\s")
162-
.withStartupTimeout(Duration.of(10, ChronoUnit.MINUTES));
163-
setShmSize(1024L * 1024L * 1024L);
164-
addEnv("ORACLE_PWD", getPassword());
165-
}
166-
167-
@Override
168-
protected void waitUntilContainerStarted() {
169-
getWaitStrategy().waitUntilReady(this);
170-
}
62+
@Override
63+
protected void waitUntilContainerStarted() {
64+
getWaitStrategy().waitUntilReady(this);
65+
}
17166

67+
};
17268
}
17369

174-
private static class PostgreSql9Container extends PostgreSQLContainer<PostgreSql9Container> {
175-
176-
PostgreSql9Container() {
177-
super("postgres:9.6.15");
178-
}
179-
180-
}
181-
182-
private static class PostgreSql10Container extends PostgreSQLContainer<PostgreSql10Container> {
183-
184-
PostgreSql10Container() {
185-
super("postgres:10.10");
186-
}
187-
70+
static PostgreSQLContainer<?> postgreSql() {
71+
return new PostgreSQLContainer<>("postgres:13.0");
18872
}
18973

190-
private static class PostgreSql11Container extends PostgreSQLContainer<PostgreSql11Container> {
191-
192-
PostgreSql11Container() {
193-
super("postgres:11.5");
194-
}
195-
196-
}
197-
198-
private static class SqlServer2017Container extends MSSQLServerContainer<SqlServer2017Container> {
199-
200-
SqlServer2017Container() {
201-
super("mcr.microsoft.com/mssql/server:2017-CU16");
202-
}
203-
74+
static MSSQLServerContainer<?> sqlServer() {
75+
return new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2019-CU8-ubuntu-16.04");
20476
}
20577

20678
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
import org.springframework.test.context.web.WebAppConfiguration;
2626

2727
/**
28-
* Integration tests for {@link JdbcIndexedSessionRepository} using IBM DB2 11.x database
29-
* with {@link Db2JdbcIndexedSessionRepositoryCustomizer}.
28+
* Integration tests for {@link JdbcIndexedSessionRepository} using IBM DB2 database with
29+
* {@link Db2JdbcIndexedSessionRepositoryCustomizer}.
3030
*
3131
* @author Vedran Pavic
3232
*/
3333
@ExtendWith(SpringExtension.class)
3434
@WebAppConfiguration
3535
@ContextConfiguration
36-
class Db211JdbcIndexedSessionRepositoryCustomizerITests extends Db211JdbcIndexedSessionRepositoryITests {
36+
class Db2JdbcIndexedSessionRepositoryCustomizerITests extends Db2JdbcIndexedSessionRepositoryITests {
3737

3838
@Configuration
3939
static class CustomizerConfig extends Config {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 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.
@@ -27,21 +27,21 @@
2727
import org.springframework.test.context.web.WebAppConfiguration;
2828

2929
/**
30-
* Integration tests for {@link JdbcIndexedSessionRepository} using IBM DB2 11.x database.
30+
* Integration tests for {@link JdbcIndexedSessionRepository} using IBM DB2 database.
3131
*
3232
* @author Vedran Pavic
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@WebAppConfiguration
3636
@ContextConfiguration
37-
class Db211JdbcIndexedSessionRepositoryITests extends AbstractContainerJdbcIndexedSessionRepositoryITests {
37+
class Db2JdbcIndexedSessionRepositoryITests extends AbstractContainerJdbcIndexedSessionRepositoryITests {
3838

3939
@Configuration
4040
static class Config extends BaseContainerConfig {
4141

4242
@Bean
4343
Db2Container databaseContainer() {
44-
Db2Container databaseContainer = DatabaseContainers.db211();
44+
Db2Container databaseContainer = DatabaseContainers.db2();
4545
databaseContainer.start();
4646
return databaseContainer;
4747
}

spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/MariaDb10JdbcIndexedSessionRepositoryITests.java

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
import org.springframework.test.context.web.WebAppConfiguration;
2626

2727
/**
28-
* Integration tests for {@link JdbcIndexedSessionRepository} using MySQL 8.x database
29-
* with {@link MySqlJdbcIndexedSessionRepositoryCustomizer}.
28+
* Integration tests for {@link JdbcIndexedSessionRepository} using MariaDB database with
29+
* {@link MySqlJdbcIndexedSessionRepositoryCustomizer}.
3030
*
3131
* @author Vedran Pavic
3232
*/
3333
@ExtendWith(SpringExtension.class)
3434
@WebAppConfiguration
3535
@ContextConfiguration
36-
class MySql8JdbcIndexedSessionRepositoryCustomizerITests extends MySql8JdbcIndexedSessionRepositoryITests {
36+
class MariaDbJdbcIndexedSessionRepositoryCustomizerITests extends MariaDbJdbcIndexedSessionRepositoryITests {
3737

3838
@Configuration
3939
static class CustomizerConfig extends Config {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 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.
@@ -27,21 +27,21 @@
2727
import org.springframework.test.context.web.WebAppConfiguration;
2828

2929
/**
30-
* Integration tests for {@link JdbcIndexedSessionRepository} using MariaDB 5.x database.
30+
* Integration tests for {@link JdbcIndexedSessionRepository} using MariaDB database.
3131
*
3232
* @author Vedran Pavic
3333
*/
3434
@ExtendWith(SpringExtension.class)
3535
@WebAppConfiguration
3636
@ContextConfiguration
37-
class MariaDb5JdbcIndexedSessionRepositoryITests extends AbstractContainerJdbcIndexedSessionRepositoryITests {
37+
class MariaDbJdbcIndexedSessionRepositoryITests extends AbstractContainerJdbcIndexedSessionRepositoryITests {
3838

3939
@Configuration
4040
static class Config extends BaseContainerConfig {
4141

4242
@Bean
43-
MariaDBContainer databaseContainer() {
44-
MariaDBContainer databaseContainer = DatabaseContainers.mariaDb5();
43+
MariaDBContainer<?> databaseContainer() {
44+
MariaDBContainer<?> databaseContainer = DatabaseContainers.mariaDb();
4545
databaseContainer.start();
4646
return databaseContainer;
4747
}

0 commit comments

Comments
 (0)