You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by pt...@apache.org on 2015/06/01 19:37:37 UTC

[02/50] storm git commit: Rather then just log errors when required parameters are missing, throw a NullPointerException as soon as a required value is missing.

Rather then just log errors when required parameters are missing, throw a NullPointerException as soon as a required value is missing.


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

Branch: refs/heads/0.10.x-branch
Commit: 95a10557ca9eed5f193841e0a72b5032b627aceb
Parents: 326cc1c
Author: Curtis Allen <cu...@pearson.com>
Authored: Thu Apr 30 13:13:24 2015 -0600
Committer: Curtis Allen <cu...@pearson.com>
Committed: Thu Apr 30 13:13:24 2015 -0600

----------------------------------------------------------------------
 .../jvm/storm/kafka/DynamicBrokersReader.java   | 34 +++++++++++---------
 .../storm/kafka/DynamicBrokersReaderTest.java   |  2 +-
 2 files changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/95a10557/external/storm-kafka/src/jvm/storm/kafka/DynamicBrokersReader.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka/src/jvm/storm/kafka/DynamicBrokersReader.java b/external/storm-kafka/src/jvm/storm/kafka/DynamicBrokersReader.java
index b7baf17..d379061 100644
--- a/external/storm-kafka/src/jvm/storm/kafka/DynamicBrokersReader.java
+++ b/external/storm-kafka/src/jvm/storm/kafka/DynamicBrokersReader.java
@@ -19,6 +19,7 @@ package storm.kafka;
 
 import backtype.storm.Config;
 import backtype.storm.utils.Utils;
+import com.google.common.base.Preconditions;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.RetryNTimes;
@@ -42,12 +43,13 @@ public class DynamicBrokersReader {
 
     public DynamicBrokersReader(Map conf, String zkStr, String zkPath, String topic) {
         // Check required parameters
-        if(conf == null) {LOG.error("conf cannot be null");}
+        Preconditions.checkNotNull(conf, "conf cannot be null");
+
         validateConfig(conf);
 
-        if(zkStr == null) {LOG.error("zkString cannot be null");}
-        if(zkPath == null) {LOG.error("zkPath cannot be null");}
-        if(topic == null) {LOG.error("topic cannot be null");}
+        Preconditions.checkNotNull(zkStr,"zkString cannot be null");
+        Preconditions.checkNotNull(zkPath, "zkPath cannot be null");
+        Preconditions.checkNotNull(topic, "topic cannot be null");
 
         _zkPath = zkPath;
         _topic = topic;
@@ -158,19 +160,19 @@ public class DynamicBrokersReader {
         }
     }
 
+    /**
+     * Validate required parameters in the input configuration Map
+     * @param conf
+     */
     private void validateConfig(final Map conf) {
-        if(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT) == null) {
-            LOG.error("{} cannot be null", Config.STORM_ZOOKEEPER_SESSION_TIMEOUT);
-        }
-        if(conf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT) == null) {
-            LOG.error("{} cannot be null", Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT);
-        }
-        if(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES) == null) {
-            LOG.error("{} cannot be null", Config.STORM_ZOOKEEPER_RETRY_TIMES);
-        }
-        if(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL) == null) {
-            LOG.error("{} cannot be null", Config.STORM_ZOOKEEPER_RETRY_INTERVAL);
-        }
+        Preconditions.checkNotNull(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT),
+                "%s cannot be null", Config.STORM_ZOOKEEPER_SESSION_TIMEOUT);
+        Preconditions.checkNotNull(conf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT),
+                "%s cannot be null", Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT);
+        Preconditions.checkNotNull(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES),
+                "%s cannot be null", Config.STORM_ZOOKEEPER_RETRY_TIMES);
+        Preconditions.checkNotNull(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL),
+                "%s cannot be null", Config.STORM_ZOOKEEPER_RETRY_INTERVAL);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/storm/blob/95a10557/external/storm-kafka/src/test/storm/kafka/DynamicBrokersReaderTest.java
----------------------------------------------------------------------
diff --git a/external/storm-kafka/src/test/storm/kafka/DynamicBrokersReaderTest.java b/external/storm-kafka/src/test/storm/kafka/DynamicBrokersReaderTest.java
index 02ff3ea..941ac9e 100644
--- a/external/storm-kafka/src/test/storm/kafka/DynamicBrokersReaderTest.java
+++ b/external/storm-kafka/src/test/storm/kafka/DynamicBrokersReaderTest.java
@@ -171,7 +171,7 @@ public class DynamicBrokersReaderTest {
         assertEquals(newHost, brokerInfo.getBrokerFor(partition).host);
     }
 
-    @Test(expected = RuntimeException.class)
+    @Test(expected = NullPointerException.class)
     public void testErrorLogsWhenConfigIsMissing() throws Exception {
         String connectionString = server.getConnectString();
         Map conf = new HashMap();