kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-3237: Allow ConfigDef options with no default and validator
Date Wed, 09 Mar 2016 05:56:53 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 39f1c3ff8 -> 090d7220e


KAFKA-3237: Allow ConfigDef options with no default and validator

Remove test cases testInvalidDefaultRange() and testInvalidDefaultString(). Defaults if not
overridden will get checked on parse. Testing the defaults is unnecessary. This allows you
to set that a parameter is required while setting a validator for that parameter. Added a
test case testNullDefaultWithValidator that allows a null default with a validator for certain
strings.

Author: Jeremy Custenborder <jcustenborder@gmail.com>

Reviewers: Grant Henke <granthenke@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #936 from jcustenborder/KAFKA-3237


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/090d7220
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/090d7220
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/090d7220

Branch: refs/heads/trunk
Commit: 090d7220e2c0c4c8a39c388043c6032386ea024f
Parents: 39f1c3f
Author: Jeremy Custenborder <jcustenborder@gmail.com>
Authored: Tue Mar 8 21:56:33 2016 -0800
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Tue Mar 8 21:56:33 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/kafka/common/config/ConfigDef.java |  4 ++--
 .../org/apache/kafka/common/config/ConfigDefTest.java  | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/090d7220/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
index fe7bcce..703eb7c 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
@@ -48,7 +48,7 @@ import org.apache.kafka.common.utils.Utils;
  */
 public class ConfigDef {
 
-    private static final Object NO_DEFAULT_VALUE = new String("");
+    public static final Object NO_DEFAULT_VALUE = new String("");
 
     private final Map<String, ConfigKey> configKeys = new HashMap<String, ConfigKey>();
 
@@ -360,7 +360,7 @@ public class ConfigDef {
             this.defaultValue = defaultValue;
             this.validator = validator;
             this.importance = importance;
-            if (this.validator != null)
+            if (this.validator != null && this.hasDefault())
                 this.validator.ensureValid(name, defaultValue);
             this.documentation = documentation;
         }

http://git-wip-us.apache.org/repos/asf/kafka/blob/090d7220/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
index cb6de24..fa0370b 100644
--- a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
@@ -151,6 +151,19 @@ public class ConfigDefTest {
         assertEquals(Password.HIDDEN, vals.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG).toString());
     }
 
+    @Test
+    public void testNullDefaultWithValidator() {
+        final String key = "enum_test";
+
+        ConfigDef def = new ConfigDef();
+        def.define(key, Type.STRING, ConfigDef.NO_DEFAULT_VALUE, ValidString.in("ONE", "TWO",
"THREE"), Importance.HIGH, "docs");
+
+        Properties props = new Properties();
+        props.put(key, "ONE");
+        Map<String, Object> vals = def.parse(props);
+        assertEquals("ONE", vals.get(key));
+    }
+
     private void testValidators(Type type, Validator validator, Object defaultVal, Object[]
okValues, Object[] badValues) {
         ConfigDef def = new ConfigDef().define("name", type, defaultVal, validator, Importance.HIGH,
"docs");
 


Mime
View raw message