kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-5230; Fix conversion of Class configs to handle nested classes properly
Date Sun, 14 May 2017 23:39:43 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.2 6ca71c064 -> 758e3aa7e


KAFKA-5230; Fix conversion of Class configs to handle nested classes properly

Author: Ewen Cheslack-Postava <me@ewencp.org>

Reviewers: Konstantine Karantasis <konstantine@confluent.io>, Ismael Juma <ismael@juma.me.uk>

Closes #3044 from ewencp/kafka-5230-nested-class-recommended-values

(cherry picked from commit 885643ce100b3b74a2b6859bf0b85103d8c05ef8)
Signed-off-by: Ismael Juma <ismael@juma.me.uk>


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

Branch: refs/heads/0.10.2
Commit: 758e3aa7eb9fc7e7d60def9d055875a60161d2ba
Parents: 6ca71c0
Author: Ewen Cheslack-Postava <me@ewencp.org>
Authored: Mon May 15 00:39:12 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Mon May 15 00:39:38 2017 +0100

----------------------------------------------------------------------
 .../apache/kafka/common/config/ConfigDef.java   |  2 +-
 .../kafka/common/config/ConfigDefTest.java      | 67 ++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/758e3aa7/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 312205f..8a116ef 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
@@ -727,7 +727,7 @@ public class ConfigDef {
                 return Utils.join(valueList, ",");
             case CLASS:
                 Class<?> clazz = (Class<?>) parsedValue;
-                return clazz.getCanonicalName();
+                return clazz.getName();
             default:
                 throw new IllegalStateException("Unknown type.");
         }

http://git-wip-us.apache.org/repos/asf/kafka/blob/758e3aa7/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 4305779..68a5448 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
@@ -105,6 +105,7 @@ public class ConfigDefTest {
         testBadInputs(Type.STRING, new Object());
         testBadInputs(Type.LIST, 53, new Object());
         testBadInputs(Type.BOOLEAN, "hello", "truee", "fals");
+        testBadInputs(Type.CLASS, "ClassDoesNotExist");
     }
 
     private void testBadInputs(Type type, Object... values) {
@@ -132,6 +133,13 @@ public class ConfigDefTest {
     }
 
     @Test
+    public void testNestedClass() {
+        // getName(), not getSimpleName() or getCanonicalName(), is the version that should
be able to locate the class
+        Map<String, Object> props = Collections.<String, Object>singletonMap("name",
NestedClass.class.getName());
+        new ConfigDef().define("name", Type.CLASS, Importance.HIGH, "docs").parse(props);
+    }
+
+    @Test
     public void testValidators() {
         testValidators(Type.INT, Range.between(0, 10), 5, new Object[]{1, 5, 9}, new Object[]{-1,
11, null});
         testValidators(Type.STRING, ValidString.in("good", "values", "default"), "default",
@@ -481,4 +489,63 @@ public class ConfigDefTest {
         assertEquals(expectedRst, def.toEnrichedRst());
     }
 
+    @Test
+    public void testConvertValueToStringBoolean() {
+        assertEquals("true", ConfigDef.convertToString(true, Type.BOOLEAN));
+    }
+
+    @Test
+    public void testConvertValueToStringShort() {
+        assertEquals("32767", ConfigDef.convertToString(Short.MAX_VALUE, Type.SHORT));
+    }
+
+    @Test
+    public void testConvertValueToStringInt() {
+        assertEquals("2147483647", ConfigDef.convertToString(Integer.MAX_VALUE, Type.INT));
+    }
+
+    @Test
+    public void testConvertValueToStringLong() {
+        assertEquals("9223372036854775807", ConfigDef.convertToString(Long.MAX_VALUE, Type.LONG));
+    }
+
+    @Test
+    public void testConvertValueToStringDouble() {
+        assertEquals("3.125", ConfigDef.convertToString(3.125, Type.DOUBLE));
+    }
+
+    @Test
+    public void testConvertValueToStringString() {
+        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.STRING));
+    }
+
+    @Test
+    public void testConvertValueToStringPassword() {
+        assertEquals(Password.HIDDEN, ConfigDef.convertToString(new Password("foobar"), Type.PASSWORD));
+        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.PASSWORD));
+    }
+
+    @Test
+    public void testConvertValueToStringList() {
+        assertEquals("a,bc,d", ConfigDef.convertToString(Arrays.asList("a", "bc", "d"), Type.LIST));
+    }
+
+    @Test
+    public void testConvertValueToStringClass() throws ClassNotFoundException {
+        String actual = ConfigDef.convertToString(ConfigDefTest.class, Type.CLASS);
+        assertEquals("org.apache.kafka.common.config.ConfigDefTest", actual);
+        // Additionally validate that we can look up this class by this name
+        assertEquals(ConfigDefTest.class, Class.forName(actual));
+    }
+
+    @Test
+    public void testConvertValueToStringNestedClass() throws ClassNotFoundException {
+        String actual = ConfigDef.convertToString(NestedClass.class, Type.CLASS);
+        assertEquals("org.apache.kafka.common.config.ConfigDefTest$NestedClass", actual);
+        // Additionally validate that we can look up this class by this name
+        assertEquals(NestedClass.class, Class.forName(actual));
+    }
+
+    private class NestedClass {
+    }
 }


Mime
View raw message