I have some unit tests that run fine under Java 11.x
and a Docker
container with PostgreSQL 12.x
. I'm in the process of migrating the application into Java 17.x
, and now there are several of these unit tests failing. As far as I can tell the issue is around the precision of LocalDateTime
types.
[ERROR] UnitTest.test1:334
expected: CustomType (3185, 1, Description, 2022-12-01T22:10:27.924910854, 2022-12-01T22:10:27.924951801, user, false)
but was: CustomType (3185, 1, Description, 2022-12-01T22:10:27.924911, 2022-12-01T22:10:27.924952, user, false)
[ERROR] UnitTest.test2:60
expected: CustomType2 (3182, Test, Hello, 2022-12-01T22:10:27.653447384, user, index, null, null, false, null)
but was: CustomType2 (3182, Test, Hello, 2022-12-01T22:10:27.653447, user, index, null, null, false, null)
[ERROR] UnitTest.test3:268
expected: CustomType (3184, 1, Description, 2022-12-01T22:10:27.863401246, 2022-12-01T22:10:27.863438735, user, false)
but was: CustomType (3184, 1, Description, 2022-12-01T22:10:27.863401, 2022-12-01T22:10:27.863439, user, false)
The tests are simple: the auto-generated (jOOQ
) objects are compared after being instantiated manually with some predefined data (the expected
), and then saved/updated from the database (the actual
). The types in the database are defined as timestamp
and jOOQ
generates a LocalDateTime
(instead of an Instant
I would say) for the same.
// Unit Test
CustomType instance = CustomType.builder()
// ...rest of the fields ommited for brevity
.lastUpdatedAt(LocalDateTime.now())
.build();
CustomType result = repository.insert(instance);
instance.setId(result.getId());
Assertions.assertThat(result).isEqualTo(instance); // AssertJ
// Repository
public CustomType insert(CustomType data) {
data.setId(null);
CustomTypeRecord record = new CustomTypeRecord(); // ...nevermind using record here ;)
record.from(data);
data = mainDsl.insertInto(CUSTOM_TYPE)
.set(record)
.returning()
.fetchOneInto(CustomType.class);
return data;
}
I don't know where else to look for hint(s) of what's going on here. I'm certain there aren't any custom formatting done to the LocalDateTime
types in the source code.
UPDATES
Dependencies after upgrading jOOQ
to version 3.17.5
:
$ ./mvnw dependency:list
...
[INFO] --- maven-dependency-plugin:3.3.0:list (default-cli) @ graphql-api ---
[INFO]
[INFO] The following files have been resolved:
[INFO] org.springframework.boot:spring-boot-starter-jooq:jar:2.7.4:compile -- module spring.boot.starter.jooq [auto]
[INFO] org.springframework.boot:spring-boot-starter-jdbc:jar:2.7.4:compile -- module spring.boot.starter.jdbc [auto]
[INFO] com.zaxxer:HikariCP:jar:4.0.3:compile -- module com.zaxxer.hikari
[INFO] org.springframework:spring-jdbc:jar:5.3.23:compile -- module spring.jdbc [auto]
[INFO] jakarta.activation:jakarta.activation-api:jar:1.2.2:compile -- module jakarta.activation
[INFO] jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile -- module java.xml.bind
[INFO] org.springframework:spring-tx:jar:5.3.23:compile -- module spring.tx [auto]
[INFO] org.springframework:spring-core:jar:5.3.23:compile -- module spring.core [auto]
[INFO] org.springframework:spring-jcl:jar:5.3.23:compile -- module spring.jcl [auto]
[INFO] org.jooq:jooq:jar:3.17.5:compile -- module org.jooq
[INFO] io.r2dbc:r2dbc-spi:jar:0.9.1.RELEASE:compile -- module r2dbc.spi [auto]
[INFO] org.reactivestreams:reactive-streams:jar:1.0.4:compile -- module org.reactivestreams [auto]
[INFO] org.jooq:jooq-codegen:jar:3.17.5:compile -- module org.jooq.codegen
[INFO] org.jooq:jooq-meta:jar:3.17.5:compile -- module org.jooq.meta
[INFO] org.jooq:jooq-postgres-extensions:jar:3.17.5:compile -- module org.jooq.postgres.extensions
[INFO] org.springframework.boot:spring-boot-starter-web:jar:2.7.4:compile -- module spring.boot.starter.web [auto]
...