You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ij...@apache.org on 2017/03/29 15:11:06 UTC

kafka git commit: KAFKA-4903; Remove dead code in Shell

Repository: kafka
Updated Branches:
  refs/heads/trunk 4ce65d65d -> 42284960d


KAFKA-4903; Remove dead code in Shell

Author: Colin P. Mccabe <cm...@confluent.io>

Reviewers: Ismael Juma <is...@juma.me.uk>

Closes #2692 from cmccabe/KAFKA-4903


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

Branch: refs/heads/trunk
Commit: 42284960dab4724445a4a3a7831b3b48f0ddcb48
Parents: 4ce65d6
Author: Colin P. Mccabe <cm...@confluent.io>
Authored: Wed Mar 29 16:07:15 2017 +0100
Committer: Ismael Juma <is...@juma.me.uk>
Committed: Wed Mar 29 16:10:19 2017 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/kafka/common/Os.java   | 30 +++++++++++++
 .../org/apache/kafka/common/utils/Shell.java    |  5 ---
 .../apache/kafka/common/utils/ShellTest.java    | 45 ++++++++++++++++++++
 .../main/scala/kafka/log/AbstractIndex.scala    | 11 ++---
 core/src/main/scala/kafka/utils/Os.scala        | 25 -----------
 5 files changed, 81 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/42284960/clients/src/main/java/org/apache/kafka/common/Os.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/Os.java b/clients/src/main/java/org/apache/kafka/common/Os.java
new file mode 100644
index 0000000..ba41516
--- /dev/null
+++ b/clients/src/main/java/org/apache/kafka/common/Os.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import java.util.Locale;
+
+public final class Os {
+    public static final String NAME;
+
+    public static final boolean IS_WINDOWS;
+
+    static {
+        NAME = System.getProperty("os.name").toLowerCase(Locale.ROOT);
+        IS_WINDOWS = NAME.startsWith("windows");
+    }
+}

http://git-wip-us.apache.org/repos/asf/kafka/blob/42284960/clients/src/main/java/org/apache/kafka/common/utils/Shell.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Shell.java b/clients/src/main/java/org/apache/kafka/common/utils/Shell.java
index 0a7e1af..33bf3c1 100644
--- a/clients/src/main/java/org/apache/kafka/common/utils/Shell.java
+++ b/clients/src/main/java/org/apache/kafka/common/utils/Shell.java
@@ -115,11 +115,6 @@ abstract public class Shell {
 
         try {
             parseExecResult(inReader); // parse the output
-            // clear the input stream buffer
-            String line = null;
-            while (line != null) {
-                line = inReader.readLine();
-            }
             // wait for the process to finish and check the exit code
             exitCode = process.waitFor();
             try {

http://git-wip-us.apache.org/repos/asf/kafka/blob/42284960/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java b/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java
new file mode 100644
index 0000000..72d0590
--- /dev/null
+++ b/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.utils;
+
+import org.apache.kafka.common.Os;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.Timeout;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+public class ShellTest {
+    @Rule
+    public final Timeout globalTimeout = Timeout.seconds(180);
+
+    @Test
+    public void testEchoHello() throws Exception {
+        assumeTrue(!Os.IS_WINDOWS);
+        String output = Shell.execCommand("echo", "hello");
+        assertEquals("hello\n", output);
+    }
+
+    @Test
+    public void testHeadDevZero() throws Exception {
+        assumeTrue(!Os.IS_WINDOWS);
+        final int length = 100000;
+        String output = Shell.execCommand("head", "-c", Integer.toString(length), "/dev/zero");
+        assertEquals(length, output.length());
+    }
+}

http://git-wip-us.apache.org/repos/asf/kafka/blob/42284960/core/src/main/scala/kafka/log/AbstractIndex.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/log/AbstractIndex.scala b/core/src/main/scala/kafka/log/AbstractIndex.scala
index 6f850d5..53b2f74 100644
--- a/core/src/main/scala/kafka/log/AbstractIndex.scala
+++ b/core/src/main/scala/kafka/log/AbstractIndex.scala
@@ -24,7 +24,8 @@ import java.util.concurrent.locks.{Lock, ReentrantLock}
 
 import kafka.log.IndexSearchType.IndexSearchEntity
 import kafka.utils.CoreUtils.inLock
-import kafka.utils.{CoreUtils, Logging, Os}
+import kafka.utils.{CoreUtils, Logging}
+import org.apache.kafka.common.Os
 import org.apache.kafka.common.utils.Utils
 import sun.nio.ch.DirectBuffer
 
@@ -104,8 +105,8 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon
       val position = mmap.position
 
       /* Windows won't let us modify the file length while the file is mmapped :-( */
-      if(Os.isWindows)
-        forceUnmap(mmap)
+      if(Os.IS_WINDOWS)
+        forceUnmap(mmap);
       try {
         raf.setLength(roundedNewSize)
         mmap = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, roundedNewSize)
@@ -216,12 +217,12 @@ abstract class AbstractIndex[K, V](@volatile var file: File, val baseOffset: Lon
    * and this requires synchronizing reads.
    */
   protected def maybeLock[T](lock: Lock)(fun: => T): T = {
-    if(Os.isWindows)
+    if(Os.IS_WINDOWS)
       lock.lock()
     try {
       fun
     } finally {
-      if(Os.isWindows)
+      if(Os.IS_WINDOWS)
         lock.unlock()
     }
   }

http://git-wip-us.apache.org/repos/asf/kafka/blob/42284960/core/src/main/scala/kafka/utils/Os.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/utils/Os.scala b/core/src/main/scala/kafka/utils/Os.scala
deleted file mode 100644
index 0100a0a..0000000
--- a/core/src/main/scala/kafka/utils/Os.scala
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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 kafka.utils
-
-import java.util.Locale
-
-object Os {
-  val name = System.getProperty("os.name").toLowerCase(Locale.ROOT)
-  val isWindows = name.startsWith("windows")
-}
\ No newline at end of file