From 2f145378dff577bd153e0585f4990f637185d900 Mon Sep 17 00:00:00 2001 From: wilderrodrigues Date: Tue, 23 Jun 2015 19:21:29 +0200 Subject: [PATCH] Testing the elapsed time between 2 consecultive calls to System.nanoTime() - 1 test was added Signed-off-by: Daan Hoogland --- utils/test/com/cloud/utils/TestProfiler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/utils/test/com/cloud/utils/TestProfiler.java b/utils/test/com/cloud/utils/TestProfiler.java index cbd28f504b6..d801059c1f6 100644 --- a/utils/test/com/cloud/utils/TestProfiler.java +++ b/utils/test/com/cloud/utils/TestProfiler.java @@ -94,4 +94,18 @@ public class TestProfiler extends Log4jEnabledTestCase { Assert.assertTrue(pf.getDurationInMillis() == -1); Assert.assertFalse(pf.isStopped()); } + + @Test + public void testResolution() { + long nanoTime1 = 0l; + long nanoTime2 = 0l; + nanoTime1 = System.nanoTime(); + nanoTime2 = System.nanoTime(); + System.out.println("Nano time 1: " + nanoTime1); + System.out.println("Nano time 2: " + nanoTime2); + + // We are measuring the elapsed time in 2 consecutive calls of System.nanoTime() + // That's the same as 0.002 milliseconds or 2000 nanoseconds. + Assert.assertTrue("It took more than 2 microseconds between 2 consecutive calls to System.nanoTime().", nanoTime2 - nanoTime1 <= 2000); + } } \ No newline at end of file