You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by jk...@apache.org on 2014/07/04 06:16:43 UTC
git commit: KAFKA-1519 Make it possible to disable the line seperator
in the console consumer. Patch from Gwen Shapira.
Repository: kafka
Updated Branches:
refs/heads/trunk b1a1cae88 -> 6de56b30b
KAFKA-1519 Make it possible to disable the line seperator in the console consumer. Patch from Gwen Shapira.
Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/6de56b30
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/6de56b30
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/6de56b30
Branch: refs/heads/trunk
Commit: 6de56b30b0f9aee19bf110431bcb4511d9b748f2
Parents: b1a1cae
Author: Jay Kreps <ja...@gmail.com>
Authored: Thu Jul 3 21:15:01 2014 -0700
Committer: Jay Kreps <ja...@gmail.com>
Committed: Thu Jul 3 21:15:01 2014 -0700
----------------------------------------------------------------------
.../scala/kafka/utils/CommandLineUtils.scala | 17 ++++---
.../unit/kafka/utils/CommandLineUtilsTest.scala | 49 ++++++++++++++++++++
2 files changed, 59 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kafka/blob/6de56b30/core/src/main/scala/kafka/utils/CommandLineUtils.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/utils/CommandLineUtils.scala b/core/src/main/scala/kafka/utils/CommandLineUtils.scala
index 1ba605c..086a624 100644
--- a/core/src/main/scala/kafka/utils/CommandLineUtils.scala
+++ b/core/src/main/scala/kafka/utils/CommandLineUtils.scala
@@ -60,14 +60,17 @@ object CommandLineUtils extends Logging {
* Parse key-value pairs in the form key=value
*/
def parseKeyValueArgs(args: Iterable[String]): Properties = {
- val splits = args.map(_ split "=").filterNot(_ == null).filterNot(_.length == 0)
- if(!splits.forall(_.length == 2)) {
- System.err.println("Invalid command line properties: " + args.mkString(" "))
- System.exit(1)
- }
+ val splits = args.map(_ split "=").filterNot(_.length == 0)
+
val props = new Properties
- for(a <- splits)
- props.put(a(0), a(1))
+ for(a <- splits) {
+ if (a.length == 1) props.put(a(0), "")
+ else if (a.length == 2) props.put(a(0), a(1))
+ else {
+ System.err.println("Invalid command line properties: " + args.mkString(" "))
+ System.exit(1)
+ }
+ }
props
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/kafka/blob/6de56b30/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala b/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala
new file mode 100644
index 0000000..e832a01
--- /dev/null
+++ b/core/src/test/scala/unit/kafka/utils/CommandLineUtilsTest.scala
@@ -0,0 +1,49 @@
+/**
+ * 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 unit.kafka.utils
+
+import junit.framework.Assert._
+import org.junit.{Test, After, Before}
+import kafka.utils.CommandLineUtils;
+
+class CommandLineUtilsTest {
+
+
+ @Test
+ def testParseEmptyArg() {
+ val argArray = Array("my.empty.property=")
+ val props = CommandLineUtils.parseKeyValueArgs(argArray)
+ assertEquals("Empty value should be equal to empty string",props.getProperty("my.empty.property"),"")
+ }
+
+ @Test
+ def testParseSingleArg() {
+ val argArray = Array("my.property=value")
+ val props = CommandLineUtils.parseKeyValueArgs(argArray)
+ assertEquals("Value of a single property should be 'value' ",props.getProperty("my.property"),"value")
+ }
+
+ @Test
+ def testParseArgs() {
+ val argArray = Array("first.property=first","second.property=second")
+ val props = CommandLineUtils.parseKeyValueArgs(argArray)
+ assertEquals("Value of first property should be 'first'",props.getProperty("first.property"),"first")
+ assertEquals("Value of second property should be 'second'",props.getProperty("second.property"),"second")
+ }
+
+}