Skip to content

Commit 58ebe5c

Browse files
committed
Integration tests for quarkus.hibernate-orm.database.orm-compatibility.version
For reference, below are the failures when not setting the property (and ignoring schema validation). MariaDB: [ERROR] Failures: [ERROR] CompatibilityTest.instant:81 expected: 2018-01-01T10:58:30Z but was: 2018-01-01T11:58:30Z [ERROR] CompatibilityTest.offsetDateTime:91 expected: 2018-01-01T11:58:30+01:00 (java.time.OffsetDateTime) but was: 2018-01-01T11:58:30Z (java.time.OffsetDateTime) when comparing values using 'OffsetDateTime.timeLineOrder()' [ERROR] CompatibilityTest.persistUsingOldSchema:61 1 expectation failed. Expected status code is <200> but was <500>. [ERROR] CompatibilityTest.sequence:38 1 expectation failed. Expected status code is <200> but was <500>. [ERROR] CompatibilityTest.zonedDateTime:102 expected: 2018-01-01T11:58:30+01:00[Europe/Paris] (java.time.ZonedDateTime) but was: 2018-01-01T11:58:30Z[UTC] (java.time.ZonedDateTime) when comparing values using 'ChronoZonedDateTime.timeLineOrder()' PostgreSQL: Everything failing due to array support not liking binary columns, so I had to comment out the array/arrayList properties. See https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/Array.20support Then we get that: [ERROR] Failures: [ERROR] CompatibilityTest.instant:79 expected: 2018-01-01T10:58:30Z but was: 2018-01-01T11:58:30Z [ERROR] CompatibilityTest.offsetDateTime:89 expected: 2018-01-01T11:58:30+01:00 (java.time.OffsetDateTime) but was: 2018-01-01T11:58:30Z (java.time.OffsetDateTime) when comparing values using 'OffsetDateTime.timeLineOrder()' [ERROR] CompatibilityTest.persistUsingOldSchema:59 1 expectation failed. Expected status code is <200> but was <500>. [ERROR] CompatibilityTest.sequence:36 1 expectation failed. Expected status code is <200> but was <500>. [ERROR] CompatibilityTest.zonedDateTime:100 expected: 2018-01-01T11:58:30+01:00[Europe/Paris] (java.time.ZonedDateTime) but was: 2018-01-01T11:58:30Z[UTC] (java.time.ZonedDateTime) when comparing values using 'ChronoZonedDateTime.timeLineOrder()'
1 parent af1abc7 commit 58ebe5c

File tree

25 files changed

+1518
-0
lines changed

25 files changed

