You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ek...@apache.org on 2015/06/23 10:03:43 UTC
[1/2] git commit: updated refs/heads/master to f29bf1e
Repository: cloudstack
Updated Branches:
refs/heads/master c0a100974 -> f29bf1e85
Add unit tests to cover negative cases
- Cover when the profile is not started/stopped
Signed-off-by: wilderrodrigues <wr...@schubergphilis.com>
This closes #509
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f29bf1e8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f29bf1e8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f29bf1e8
Branch: refs/heads/master
Commit: f29bf1e85c84f7a7c91ff9521b41b32532f737ee
Parents: 78c802a
Author: wilderrodrigues <wr...@schubergphilis.com>
Authored: Mon Jun 22 16:05:15 2015 +0200
Committer: wilderrodrigues <wr...@schubergphilis.com>
Committed: Tue Jun 23 10:03:20 2015 +0200
----------------------------------------------------------------------
utils/test/com/cloud/utils/TestProfiler.java | 32 ++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f29bf1e8/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 2690a26..4323f1d 100644
--- a/utils/test/com/cloud/utils/TestProfiler.java
+++ b/utils/test/com/cloud/utils/TestProfiler.java
@@ -32,11 +32,11 @@ public class TestProfiler extends Log4jEnabledTestCase {
public void testProfiler() {
s_logger.info("testProfiler() started");
- Profiler pf = new Profiler();
+ final Profiler pf = new Profiler();
pf.start();
try {
Thread.sleep(1000);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
}
pf.stop();
@@ -46,4 +46,30 @@ public class TestProfiler extends Log4jEnabledTestCase {
s_logger.info("testProfiler() stopped");
}
-}
+
+ @Test
+ public void testProfilerNoStart() {
+ final Profiler pf = new Profiler();
+ try {
+ Thread.sleep(20);
+ } catch (final InterruptedException e) {
+ }
+ pf.stop();
+
+ Assert.assertTrue(pf.getDuration() == -1);
+ Assert.assertFalse(pf.isStarted());
+ }
+
+ @Test
+ public void testProfilerNoStop() {
+ final Profiler pf = new Profiler();
+ pf.start();
+ try {
+ Thread.sleep(20);
+ } catch (final InterruptedException e) {
+ }
+
+ Assert.assertTrue(pf.getDuration() == -1);
+ Assert.assertFalse(pf.isStopped());
+ }
+}
\ No newline at end of file
[2/2] git commit: updated refs/heads/master to f29bf1e
Posted by ek...@apache.org.
Replace System.currentTimeMillis() by System.nanoTime()
- System.nanoTime() is the best way to measure elapsed time in Java.
- It gives a resolution on the order of microseconds
The System.currentTimeMillis() is used when calculating absolut time.
Signed-off-by: wilderrodrigues <wr...@schubergphilis.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/78c802a5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/78c802a5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/78c802a5
Branch: refs/heads/master
Commit: 78c802a539e3446dee351efdbdb678cf91f8729e
Parents: c0a1009
Author: wilderrodrigues <wr...@schubergphilis.com>
Authored: Mon Jun 22 14:07:33 2015 +0200
Committer: wilderrodrigues <wr...@schubergphilis.com>
Committed: Tue Jun 23 10:03:20 2015 +0200
----------------------------------------------------------------------
utils/src/com/cloud/utils/Profiler.java | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/78c802a5/utils/src/com/cloud/utils/Profiler.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/Profiler.java b/utils/src/com/cloud/utils/Profiler.java
index e75da0e..6082a92 100644
--- a/utils/src/com/cloud/utils/Profiler.java
+++ b/utils/src/com/cloud/utils/Profiler.java
@@ -23,24 +23,20 @@ public class Profiler {
private Long startTickInMs;
private Long stopTickInMs;
- public Profiler() {
- startTickInMs = null;
- stopTickInMs = null;
- }
-
public long start() {
- startTickInMs = System.currentTimeMillis();
+ startTickInMs = System.nanoTime();
return startTickInMs.longValue();
}
public long stop() {
- stopTickInMs = System.currentTimeMillis();
+ stopTickInMs = System.nanoTime();
return stopTickInMs.longValue();
}
public long getDuration() {
- if (startTickInMs != null && stopTickInMs != null)
+ if (startTickInMs != null && stopTickInMs != null) {
return stopTickInMs.longValue() - startTickInMs.longValue();
+ }
return -1;
}
@@ -55,12 +51,14 @@ public class Profiler {
@Override
public String toString() {
- if (startTickInMs == null)
+ if (startTickInMs == null) {
return "Not Started";
+ }
- if (stopTickInMs == null)
+ if (stopTickInMs == null) {
return "Started but not stopped";
+ }
return "Done. Duration: " + getDuration() + "ms";
}
-}
+}
\ No newline at end of file