storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kabh...@apache.org
Subject [1/3] storm git commit: STORM-988: supervisor.slots.ports should not allow duplicate element values
Date Fri, 14 Aug 2015 14:59:39 GMT
Repository: storm
Updated Branches:
  refs/heads/master 5966ff3c5 -> 80c6119ba


STORM-988: supervisor.slots.ports should not allow duplicate element values


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

Branch: refs/heads/master
Commit: 26ea627fb39fb84f31de773e650318a81eba8bd4
Parents: 55ec459
Author: caofangkun <caofangkun@gmail.com>
Authored: Thu Aug 13 10:41:23 2015 +0800
Committer: caofangkun <caofangkun@gmail.com>
Committed: Thu Aug 13 10:41:23 2015 +0800

----------------------------------------------------------------------
 storm-core/src/jvm/backtype/storm/Config.java          |  2 +-
 .../src/jvm/backtype/storm/ConfigValidation.java       | 13 ++++++++++---
 storm-core/test/clj/backtype/storm/config_test.clj     |  4 +++-
 3 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/26ea627f/storm-core/src/jvm/backtype/storm/Config.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/Config.java b/storm-core/src/jvm/backtype/storm/Config.java
index 4628bd4..92f55e3 100644
--- a/storm-core/src/jvm/backtype/storm/Config.java
+++ b/storm-core/src/jvm/backtype/storm/Config.java
@@ -876,7 +876,7 @@ public class Config extends HashMap<String, Object> {
      * how many workers run on each machine.
      */
     public static final String SUPERVISOR_SLOTS_PORTS = "supervisor.slots.ports";
-    public static final Object SUPERVISOR_SLOTS_PORTS_SCHEMA = ConfigValidation.IntegersValidator;
+    public static final Object SUPERVISOR_SLOTS_PORTS_SCHEMA = ConfigValidation.NoDuplicateIntegersValidator;
 
     /**
      * A number representing the maximum number of workers any single topology can acquire.

http://git-wip-us.apache.org/repos/asf/storm/blob/26ea627f/storm-core/src/jvm/backtype/storm/ConfigValidation.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/ConfigValidation.java b/storm-core/src/jvm/backtype/storm/ConfigValidation.java
index 1153a4a..fd9dae7 100644
--- a/storm-core/src/jvm/backtype/storm/ConfigValidation.java
+++ b/storm-core/src/jvm/backtype/storm/ConfigValidation.java
@@ -16,9 +16,9 @@
  * limitations under the License.
  */
 package backtype.storm;
+import java.util.HashSet;
 import java.util.Map;
-
-import java.util.Map;
+import java.util.Set;
 
 /**
  * Provides functionality for validating configuration fields.
@@ -228,7 +228,7 @@ public class ConfigValidation {
     /**
      * Validates is a list of Integers.
      */
-    public static Object IntegersValidator = new FieldValidator() {
+    public static Object NoDuplicateIntegersValidator = new FieldValidator() {
         @Override
         public void validateField(String name, Object field)
                 throws IllegalArgumentException {
@@ -236,18 +236,25 @@ public class ConfigValidation {
                 // A null value is acceptable.
                 return;
             }
+            int size = 0;
+            Set<Number> integerSet = new HashSet<Number>();
             if (field instanceof Iterable) {
                 for (Object o : (Iterable)field) {
+                    size++;
                     final long i;
                     if (o instanceof Number &&
                             ((i = ((Number)o).longValue()) == ((Number)o).doubleValue())
&&
                             (i <= Integer.MAX_VALUE && i >= Integer.MIN_VALUE))
{
                         // pass the test
+                        integerSet.add((Number) o);
                     } else {
                         throw new IllegalArgumentException(
                                 "Each element of the list " + name + " must be an Integer
within type range.");
                     }
                 }
+                if (size != integerSet.size()) {
+                       throw new IllegalArgumentException(name + " should contain no duplicate
elements");
+                }
                 return;
             }
         }

http://git-wip-us.apache.org/repos/asf/storm/blob/26ea627f/storm-core/test/clj/backtype/storm/config_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/backtype/storm/config_test.clj b/storm-core/test/clj/backtype/storm/config_test.clj
index fa5575e..0d7a963 100644
--- a/storm-core/test/clj/backtype/storm/config_test.clj
+++ b/storm-core/test/clj/backtype/storm/config_test.clj
@@ -89,10 +89,12 @@
           (.validateField validator "test" (inc Integer/MAX_VALUE))))))
 
 (deftest test-integers-validator
-  (let [validator ConfigValidation/IntegersValidator]
+  (let [validator ConfigValidation/NoDuplicateIntegersValidator]
     (.validateField validator "test" nil)
     (.validateField validator "test" [1000 0 -1000])
     (is (thrown-cause? java.lang.IllegalArgumentException
+          (.validateField validator "test" [0 10 10])))
+    (is (thrown-cause? java.lang.IllegalArgumentException
           (.validateField validator "test" [0 10 1.34])))
     (is (thrown-cause? java.lang.IllegalArgumentException
           (.validateField validator "test" [0 nil])))


Mime
View raw message