+1518
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Hibernate ORM 5.6 database compatibility tests
2+
3+
## What is this?
4+
5+
These module test that Quarkus can indeed work with a database created by Hibernate ORM 5.6
6+
when the following property is set:
7+
8+
```properties
9+
quarkus.hibernate-orm.database.orm-compatibility.version = 5.6
10+
```
11+
12+
## How does it work?
13+
14+
The tests need to execute on a database whose schema and data
15+
was initialized with Hibernate ORM 5.6.
16+
17+
Everything is already set up to restore a dump on startup.
18+
19+
## How to update the tests?
20+
21+
If you add new tests and those changes require new entity mappings and/or data,
22+
make sure to update the project `database-generator` accordingly
23+
(same entity mapping as in your tests, in particular).
24+
This project depends on Quarkus 2 and is used to generate a database.
25+
26+
Then, to update the dump, run `./update-dump.sh` from each DB directory (`mariadb`, `postgresql`, ...).
27+
This will start a container, generate the database, and update the dump in `src/test/resources`.
28+
29+
## Why is `database-generator` not part of the build?
30+
31+
Because:
32+
33+
1. It doesn't need to. This project is only meant to be used to update dumps.
34+
2. It depends on Quarkus 2, so adding it to the build would pollute the local Maven repository unnecessarily.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>io.quarkus</groupId>
7+
<artifactId>quarkus-integration-test-hibernate-orm-compatibility-5.6-database-generator</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<properties>
10+
<compiler-plugin.version>3.10.1</compiler-plugin.version>
11+
<maven.compiler.release>17</maven.compiler.release>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
15+
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
16+
<quarkus.platform.version>2.16.3.Final</quarkus.platform.version>
17+
<skipITs>true</skipITs>
18+
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
19+
</properties>
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>${quarkus.platform.group-id}</groupId>
24+
<artifactId>${quarkus.platform.artifact-id}</artifactId>
25+
<version>${quarkus.platform.version}</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
<dependencies>
32+
<dependency>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-hibernate-orm</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.quarkus</groupId>
38+
<artifactId>quarkus-jdbc-mariadb</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>io.quarkus</groupId>
42+
<artifactId>quarkus-jdbc-postgresql</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.quarkus</groupId>
46+
<artifactId>quarkus-arc</artifactId>
47+
</dependency>
48+
</dependencies>
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>${quarkus.platform.group-id}</groupId>
53+
<artifactId>quarkus-maven-plugin</artifactId>
54+
<version>${quarkus.platform.version}</version>
55+
<extensions>true</extensions>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>build</goal>
60+
<goal>generate-code</goal>
61+
<goal>generate-code-tests</goal>
62+
</goals>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-compiler-plugin</artifactId>
68+
<version>${compiler-plugin.version}</version>
69+
<configuration>
70+
<compilerArgs>
71+
<arg>-parameters</arg>
72+
</compilerArgs>
73+
</configuration>
74+
</plugin>
75+
<plugin>
76+
<artifactId>maven-surefire-plugin</artifactId>
77+
<version>${surefire-plugin.version}</version>
78+
<configuration>
79+
<systemPropertyVariables>
80+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
81+
<maven.home>${maven.home}</maven.home>
82+
</systemPropertyVariables>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<artifactId>maven-failsafe-plugin</artifactId>
87+
<version>${surefire-plugin.version}</version>
88+
<executions>
89+
<execution>
90+
<goals>
91+
<goal>integration-test</goal>
92+
<goal>verify</goal>
93+
</goals>
94+
<configuration>
95+
<systemPropertyVariables>
96+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner
97+
</native.image.path>
98+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
99+
<maven.home>${maven.home}</maven.home>
100+
</systemPropertyVariables>
101+
</configuration>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
<profiles>
108+
<profile>
109+
<id>native</id>
110+
<activation>
111+
<property>
112+
<name>native</name>
113+
</property>
114+
</activation>
115+
<properties>
116+
<skipITs>false</skipITs>
117+
<quarkus.package.type>native</quarkus.package.type>
118+
</properties>
119+
</profile>
120+
</profiles>
121+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package io.quarkus.it.hibernate.compatibility;
2+
3+
import java.time.Duration;
4+
import java.time.Instant;
5+
import java.time.LocalDateTime;
6+
import java.time.ZoneId;
7+
import java.time.ZoneOffset;
8+
import java.time.temporal.ChronoUnit;
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.Objects;
13+
import java.util.UUID;
14+
15+
import javax.inject.Inject;
16+
import javax.persistence.EntityManager;
17+
18+
import io.quarkus.narayana.jta.QuarkusTransaction;
19+
import io.quarkus.runtime.Quarkus;
20+
import io.quarkus.runtime.QuarkusApplication;
21+
import io.quarkus.runtime.annotations.QuarkusMain;
22+
23+
@QuarkusMain
24+
public class Main {
25+
public static void main(String... args) {
26+
System.out.println("Initializing schema...");
27+
Quarkus.run(QuarkusMain.class, args);
28+
}
29+
30+
static class QuarkusMain implements QuarkusApplication {
31+
@Inject
32+
EntityManager em;
33+
34+
@Override
35+
public int run(String... args) {
36+
System.out.println("Initializing data...");
37+
MyEntity createdEntity = QuarkusTransaction.requiringNew().call(() -> {
38+
var entity = new MyEntity();
39+
entity.duration = Duration.of(59, ChronoUnit.SECONDS);
40+
entity.uuid = UUID.fromString("f49c6ba8-8d7f-417a-a255-d594dddf729f");
41+
entity.instant = Instant.parse("2018-01-01T10:58:30.00Z");
42+
entity.offsetDateTime = LocalDateTime.of(2018, 1, 1, 12, 58, 30, 0)
43+
.atOffset(ZoneOffset.ofHours(2));
44+
entity.zonedDateTime = LocalDateTime.of(2018, 1, 1, 12, 58, 30, 0)
45+
.atZone(ZoneId.of("Africa/Cairo" /* UTC+2 */));
46+
entity.intArray = new int[] { 0, 1, 42 };
47+
entity.stringList = new ArrayList<>(List.of("one", "two"));
48+
entity.myEnum = MyEnum.VALUE2;
49+
em.persist(entity);
50+
return entity;
51+
});
52+
53+
System.out.println("Checking data...");
54+
// Check that Hibernate ORM 5 used to load the values we're going to expect in compatibility tests
55+
QuarkusTransaction.requiringNew().run(() -> {
56+
checkEqual(1L, createdEntity.id);
57+
var loadedEntity = em.find(MyEntity.class, createdEntity.id);
58+
checkEqual(createdEntity.duration, loadedEntity.duration);
59+
checkEqual(createdEntity.uuid, loadedEntity.uuid);
60+
checkEqual(createdEntity.instant, loadedEntity.instant);
61+
checkEqual(createdEntity.offsetDateTime.atZoneSameInstant(ZoneId.systemDefault()).toOffsetDateTime(),
62+
loadedEntity.offsetDateTime);
63+
checkEqual(createdEntity.zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()), loadedEntity.zonedDateTime);
64+
checkEqual(createdEntity.intArray, loadedEntity.intArray);
65+
checkEqual(createdEntity.stringList, loadedEntity.stringList);
66+
checkEqual(createdEntity.myEnum, loadedEntity.myEnum);
67+
});
68+
69+
System.out.println("Done.");
70+
return 0;
71+
}
72+
73+
private <T> void checkEqual(T expected, T actual) {
74+
if (!Objects.equals(expected, actual)) {
75+
throw new AssertionError("Not equal; expected: " + expected + ", actual: " + actual);
76+
}
77+
}
78+
79+
private void checkEqual(int[] expected, int[] actual) {
80+
if (!Arrays.equals(expected, actual)) {
81+
throw new AssertionError("Not equal; expected: " + Arrays.toString(expected)
82+
+ ", actual: " + Arrays.toString(actual));
83+
}
84+
}
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.quarkus.it.hibernate.compatibility;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.EnumType;
5+
import javax.persistence.Enumerated;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.Id;
8+
import java.time.Duration;
9+
import java.time.Instant;
10+
import java.time.OffsetDateTime;
11+
import java.time.ZonedDateTime;
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
import java.util.UUID;
15+
16+
@Entity
17+
public class MyEntity {
18+
@Id
19+
@GeneratedValue
20+
public Long id;
21+
22+
public Duration duration;
23+
24+
public UUID uuid;
25+
26+
public Instant instant;
27+
28+
public OffsetDateTime offsetDateTime;
29+
30+
public ZonedDateTime zonedDateTime;
31+
32+
public int[] intArray;
33+
34+
public ArrayList<String> stringList;
35+
36+
@Enumerated(EnumType.ORDINAL)
37+
public MyEnum myEnum;
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.quarkus.it.hibernate.compatibility;
2+
3+
public enum MyEnum {
4+
VALUE1,
5+
VALUE2,
6+
VALUE3
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is set from the commandline when building
2+
quarkus.datasource.db-kind=${db-kind}
3+
quarkus.hibernate-orm.database.generation=create

0 commit comments

Comments
 (0)