Repository: kafka Updated Branches: refs/heads/trunk 8a719e037 -> 74bc8860c
kafka-1799; (add missing test file) 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/74bc8860 Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/74bc8860 Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/74bc8860 Branch: refs/heads/trunk Commit: 74bc8860c3c3d582f88581fc7d9edffdfa2dc3a5 Parents: 8a719e0 Author: Manikumar Reddy <[email protected]> Authored: Mon Dec 1 16:04:01 2014 -0800 Committer: Jun Rao <[email protected]> Committed: Mon Dec 1 16:04:01 2014 -0800 ---------------------------------------------------------------------- .../kafka/common/config/AbstractConfigTest.java | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/74bc8860/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() { + } + } +}
