distributedlog-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject incubator-distributedlog git commit: DL-20: Validate bk read timeout in configuration
Date Sun, 31 Jul 2016 07:57:51 GMT
Repository: incubator-distributedlog
Updated Branches:
  refs/heads/master dee77d987 -> da289667f


DL-20: Validate bk read timeout in configuration

DL-20: Ensure bkcReadTimeoutSeconds is larger than readLACLongPollTimeout

Author: Yiming Zang <yzang@twitter.com>

Reviewers: Sijie Guo <sijie@apache.org>

Closes #4 from yzang/yzang/validate_configuration


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

Branch: refs/heads/master
Commit: da289667f7bdd2692e0cdd2575c3810476fdd7b6
Parents: dee77d9
Author: Yiming Zang <yzang@twitter.com>
Authored: Sun Jul 31 00:57:41 2016 -0700
Committer: Sijie Guo <sijieg@twitter.com>
Committed: Sun Jul 31 00:57:41 2016 -0700

----------------------------------------------------------------------
 .../DistributedLogConfiguration.java            |  9 +++++++
 .../twitter/distributedlog/impl/BKDLUtils.java  |  2 ++
 .../TestDistributedLogConfiguration.java        | 26 ++++++++++++++++++++
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/da289667/distributedlog-core/src/main/java/com/twitter/distributedlog/DistributedLogConfiguration.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/main/java/com/twitter/distributedlog/DistributedLogConfiguration.java
b/distributedlog-core/src/main/java/com/twitter/distributedlog/DistributedLogConfiguration.java
index 639de21..0d69f4a 100644
--- a/distributedlog-core/src/main/java/com/twitter/distributedlog/DistributedLogConfiguration.java
+++ b/distributedlog-core/src/main/java/com/twitter/distributedlog/DistributedLogConfiguration.java
@@ -3336,5 +3336,14 @@ public class DistributedLogConfiguration extends CompositeConfiguration
{
         return this;
     }
 
+    /**
+     * Validate the configuration
+     */
+    public void validate() {
+        Preconditions.checkArgument(getBKClientReadTimeout() * 1000 > getReadLACLongPollTimeout(),
+            "Invalid timeout configuration : bkcReadTimeoutSeconds ("+getBKClientReadTimeout()+
+                ") should be longer than readLACLongPollTimeout ("+getReadLACLongPollTimeout()+")");
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/da289667/distributedlog-core/src/main/java/com/twitter/distributedlog/impl/BKDLUtils.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/main/java/com/twitter/distributedlog/impl/BKDLUtils.java
b/distributedlog-core/src/main/java/com/twitter/distributedlog/impl/BKDLUtils.java
index b599dc6..dd78a4e 100644
--- a/distributedlog-core/src/main/java/com/twitter/distributedlog/impl/BKDLUtils.java
+++ b/distributedlog-core/src/main/java/com/twitter/distributedlog/impl/BKDLUtils.java
@@ -51,6 +51,8 @@ public class BKDLUtils {
         throws IllegalArgumentException {
         if (null == conf) {
             throw new IllegalArgumentException("Incorrect Configuration");
+        } else {
+            conf.validate();
         }
         if ((null == uri) || (null == uri.getAuthority()) || (null == uri.getPath())) {
             throw new IllegalArgumentException("Incorrect ZK URI");

http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/da289667/distributedlog-core/src/test/java/com/twitter/distributedlog/TestDistributedLogConfiguration.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/test/java/com/twitter/distributedlog/TestDistributedLogConfiguration.java
b/distributedlog-core/src/test/java/com/twitter/distributedlog/TestDistributedLogConfiguration.java
index f0c8e96..8dcb053 100644
--- a/distributedlog-core/src/test/java/com/twitter/distributedlog/TestDistributedLogConfiguration.java
+++ b/distributedlog-core/src/test/java/com/twitter/distributedlog/TestDistributedLogConfiguration.java
@@ -102,4 +102,30 @@ public class TestDistributedLogConfiguration {
                 .setEnsemblePlacementDnsResolverClass(TestDNSResolver.class);
         assertEquals(TestDNSResolver.class, conf3.getEnsemblePlacementDnsResolverClass());
     }
+
+    @Test(timeout = 200000)
+    public void validateConfiguration(){
+        boolean exceptionThrown=false;
+        DistributedLogConfiguration conf = new DistributedLogConfiguration();
+        // validate default configuration
+        conf.validate();
+        // test invalid timeout, should throw exception
+        conf.setReadLACLongPollTimeout(conf.getBKClientReadTimeout() * 1000);
+        try {
+            conf.validate();
+        } catch (IllegalArgumentException e){
+            exceptionThrown=true;
+        }
+        assertTrue(exceptionThrown);
+        exceptionThrown=false;
+        conf.setReadLACLongPollTimeout(conf.getBKClientReadTimeout() * 1000 * 2);
+        try {
+            conf.validate();
+        } catch (IllegalArgumentException e){
+            exceptionThrown=true;
+        }
+        assertTrue(exceptionThrown);
+    }
+
+
 }


Mime
View raw message