curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [1/3] git commit: Allow forWaiting multiple to be specified via a System property
Date Sun, 07 Jul 2013 17:56:00 GMT
Updated Branches:
  refs/heads/2.2.0-incubating d55c3c0a8 -> 477cb13e5
  refs/heads/CURATOR-26 c8942b130 -> 477cb13e5


Allow forWaiting multiple to be specified via a System property


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

Branch: refs/heads/2.2.0-incubating
Commit: c8942b13030f3bc33567b02268e6f9304499460e
Parents: d55c3c0
Author: randgalt <randgalt@apache.org>
Authored: Sun Jul 7 10:25:15 2013 -0700
Committer: randgalt <randgalt@apache.org>
Committed: Sun Jul 7 10:25:15 2013 -0700

----------------------------------------------------------------------
 .../java/org/apache/curator/test/Timing.java    | 60 +++++++++++++++-----
 1 file changed, 45 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/c8942b13/curator-test/src/main/java/org/apache/curator/test/Timing.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/Timing.java b/curator-test/src/main/java/org/apache/curator/test/Timing.java
index 490bf17..2bd9159 100644
--- a/curator-test/src/main/java/org/apache/curator/test/Timing.java
+++ b/curator-test/src/main/java/org/apache/curator/test/Timing.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.test;
 
 import java.util.concurrent.CountDownLatch;
@@ -27,10 +28,12 @@ import java.util.concurrent.TimeUnit;
  */
 public class Timing
 {
-    private final long      value;
-    private final TimeUnit  unit;
+    private final long value;
+    private final TimeUnit unit;
+    private final int waitingMultiple;
 
     private static final int DEFAULT_SECONDS = 10;
+    private static final int DEFAULT_WAITING_MULTIPLE = 5;
     private static final double SESSION_MULTIPLE = .25;
 
     /**
@@ -38,7 +41,11 @@ public class Timing
      */
     public Timing()
     {
-        this(Integer.getInteger("timing-multiple", 1));
+        this
+        (
+            Integer.getInteger("timing-multiple", 1),
+            Integer.getInteger("timing-waiting-multiple", DEFAULT_WAITING_MULTIPLE)
+        );
     }
 
     /**
@@ -48,33 +55,54 @@ public class Timing
      */
     public Timing(double multiple)
     {
-        value = (int)(DEFAULT_SECONDS * multiple);
-        unit = TimeUnit.SECONDS;
+        this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, DEFAULT_WAITING_MULTIPLE);
+    }
+
+    /**
+     * Use a multiple of the default base time
+     *
+     * @param multiple the multiple
+     * @param waitingMultiple multiple of main timing to use when waiting
+     */
+    public Timing(double multiple, int waitingMultiple)
+    {
+        this((long)(DEFAULT_SECONDS * multiple), TimeUnit.SECONDS, waitingMultiple);
     }
 
     /**
      * @param value base time
-     * @param unit base time unit
+     * @param unit  base time unit
      */
     public Timing(long value, TimeUnit unit)
     {
+        this(value, unit, DEFAULT_WAITING_MULTIPLE);
+    }
+
+    /**
+     * @param value base time
+     * @param unit  base time unit
+     * @param waitingMultiple multiple of main timing to use when waiting
+     */
+    public Timing(long value, TimeUnit unit, int waitingMultiple)
+    {
         this.value = value;
         this.unit = unit;
+        this.waitingMultiple = waitingMultiple;
     }
 
     /**
      * Return the base time in milliseconds
-     * 
+     *
      * @return time ms
      */
-    public int  milliseconds()
+    public int milliseconds()
     {
         return (int)TimeUnit.MILLISECONDS.convert(value, unit);
     }
 
     /**
      * Return the base time in seconds
-     * 
+     *
      * @return time secs
      */
     public int seconds()
@@ -84,7 +112,7 @@ public class Timing
 
     /**
      * Wait on the given latch
-     * 
+     *
      * @param latch latch to wait on
      * @return result of {@link CountDownLatch#await(long, TimeUnit)}
      */
@@ -126,7 +154,7 @@ public class Timing
      * Wait on the given semaphore
      *
      * @param semaphore the semaphore
-     * @param n number of permits to acquire
+     * @param n         number of permits to acquire
      * @return result of {@link Semaphore#tryAcquire(int, long, TimeUnit)}
      */
     public boolean acquireSemaphore(Semaphore semaphore, int n)
@@ -149,7 +177,7 @@ public class Timing
      * @param n the multiple
      * @return this timing times the multiple
      */
-    public Timing   multiple(double n)
+    public Timing multiple(double n)
     {
         return new Timing((int)(value * n), unit);
     }
@@ -162,7 +190,7 @@ public class Timing
     @SuppressWarnings("PointlessArithmeticExpression")
     public Timing forWaiting()
     {
-        return multiple(5);
+        return multiple(waitingMultiple);
     }
 
     /**
@@ -177,18 +205,20 @@ public class Timing
 
     /**
      * Return the value to use for ZK session timeout
+     *
      * @return session timeout
      */
-    public int  session()
+    public int session()
     {
         return multiple(SESSION_MULTIPLE).milliseconds();
     }
 
     /**
      * Return the value to use for ZK connection timeout
+     *
      * @return connection timeout
      */
-    public int  connection()
+    public int connection()
     {
         return milliseconds();
     }


Mime
View raw message