Skip to content

Commit a4ef56d

Browse files
committed
Add support for MySQL and Postgres testing.
* Introduce Testcontainers as the mechanism to test against real data stores. * Alter CI to handle running Testcontainers in reduced privilege mode. * Run the data store specific test cases ONLY for the baseline Java 8 test execution. See #2256.
1 parent 183e3e5 commit a4ef56d

File tree

9 files changed

+697
-8
lines changed

9 files changed

+697
-8
lines changed

Diff for: Jenkinsfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ pipeline {
2424
}
2525
options { timeout(time: 30, unit: 'MINUTES') }
2626
environment {
27+
DOCKER_HUB = credentials('hub.docker.com-springbuildmaster')
2728
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
2829
}
2930
steps {
3031
script {
3132
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
32-
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
33-
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml clean dependency:list test -Dsort -Dbundlor.enabled=false -U -B'
33+
docker.image('adoptopenjdk/openjdk8:latest').inside('-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $HOME:/tmp/jenkins-home') {
34+
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
35+
sh 'PROFILE=all-dbs ci/test.sh'
36+
sh "ci/clean.sh"
3437
}
3538
}
3639
}

Diff for: ci/clean.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -x
2+
3+
set -euo pipefail
4+
5+
MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" \
6+
./mvnw -s settings.xml clean -Dmaven.repo.local=/tmp/jenkins-home/.m2/spring-data-jpa

Diff for: ci/test.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash -x
2+
3+
set -euo pipefail
4+
5+
mkdir -p /tmp/jenkins-home/.m2/spring-data-jpa
6+
chown -R 1001:1001 .
7+
8+
MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" \
9+
./mvnw -s settings.xml \
10+
-P${PROFILE} clean dependency:list test -Dsort -U -B -Dmaven.repo.local=/tmp/jenkins-home/.m2/spring-data-jpa

Diff for: pom.xml

+93-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323

2424
<eclipselink>2.7.9</eclipselink>
2525
<hibernate>5.5.3.Final</hibernate>
26+
<mysql-connector-java>8.0.23</mysql-connector-java>
27+
<postgresql>42.2.19</postgresql>
28+
<springdata.commons>2.6.0-SNAPSHOT</springdata.commons>
2629
<vavr>0.10.3</vavr>
30+
2731
<hibernate.groupId>org.hibernate</hibernate.groupId>
28-
<springdata.commons>2.6.0-SNAPSHOT</springdata.commons>
2932

3033
<java-module-name>spring.data.jpa</java-module-name>
3134

@@ -34,6 +37,43 @@
3437
</properties>
3538

3639
<profiles>
40+
<profile>
41+
<id>all-dbs</id>
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>mysql-test</id>
50+
<phase>test</phase>
51+
<goals>
52+
<goal>test</goal>
53+
</goals>
54+
<configuration>
55+
<includes>
56+
<include>**/MySql*IntegrationTests.java</include>
57+
</includes>
58+
</configuration>
59+
</execution>
60+
<execution>
61+
<id>postgres-test</id>
62+
<phase>test</phase>
63+
<goals>
64+
<goal>test</goal>
65+
</goals>
66+
<configuration>
67+
<includes>
68+
<include>**/Postgres*IntegrationTests.java</include>
69+
</includes>
70+
</configuration>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
</profile>
3777
<profile>
3878
<id>hibernate-next</id>
3979
<properties>
@@ -116,6 +156,18 @@
116156
</profile>
117157
</profiles>
118158

159+
<dependencyManagement>
160+
<dependencies>
161+
<dependency>
162+
<groupId>org.testcontainers</groupId>
163+
<artifactId>testcontainers-bom</artifactId>
164+
<version>${testcontainers}</version>
165+
<type>pom</type>
166+
<scope>import</scope>
167+
</dependency>
168+
</dependencies>
169+
</dependencyManagement>
170+
119171
<dependencies>
120172

121173
<dependency>
@@ -187,6 +239,40 @@
187239
<scope>test</scope>
188240
</dependency>
189241

242+
<!-- MySQL testing support -->
243+
<dependency>
244+
<groupId>mysql</groupId>
245+
<artifactId>mysql-connector-java</artifactId>
246+
<version>${mysql-connector-java}</version>
247+
<scope>test</scope>
248+
</dependency>
249+
250+
<dependency>
251+
<groupId>org.testcontainers</groupId>
252+
<artifactId>mysql</artifactId>
253+
<scope>test</scope>
254+
<exclusions>
255+
<exclusion>
256+
<groupId>org.slf4j</groupId>
257+
<artifactId>jcl-over-slf4j</artifactId>
258+
</exclusion>
259+
</exclusions>
260+
</dependency>
261+
262+
<!-- Postgres testing support -->
263+
<dependency>
264+
<groupId>org.postgresql</groupId>
265+
<artifactId>postgresql</artifactId>
266+
<version>${postgresql}</version>
267+
<scope>test</scope>
268+
</dependency>
269+
270+
<dependency>
271+
<groupId>org.testcontainers</groupId>
272+
<artifactId>postgresql</artifactId>
273+
<scope>test</scope>
274+
</dependency>
275+
190276
<dependency>
191277
<groupId>org.threeten</groupId>
192278
<artifactId>threetenbp</artifactId>
@@ -325,6 +411,7 @@
325411
</dependencies>
326412
<executions>
327413
<execution>
414+
<!-- override the default-test execution and exclude everything -->
328415
<id>default-test</id>
329416
<configuration>
330417
<excludes>
@@ -333,7 +420,7 @@
333420
</configuration>
334421
</execution>
335422
<execution>
336-
<id>unit-tests</id>
423+
<id>unit-test</id>
337424
<goals>
338425
<goal>test</goal>
339426
</goals>
@@ -345,7 +432,7 @@
345432
</configuration>
346433
</execution>
347434
<execution>
348-
<id>integration-tests</id>
435+
<id>integration-test</id>
349436
<goals>
350437
<goal>test</goal>
351438
</goals>
@@ -359,6 +446,8 @@
359446
<exclude>**/*UnitTests.java</exclude>
360447
<exclude>**/OpenJpa*</exclude>
361448
<exclude>**/EclipseLink*</exclude>
449+
<exclude>**/MySql*</exclude>
450+
<exclude>**/Postgres*</exclude>
362451
</excludes>
363452
<argLine>
364453
-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring}/spring-instrument-${spring}.jar
@@ -367,7 +456,7 @@
367456
</configuration>
368457
</execution>
369458
<execution>
370-
<id>eclipselink-tests</id>
459+
<id>eclipselink-test</id>
371460
<goals>
372461
<goal>test</goal>
373462
</goals>

0 commit comments

Comments
 (0)