From: Robert Varga Date: Tue, 1 Jan 2019 21:32:01 +0000 (+0100) Subject: Fix unit test with Java 9+ X-Git-Tag: release/neon~27 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=baca0f4811fdef689cbefd5c776a2955f3e269ba;hp=f09c372c4cb1ab228f0133a8b259d62240cc28cd Fix unit test with Java 9+ 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 --- diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouterTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouterTest.java index ab3a8a3df0..36c5f8f4a7 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouterTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMNotificationRouterTest.java @@ -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 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 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> receivedNotification = SettableFuture.create(); @Override - public void onSubscriptionChanged(Set currentTypes) { + public void onSubscriptionChanged(final Set currentTypes) { receivedNotification.set(currentTypes); } - void verifyReceived(SchemaPath... paths) + void verifyReceived(final SchemaPath... paths) throws InterruptedException, ExecutionException, TimeoutException { final Set actual = receivedNotification.get(5, TimeUnit.SECONDS); assertEquals(ImmutableSet.copyOf(paths), actual);