From 5d82a0740216664385c8225d009712092fba16fd Mon Sep 17 00:00:00 2001 From: Pavel Bortnik Date: Fri, 10 Jan 2025 16:35:04 +0300 Subject: [PATCH 1/3] EPMRPP-98599 || Add truncate of instant with nanos to microseconds --- .../databind/MultiFormatDateDeserializer.java | 15 ++++++++--- .../MultiFormatDateDeserializerTest.java | 25 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java index 75d7c11..2806cc2 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java +++ b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java @@ -27,6 +27,7 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAccessor; import java.util.Arrays; import java.util.List; @@ -67,14 +68,14 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th try { long longDate = parser.getLongValue(); if (parser.getText() == null) { - return Instant.ofEpochMilli(longDate); + return getTruncatedMillis(longDate); } } catch (Exception e) { // ignore } try { long millis = Long.parseLong(parser.getText()); - return Instant.ofEpochMilli(millis); + return getTruncatedMillis(millis); } catch (Exception e) { // ignore } @@ -85,12 +86,18 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th try { TemporalAccessor parsedDate = formatter.parseBest(strDate, ZonedDateTime::from, LocalDateTime::from); - return parsedDate instanceof ZonedDateTime ? ((ZonedDateTime) parsedDate).toInstant() - : ((LocalDateTime) parsedDate).toInstant(ZoneOffset.UTC); + Instant instant = + parsedDate instanceof ZonedDateTime ? ((ZonedDateTime) parsedDate).toInstant() + : ((LocalDateTime) parsedDate).toInstant(ZoneOffset.UTC); + return instant.truncatedTo(ChronoUnit.MICROS); } catch (DateTimeParseException e) { // Exception means the text could not be parsed with this formatter, continue with next formatter } } throw new IOException("Unable to parse date: " + strDate); } + + private Instant getTruncatedMillis(long value) { + return Instant.ofEpochMilli(value).truncatedTo(ChronoUnit.MICROS); + } } diff --git a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java index 68698eb..6860e1f 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java @@ -37,7 +37,8 @@ @ExtendWith(MockitoExtension.class) class MultiFormatDateDeserializerTest { - private static final Instant expectedTime = Instant.parse("2024-03-01T20:24:09.930Z"); + private static final Instant expectedTime = Instant.parse("2024-03-01T20:24:09.930987Z"); + private static final Instant expectedTimeMillis = Instant.parse("2024-03-01T20:24:09.930Z"); @Mock JsonParser jsonParser; @@ -46,22 +47,34 @@ class MultiFormatDateDeserializerTest { @ValueSource(strings = { "2024-03-01T20:24:09.930987Z", "2024-03-01T20:24:09.930987654", + "2024-03-01T20:24:09.930987+0000", + "2024-03-01T20:24:09.930987999" + }) + void deserializeDatesMicros(String strDate) throws IOException { + MultiFormatDateDeserializer a = new MultiFormatDateDeserializer(); + when(jsonParser.getText()).thenReturn(strDate); + Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class)); + + Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MICROS)); + } + + @ParameterizedTest + @ValueSource(strings = { "2024-03-01T20:24:09.930Z", "2024-03-01T20:24:09.930", "2024-03-01T20:24:09.930+00:00", "2024-03-01T19:24:09.930-01:00", - "2024-03-01T23:24:09.930+0300", - "2024-03-01T20:24:09.930000+0000", "1709324649930" }) - void deserializeDates(String strDate) throws IOException { + void deserializeDatesMillis(String strDate) throws IOException { MultiFormatDateDeserializer a = new MultiFormatDateDeserializer(); when(jsonParser.getText()).thenReturn(strDate); Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class)); - Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MILLIS)); + Assertions.assertEquals(expectedTimeMillis, date.truncatedTo(ChronoUnit.MICROS)); } + @ParameterizedTest @ValueSource(longs = { 1709324649930L, @@ -71,6 +84,6 @@ void deserializeIntegerFormat(Long longDate) throws IOException { when(jsonParser.getLongValue()).thenReturn(longDate); Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class)); - Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MILLIS)); + Assertions.assertEquals(expectedTimeMillis, date.truncatedTo(ChronoUnit.MICROS)); } } From b9f601f86ceed7c38f7d74ab8db687e60a868620 Mon Sep 17 00:00:00 2001 From: Pavel Bortnik Date: Sat, 11 Jan 2025 12:02:10 +0300 Subject: [PATCH 2/3] EPMRPP-98599 || Add truncate of instant with nanos to microseconds --- .../databind/MultiFormatDateDeserializer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java index 2806cc2..3f1dab4 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java +++ b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java @@ -68,14 +68,14 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th try { long longDate = parser.getLongValue(); if (parser.getText() == null) { - return getTruncatedMillis(longDate); + return getTruncatedToMicros(longDate); } } catch (Exception e) { // ignore } try { - long millis = Long.parseLong(parser.getText()); - return getTruncatedMillis(millis); + long longDate = Long.parseLong(parser.getText()); + return getTruncatedToMicros(longDate); } catch (Exception e) { // ignore } @@ -97,7 +97,7 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th throw new IOException("Unable to parse date: " + strDate); } - private Instant getTruncatedMillis(long value) { - return Instant.ofEpochMilli(value).truncatedTo(ChronoUnit.MICROS); + private Instant getTruncatedToMicros(long longDate) { + return Instant.ofEpochMilli(longDate).truncatedTo(ChronoUnit.MICROS); } } From 279ade866f957399c50701aa68a0ad0f50cbeb53 Mon Sep 17 00:00:00 2001 From: Pavel Bortnik Date: Sat, 11 Jan 2025 12:06:39 +0300 Subject: [PATCH 3/3] 5.13.1 || Update release version --- .github/workflows/release.yml | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5470762..6cd57ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ on: env: GH_USER_NAME: github.actor SCRIPTS_VERSION: 5.12.0 - RELEASE_VERSION: 5.13.0 + RELEASE_VERSION: 5.13.1 jobs: release: diff --git a/gradle.properties b/gradle.properties index dfe5c50..3214e26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.13.0 +version=5.13.1 description=EPAM Report portal. REST Reporting API model hibernateValidatorVersion=6.1.2.Final validationApiVersion=2.0.1.Final