This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 136ab14decab7d6f56b60571903d657f07941bb0
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Apr 7 17:46:22 2023 +0100

    add failing test for instant being off by 1 millisecond
---
 .../rest/util/json/BrooklynJacksonSerializerTest.java | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/util/json/BrooklynJacksonSerializerTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/util/json/BrooklynJacksonSerializerTest.java
index 71cdc497ee..adf97cf167 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/util/json/BrooklynJacksonSerializerTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/util/json/BrooklynJacksonSerializerTest.java
@@ -215,7 +215,12 @@ public class BrooklynJacksonSerializerTest {
         // It has passed in IDE w 1000 invocations, and with delays introduced 
on every line below, so not sure what is up;
         // probably a weird rounding inconsistency with milliseconds v 
nanosecond precision on the underlying Instant.
 
-        // simply worth remembering that an Instant with sub-millisecond 
precision will not survive serialization
+        // simply worth remembering that an Instant with sub-millisecond 
precision does not maintain that precision through serialization
+
+        // update 2023-04 - doing  now = 
Instant.ofEpochMilli(System.currentTimeMillis())  is not enough to solve this; 
even with it we just saw:
+        // java.lang.AssertionError: Now deserialized differently, from 
'2023-04-07T10:28:32.355Z' (from 2023-04-07T10:28:32.355Z) to 
2023-04-07T10:28:32.354Z
+        // expected [2023-04-07T10:28:32.355Z] but found 
[2023-04-07T10:28:32.354Z]
+        // traced bug to test below which fails
 
         String nowYaml = 
mapper.writerFor(Instant.class).writeValueAsString(now);
         Asserts.assertEquals(nowYaml.trim(), Time.makeIso8601DateStringZ(now));
@@ -233,6 +238,18 @@ public class BrooklynJacksonSerializerTest {
         Asserts.assertEquals(now2, now);
     }
 
+    @Test
+    public void testInstantReadWriteBuggyTime() throws JsonProcessingException 
{
+        ObjectMapper mapper = BeanWithTypeUtils.newYamlMapper(null, true, 
null, true);
+
+        String nowS = "2023-04-07T10:28:32.355Z";
+        Asserts.assertEquals(nowS, 
Time.parseCalendarMaybe(nowS).get().toInstant().toString());
+
+        Instant now2 = mapper.readerFor(Instant.class).readValue(nowS);
+        Asserts.assertEquals(now2.toString(), nowS);
+    }
+
+
     @Test
     public void testNumberReadWriteYaml() throws JsonProcessingException {
         ObjectMapper mapper = BeanWithTypeUtils.newYamlMapper(null, true, 
null, true);

Reply via email to