kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: kafka-1799; ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG doesn't work; patched by Manikumar Reddy; reviewed by Jun Rao
Date Tue, 02 Dec 2014 00:13:34 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.8.2 fbecd489c -> bd212b7a9


kafka-1799; ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG doesn't work; patched by Manikumar
Reddy; reviewed by Jun Rao


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

Branch: refs/heads/0.8.2
Commit: bd212b7a90deaf7f565d620e1aaf9a137f9a0796
Parents: fbecd48
Author: Manikumar Reddy <manikumar.reddy@gmail.com>
Authored: Mon Dec 1 16:13:28 2014 -0800
Committer: Jun Rao <junrao@gmail.com>
Committed: Mon Dec 1 16:13:28 2014 -0800

----------------------------------------------------------------------
 .../kafka/common/config/AbstractConfig.java     |   7 +-
 .../kafka/common/config/AbstractConfigTest.java | 100 +++++++++++++++++++
 2 files changed, 106 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/bd212b7a/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java b/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java
index 8d88610..3d4ab72 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java
@@ -144,7 +144,12 @@ public class AbstractConfig {
         List<String> klasses = getList(key);
         List<T> objects = new ArrayList<T>();
         for (String klass : klasses) {
-            Class<?> c = getClass(klass);
+            Class<?> c;
+            try {
+                c = Class.forName(klass);
+            } catch (ClassNotFoundException e) {
+                throw new ConfigException(key, klass, "Class " + klass + " could not be found.");
+            }
             if (c == null)
                 return null;
             Object o = Utils.newInstance(c);

http://git-wip-us.apache.org/repos/asf/kafka/blob/bd212b7a/clients/src/test/java/org/apache/kafka/common/config/AbstractConfigTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/config/AbstractConfigTest.java
b/clients/src/test/java/org/apache/kafka/common/config/AbstractConfigTest.java
new file mode 100644
index 0000000..3cfd36d
--- /dev/null
+++ b/clients/src/test/java/org/apache/kafka/common/config/AbstractConfigTest.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements. See the NOTICE
+ * file distributed with this work for additional information regarding copyright ownership.
The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the
+ * License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.kafka.common.config;
+
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.kafka.common.config.ConfigDef.Importance;
+import org.apache.kafka.common.config.ConfigDef.Type;
+import org.apache.kafka.common.metrics.KafkaMetric;
+import org.apache.kafka.common.metrics.MetricsReporter;
+import org.junit.Test;
+
+public class AbstractConfigTest {
+
+  @Test
+  public void testConfiguredInstances() {
+    testValidInputs("");
+    testValidInputs("org.apache.kafka.common.config.AbstractConfigTest$TestMetricsReporter");
+    testValidInputs("org.apache.kafka.common.config.AbstractConfigTest$TestMetricsReporter,org.apache.kafka.common.config.AbstractConfigTest$TestMetricsReporter");
+    testInvalidInputs(",");
+    testInvalidInputs("org.apache.kafka.clients.producer.unknown-metrics-reporter");
+    testInvalidInputs("test1,test2");
+    testInvalidInputs("org.apache.kafka.common.config.AbstractConfigTest$TestMetricsReporter,");
+  }
+
+  private void testValidInputs(String configValue) {
+    Properties props = new Properties();
+    props.put(TestConfig.METRIC_REPORTER_CLASSES_CONFIG, configValue);
+    TestConfig config = new TestConfig(props);
+    try {
+      config.getConfiguredInstances(TestConfig.METRIC_REPORTER_CLASSES_CONFIG,
+          MetricsReporter.class);
+    } catch (ConfigException e) {
+       fail("No exceptions are expected here, valid props are :" + props);
+    }
+  }
+  
+  private void testInvalidInputs(String configValue) {
+    Properties props = new Properties();
+    props.put(TestConfig.METRIC_REPORTER_CLASSES_CONFIG, configValue);
+    TestConfig config = new TestConfig(props);
+    try {
+      config.getConfiguredInstances(TestConfig.METRIC_REPORTER_CLASSES_CONFIG,
+          MetricsReporter.class);
+      fail("Expected a config exception due to invalid props :" + props);
+    } catch (ConfigException e) {
+      // this is good
+    }
+  }
+
+  private static class TestConfig extends AbstractConfig {
+
+    private static final ConfigDef config;
+
+    public static final String METRIC_REPORTER_CLASSES_CONFIG = "metric.reporters";
+    private static final String METRIC_REPORTER_CLASSES_DOC = "A list of classes to use as
metrics reporters.";
+
+    static {
+      config = new ConfigDef().define(METRIC_REPORTER_CLASSES_CONFIG,
+          Type.LIST, "", Importance.LOW, METRIC_REPORTER_CLASSES_DOC);
+    }
+
+    public TestConfig(Map<? extends Object, ? extends Object> props) {
+      super(config, props);
+    }
+  }
+  
+  public static class TestMetricsReporter implements MetricsReporter {
+
+    @Override
+    public void configure(Map<String, ?> configs) {
+    }
+
+    @Override
+    public void init(List<KafkaMetric> metrics) {
+}
+
+    @Override
+    public void metricChange(KafkaMetric metric) {
+    }
+
+    @Override
+    public void close() {
+    }
+  }
+}


Mime
View raw message