Skip to content

Commit a4720b2

Browse files
cmccabeijuma
authored andcommitted
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 apache#3679 from cmccabe/KAFKA-5744
1 parent 520e651 commit a4720b2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

clients/src/test/java/org/apache/kafka/common/utils/ShellTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import org.junit.Test;
2121
import org.junit.rules.Timeout;
2222

23+
import java.io.IOException;
24+
2325
import static org.junit.Assert.assertEquals;
26+
import static org.junit.Assert.assertTrue;
27+
import static org.junit.Assert.fail;
2428
import static org.junit.Assume.assumeTrue;
2529

2630
public class ShellTest {
@@ -41,4 +45,28 @@ public void testHeadDevZero() throws Exception {
4145
String output = Shell.execCommand("head", "-c", Integer.toString(length), "/dev/zero");
4246
assertEquals(length, output.length());
4347
}
48+
49+
private final static String NONEXISTENT_PATH = "/dev/a/path/that/does/not/exist/in/the/filesystem";
50+
51+
@Test
52+
public void testAttemptToRunNonExistentProgram() throws Exception {
53+
assumeTrue(!OperatingSystem.IS_WINDOWS);
54+
try {
55+
Shell.execCommand(NONEXISTENT_PATH);
56+
fail("Expected to get an exception when trying to run a program that does not exist");
57+
} catch (IOException e) {
58+
assertTrue(e.getMessage().contains("No such file"));
59+
}
60+
}
61+
62+
@Test
63+
public void testRunProgramWithErrorReturn() throws Exception {
64+
assumeTrue(!OperatingSystem.IS_WINDOWS);
65+
try {
66+
Shell.execCommand("head", "-c", "0", NONEXISTENT_PATH);
67+
fail("Expected to get an exception when trying to head a nonexistent file");
68+
} catch (Shell.ExitCodeException e) {
69+
assertTrue(e.getMessage().contains("No such file"));
70+
}
71+
}
4472
}

0 commit comments

Comments
 (0)