[05/50] [abbrv] hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-11 Thread asuresh
HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen


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

Branch: refs/heads/YARN-5972
Commit: dd814946f68d52a9b1627ac4dd61f9ab093423ae
Parents: 704267c
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:04:30 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/dd814946/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



[20/37] hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-07 Thread aengineer
HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen


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

Branch: refs/heads/HDFS-7240
Commit: dd814946f68d52a9b1627ac4dd61f9ab093423ae
Parents: 704267c
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:04:30 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/dd814946/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



[03/40] hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-07 Thread inigoiri
HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen


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

Branch: refs/heads/HDFS-10467
Commit: dd814946f68d52a9b1627ac4dd61f9ab093423ae
Parents: 704267c
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:04:30 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/dd814946/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-06 Thread jlowe
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.7 c2350ec42 -> 03892df21


HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen

(cherry picked from commit dd814946f68d52a9b1627ac4dd61f9ab093423ae)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/03892df2
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/03892df2
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/03892df2

Branch: refs/heads/branch-2.7
Commit: 03892df215634a8901910db9f84ed10c039d90a2
Parents: c2350ec
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:17:43 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/03892df2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-06 Thread jlowe
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.8 2071f8338 -> c6db50503


HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen

(cherry picked from commit dd814946f68d52a9b1627ac4dd61f9ab093423ae)


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

Branch: refs/heads/branch-2.8
Commit: c6db50503a66e52039ef75b8d6a09a60b3179b06
Parents: 2071f83
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:14:24 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c6db5050/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-06 Thread jlowe
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 fc444da89 -> f39a44412


HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen

(cherry picked from commit dd814946f68d52a9b1627ac4dd61f9ab093423ae)


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

Branch: refs/heads/branch-2
Commit: f39a44412066f06f1b1a733e6992b4c9e9fea978
Parents: fc444da
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:05:58 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/f39a4441/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-06 Thread jlowe
Repository: hadoop
Updated Branches:
  refs/heads/branch-3.0 6ec611d8c -> b2c564bca


HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen

(cherry picked from commit dd814946f68d52a9b1627ac4dd61f9ab093423ae)


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

Branch: refs/heads/branch-3.0
Commit: b2c564bca12124265d696bd98b1f75aabe667444
Parents: 6ec611d
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:05:31 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b2c564bc/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



hadoop git commit: HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. Contributed by Erik Krogen

2017-09-06 Thread jlowe
Repository: hadoop
Updated Branches:
  refs/heads/trunk 704267cb4 -> dd814946f


HADOOP-14827. Allow StopWatch to accept a Timer parameter for tests. 
Contributed by Erik Krogen


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

Branch: refs/heads/trunk
Commit: dd814946f68d52a9b1627ac4dd61f9ab093423ae
Parents: 704267c
Author: Jason Lowe 
Authored: Wed Sep 6 16:04:30 2017 -0500
Committer: Jason Lowe 
Committed: Wed Sep 6 16:04:30 2017 -0500

--
 .../java/org/apache/hadoop/util/StopWatch.java | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/dd814946/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
index b9d0d0b..c0eedf6 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StopWatch.java
@@ -25,11 +25,22 @@ import java.util.concurrent.TimeUnit;
  * A simplified StopWatch implementation which can measure times in 
nanoseconds.
  */
 public class StopWatch implements Closeable {
+  private final Timer timer;
   private boolean isStarted;
   private long startNanos;
   private long currentElapsedNanos;
 
   public StopWatch() {
+this(new Timer());
+  }
+
+  /**
+   * Used for tests to be able to create a StopWatch which does not follow real
+   * time.
+   * @param timer The timer to base this StopWatch's timekeeping off of.
+   */
+  public StopWatch(Timer timer) {
+this.timer = timer;
   }
 
   /**
@@ -49,7 +60,7 @@ public class StopWatch implements Closeable {
   throw new IllegalStateException("StopWatch is already running");
 }
 isStarted = true;
-startNanos = System.nanoTime();
+startNanos = timer.monotonicNowNanos();
 return this;
   }
 
@@ -61,7 +72,7 @@ public class StopWatch implements Closeable {
 if (!isStarted) {
   throw new IllegalStateException("StopWatch is already stopped");
 }
-long now = System.nanoTime();
+long now = timer.monotonicNowNanos();
 isStarted = false;
 currentElapsedNanos += now - startNanos;
 return this;
@@ -90,7 +101,7 @@ public class StopWatch implements Closeable {
*/
   public long now() {
 return isStarted ?
-System.nanoTime() - startNanos + currentElapsedNanos :
+timer.monotonicNowNanos() - startNanos + currentElapsedNanos :
 currentElapsedNanos;
   }
 


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org