Repository: cloudstack
Updated Branches:
  refs/heads/master e3daa1096 -> cbf5155f7


Testing the elapsed time between 2 consecultive calls to System.nanoTime()

   - 1 test was added

Signed-off-by: Daan Hoogland <d...@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2f145378
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2f145378
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2f145378

Branch: refs/heads/master
Commit: 2f145378dff577bd153e0585f4990f637185d900
Parents: 5557ad5
Author: wilderrodrigues <wrodrig...@schubergphilis.com>
Authored: Tue Jun 23 19:21:29 2015 +0200
Committer: Daan Hoogland <d...@onecht.net>
Committed: Wed Jun 24 09:36:40 2015 +0200

----------------------------------------------------------------------
 utils/test/com/cloud/utils/TestProfiler.java | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2f145378/utils/test/com/cloud/utils/TestProfiler.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/TestProfiler.java 
b/utils/test/com/cloud/utils/TestProfiler.java
index cbd28f5..d801059 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

Reply via email to