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

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new e04c2c2  AVRO-2244 Fix flaky datetime test (#386)
e04c2c2 is described below

commit e04c2c291395339b8eb488a5e045500d366553b6
Author: Thiruvalluvan M G <[email protected]>
AuthorDate: Tue Nov 20 16:28:53 2018 +0530

    AVRO-2244 Fix flaky datetime test (#386)
---
 .../apache/avro/specific/TestSpecificLogicalTypes.java | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git 
a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
 
b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
index ba89239..02bea73 100644
--- 
a/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
+++ 
b/lang/java/avro/src/test/java/org/apache/avro/specific/TestSpecificLogicalTypes.java
@@ -27,7 +27,6 @@ import java.math.BigDecimal;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.temporal.ChronoField;
-import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -46,6 +45,7 @@ import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
 import org.joda.time.LocalDate;
 import org.joda.time.LocalTime;
+import org.joda.time.chrono.ISOChronology;
 import org.joda.time.format.ISODateTimeFormat;
 import org.junit.Assert;
 import org.junit.Rule;
@@ -119,8 +119,8 @@ public class TestSpecificLogicalTypes {
         3019.34,
         null,
         java.time.LocalDate.now(),
-        java.time.LocalTime.now().truncatedTo(ChronoUnit.MILLIS),
-        java.time.Instant.now().truncatedTo(ChronoUnit.MILLIS),
+        java.time.LocalTime.now(),
+        java.time.Instant.now(),
         new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
     );
 
@@ -133,6 +133,7 @@ public class TestSpecificLogicalTypes {
 
   @Test
   public void testAbilityToReadJsr310RecordWrittenAsJodaRecord() throws 
IOException {
+
     TestRecordWithLogicalTypes withJoda = new TestRecordWithLogicalTypes(
             true,
             34,
@@ -142,7 +143,10 @@ public class TestSpecificLogicalTypes {
             null,
             LocalDate.now(),
             LocalTime.now(),
-            DateTime.now().withZone(DateTimeZone.UTC),
+            // There is no reliable way to get fixed width string from 
ISO_INSTANT below
+            // for granularity less than one second second.
+            new DateTime((System.currentTimeMillis() / 1000) * 1000,
+                    ISOChronology.getInstance()).withZone(DateTimeZone.UTC),
             new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
     );
 
@@ -162,7 +166,7 @@ public class TestSpecificLogicalTypes {
 
     Assert.assertThat(ISO_LOCAL_DATE.format(withJsr310.getD()), 
is(ISODateTimeFormat.date().print(withJoda.getD())));
     Assert.assertThat(ISO_LOCAL_TIME.format(withJsr310.getT()), 
is(ISODateTimeFormat.time().print(withJoda.getT())));
-    Assert.assertThat(ISO_INSTANT.format(withJsr310.getTs()), 
is(ISODateTimeFormat.dateTime().print(withJoda.getTs())));
+    Assert.assertThat(ISO_INSTANT.format(withJsr310.getTs()), 
is(ISODateTimeFormat.dateTimeNoMillis().print(withJoda.getTs())));
     Assert.assertThat(withJsr310.getDec(), comparesEqualTo(withJoda.getDec()));
   }
 
@@ -176,8 +180,8 @@ public class TestSpecificLogicalTypes {
             3019.34,
             null,
             java.time.LocalDate.now(),
-            java.time.LocalTime.now().truncatedTo(ChronoUnit.MILLIS),
-            java.time.Instant.now().truncatedTo(ChronoUnit.MILLIS),
+            java.time.LocalTime.now(),
+            java.time.Instant.now(),
             new BigDecimal(123.45f).setScale(2, BigDecimal.ROUND_HALF_DOWN)
     );
 

Reply via email to