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
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 @@
         return this;
     }
 
+    /**
+     * Validate the configuration
+     */
+    public void validate() {
+        Preconditions.checkArgument(getBKClientReadTimeout() * 1000 > getReadLACLongPollTimeout(),
+            "Invalid timeout configuration : bkcReadTimeoutSeconds ("+getBKClientReadTimeout()+
+                ") should be longer than readLACLongPollTimeout ("+getReadLACLongPollTimeout()+")");
+    }
+
 
 }
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 @@
         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");
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 @@
                 .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);
+    }
+
+
 }