Fix unit test with Java 9+ 01/79101/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Jan 2019 21:32:01 +0000 (22:32 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Jan 2019 22:13:54 +0000 (23:13 +0100)
With https://bugs.openjdk.java.net/browse/JDK-8068730 Instant.now()
has microsecond precision, which leads to a comparison failure.

Fix this by truncating the result of Instant.now() to milliseconds.

Change-Id: Ida8172e5b02cf352325e6f516e19592be4a83d67
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouterTest.java

index ab3a8a3..36c5f8f 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.SettableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -50,7 +51,8 @@ public class DOMNotificationRouterTest {
         new NodeIdentifier(QName.create(TestModel.TEST_QNAME.getModule(), "test-notification")))
             .withChild(ImmutableNodes.leafNode(QName.create(TestModel.TEST_QNAME.getModule(), "value-leaf"), "foo"))
                 .build();
-    private static final Instant INSTANT = Instant.now();
+    // Truncate to milliseconds, as Java 9+ we get microsecond precision, which cannot be expressed in terms of Date
+    private static final Instant INSTANT = Instant.now().truncatedTo(ChronoUnit.MILLIS);
 
     private static SchemaPath notificationSchemaPath;
 
@@ -154,11 +156,11 @@ public class DOMNotificationRouterTest {
         SettableFuture<DOMNotification> receivedNotification = SettableFuture.create();
 
         @Override
-        public void onNotification(DOMNotification notification) {
+        public void onNotification(final DOMNotification notification) {
             receivedNotification.set(notification);
         }
 
-        void verifyReceived(SchemaPath path, ContainerNode body, @Nullable Date eventTime)
+        void verifyReceived(final SchemaPath path, final ContainerNode body, @Nullable final Date eventTime)
                 throws InterruptedException, ExecutionException, TimeoutException {
             final DOMNotification actual = receivedNotification.get(5, TimeUnit.SECONDS);
             assertEquals(path, actual.getType());
@@ -185,11 +187,11 @@ public class DOMNotificationRouterTest {
         SettableFuture<org.opendaylight.mdsal.dom.api.DOMNotification> receivedNotification = SettableFuture.create();
 
         @Override
-        public void onNotification(org.opendaylight.mdsal.dom.api.DOMNotification notification) {
+        public void onNotification(final org.opendaylight.mdsal.dom.api.DOMNotification notification) {
             receivedNotification.set(notification);
         }
 
-        void verifyReceived(SchemaPath path, ContainerNode body, @Nullable Instant eventTime)
+        void verifyReceived(final SchemaPath path, final ContainerNode body, @Nullable final Instant eventTime)
                 throws InterruptedException, ExecutionException, TimeoutException {
             final org.opendaylight.mdsal.dom.api.DOMNotification actual =
                     receivedNotification.get(5, TimeUnit.SECONDS);
@@ -211,11 +213,11 @@ public class DOMNotificationRouterTest {
         SettableFuture<Set<SchemaPath>> receivedNotification = SettableFuture.create();
 
         @Override
-        public void onSubscriptionChanged(Set<SchemaPath> currentTypes) {
+        public void onSubscriptionChanged(final Set<SchemaPath> currentTypes) {
             receivedNotification.set(currentTypes);
         }
 
-        void verifyReceived(SchemaPath... paths)
+        void verifyReceived(final SchemaPath... paths)
                 throws InterruptedException, ExecutionException, TimeoutException {
             final Set<SchemaPath> actual = receivedNotification.get(5, TimeUnit.SECONDS);
             assertEquals(ImmutableSet.copyOf(paths), actual);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.