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-5744; ShellTest: add tests for attempting to run nonexistent program, error return
Date Fri, 18 Aug 2017 10:39:04 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 520e651d5 -> a4720b25a


KAFKA-5744; ShellTest: add tests for attempting to run nonexistent program, error return

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

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

Closes #3679 from cmccabe/KAFKA-5744


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

Branch: refs/heads/trunk
Commit: a4720b25a372790b26a0b00fa18eb78f830b1311
Parents: 520e651
Author: Colin P. Mccabe <cmccabe@confluent.io>
Authored: Fri Aug 18 11:38:38 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Fri Aug 18 11:38:45 2017 +0100

----------------------------------------------------------------------
 .../apache/kafka/common/utils/ShellTest.java    | 28 ++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/a4720b25/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
index 923783e..b032c0b 100644
--- a/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java
@@ -20,7 +20,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.Timeout;
 
+import java.io.IOException;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
 
 public class ShellTest {
@@ -41,4 +45,28 @@ public class ShellTest {
         String output = Shell.execCommand("head", "-c", Integer.toString(length), "/dev/zero");
         assertEquals(length, output.length());
     }
+
+    private final static String NONEXISTENT_PATH = "/dev/a/path/that/does/not/exist/in/the/filesystem";
+
+    @Test
+    public void testAttemptToRunNonExistentProgram() throws Exception {
+        assumeTrue(!OperatingSystem.IS_WINDOWS);
+        try {
+            Shell.execCommand(NONEXISTENT_PATH);
+            fail("Expected to get an exception when trying to run a program that does not
exist");
+        } catch (IOException e) {
+            assertTrue(e.getMessage().contains("No such file"));
+        }
+    }
+
+    @Test
+    public void testRunProgramWithErrorReturn() throws Exception {
+        assumeTrue(!OperatingSystem.IS_WINDOWS);
+        try {
+            Shell.execCommand("head", "-c", "0", NONEXISTENT_PATH);
+            fail("Expected to get an exception when trying to head a nonexistent file");
+        } catch (Shell.ExitCodeException e) {
+            assertTrue(e.getMessage().contains("No such file"));
+        }
+    }
 }


Mime
View raw message