From 7dff19795ffb6d2a914443ee264358c4c19a0ab3 Mon Sep 17 00:00:00 2001 From: Gavin Date: Wed, 7 Dec 2022 21:38:00 +0100 Subject: [PATCH] attempt to fix continuing test flakiness on Sybase --- .../java/org/hibernate/orm/test/timezones/AutoZonedTest.java | 5 +++-- .../org/hibernate/orm/test/timezones/ColumnZonedTest.java | 5 +++-- .../org/hibernate/orm/test/timezones/DefaultZonedTest.java | 5 +++-- .../hibernate/orm/test/timezones/NormalizedZonedTest.java | 5 +++-- .../org/hibernate/orm/test/timezones/PassThruZonedTest.java | 5 +++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/AutoZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/AutoZonedTest.java index 81f8a73e1d..5814ffcd44 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/AutoZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/AutoZonedTest.java @@ -16,6 +16,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,8 +39,8 @@ public class AutoZonedTest { Zoned z = s.find(Zoned.class, id); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision - assertEquals( nowZoned.toInstant().toEpochMilli()/30, z.zonedDateTime.toInstant().toEpochMilli()/30 ); - assertEquals( nowOffset.toInstant().toEpochMilli()/30, z.offsetDateTime.toInstant().toEpochMilli()/30 ); + assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); + assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); } else { assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ColumnZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ColumnZonedTest.java index 7385929836..ee3211dd73 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ColumnZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ColumnZonedTest.java @@ -16,6 +16,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,8 +39,8 @@ public class ColumnZonedTest { Zoned z = s.find(Zoned.class, id); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision - assertEquals( nowZoned.toInstant().toEpochMilli()/30, z.zonedDateTime.toInstant().toEpochMilli()/30 ); - assertEquals( nowOffset.toInstant().toEpochMilli()/30, z.offsetDateTime.toInstant().toEpochMilli()/30 ); + assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); + assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); } else { assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/DefaultZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/DefaultZonedTest.java index f30ba64dc4..de3c10e06f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/DefaultZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/DefaultZonedTest.java @@ -14,6 +14,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -35,8 +36,8 @@ public class DefaultZonedTest { Zoned z = s.find(Zoned.class, id); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision - assertEquals( nowZoned.toInstant().toEpochMilli()/30, z.zonedDateTime.toInstant().toEpochMilli()/30 ); - assertEquals( nowOffset.toInstant().toEpochMilli()/30, z.offsetDateTime.toInstant().toEpochMilli()/30 ); + assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); + assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); } else { assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java index 8554b3349e..7edbecec0e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java @@ -16,6 +16,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,8 +39,8 @@ public class NormalizedZonedTest { Zoned z = s.find(Zoned.class, id); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision - assertEquals( nowZoned.toInstant().toEpochMilli()/30, z.zonedDateTime.toInstant().toEpochMilli()/30 ); - assertEquals( nowOffset.toInstant().toEpochMilli()/30, z.offsetDateTime.toInstant().toEpochMilli()/30 ); + assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); + assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS) ); } else { assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java index 0947b22a7b..88dac300d7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java @@ -16,6 +16,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,8 +39,8 @@ public class PassThruZonedTest { Zoned z = s.find(Zoned.class, id); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision - assertEquals( nowZoned.toInstant().toEpochMilli()/30, z.zonedDateTime.toInstant().toEpochMilli()/30 ); - assertEquals( nowOffset.toInstant().toEpochMilli()/30, z.offsetDateTime.toInstant().toEpochMilli()/30 ); + assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); + assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); } else { assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() );