Bump mdsal to 5.0.2
[bgpcep.git] / programming / api / src / test / java / org / opendaylight / bgpcep / programming / NanotimeUtilTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.bgpcep.programming;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.math.BigInteger;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class NanotimeUtilTest {
19     private static final Logger LOG = LoggerFactory.getLogger(NanotimeUtilTest.class);
20
21     @Test
22     public void testCurrentTime() {
23         assertTrue(NanotimeUtil.currentTime().getValue().toJava().divide(BigInteger.valueOf(1000000)).subtract(
24                 BigInteger.valueOf(System.currentTimeMillis())).shortValue() <= 0);
25     }
26
27     @Test
28     public void testNanoTime() throws InterruptedException {
29         final Nanotime nt1 = NanotimeUtil.currentNanoTime();
30         Thread.sleep(1);
31         final Nanotime nt2 = NanotimeUtil.currentNanoTime();
32
33         LOG.debug("Times: {} {}", nt1, nt2);
34         assertTrue(nt1.getValue().compareTo(nt2.getValue()) < 0);
35     }
36 }