Repository: calcite Updated Branches: refs/heads/master 1d2929105 -> 3f89e037c
[CALCITE-2660] OsAdapterTest should check if required commands are available Close apache/calcite#914 Signed-off-by: Kevin Risden <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/3f89e037 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/3f89e037 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/3f89e037 Branch: refs/heads/master Commit: 3f89e037cdcf99f416633a1915cbfc047e50f638 Parents: 1d29291 Author: Kevin Risden <[email protected]> Authored: Mon Nov 12 11:30:19 2018 -0500 Committer: Kevin Risden <[email protected]> Committed: Tue Nov 13 10:38:22 2018 -0500 ---------------------------------------------------------------------- .travis.yml | 2 -- .../calcite/adapter/os/OsAdapterTest.java | 24 ++++++++++++++++++++ pom.xml | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/3f89e037/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index beb8e16..390d38e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,6 @@ matrix: - env: IMAGE=maven:3-jdk-10 - env: IMAGE=maven:3-jdk-9 - env: IMAGE=maven:3-jdk-8 JDOC=Y - allow_failures: - - env: IMAGE=maven:3-jdk-12 branches: only: - master http://git-wip-us.apache.org/repos/asf/calcite/blob/3f89e037/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java ---------------------------------------------------------------------- diff --git a/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java b/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java index 7f0c053..5423964 100644 --- a/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java +++ b/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java @@ -26,11 +26,13 @@ import org.apache.calcite.util.Sources; import org.apache.calcite.util.Util; import org.hamcrest.CoreMatchers; +import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; @@ -67,6 +69,7 @@ public class OsAdapterTest { /** Returns whether there is a ".git" directory in this directory or in a * directory between this directory and root. */ private static boolean hasGit() { + assumeToolExists("git"); final String path = Sources.of(OsAdapterTest.class.getResource("/")) .file().getAbsolutePath(); File f = new File(path); @@ -83,9 +86,26 @@ public class OsAdapterTest { } } + private static void assumeToolExists(String command) { + Assume.assumeTrue(command + " does not exist", checkProcessExists(command)); + } + + private static boolean checkProcessExists(String command) { + try { + Process process = new ProcessBuilder().command(command).start(); + Assert.assertNotNull(process); + int errCode = process.waitFor(); + Assert.assertEquals(0, errCode); + return true; + } catch (AssertionError | IOException | InterruptedException e) { + return false; + } + } + @Test public void testDu() { Assume.assumeFalse("Skip: the 'du' table does not work on Windows", isWindows()); + assumeToolExists("du"); sql("select * from du") .returns(r -> { try { @@ -102,6 +122,7 @@ public class OsAdapterTest { @Test public void testDuFilterSortLimit() { Assume.assumeFalse("Skip: the 'du' table does not work on Windows", isWindows()); + assumeToolExists("du"); sql("select * from du where path like '%/src/test/java/%'\n" + "order by 1 limit 2") .returns(r -> { @@ -129,6 +150,7 @@ public class OsAdapterTest { @Test public void testPs() { Assume.assumeFalse("Skip: the 'ps' table does not work on Windows", isWindows()); + assumeToolExists("ps"); sql("select * from ps") .returns(r -> { try { @@ -149,6 +171,7 @@ public class OsAdapterTest { @Test public void testPsDistinct() { Assume.assumeFalse("Skip: the 'ps' table does not work on Windows", isWindows()); + assumeToolExists("ps"); sql("select distinct `user` from ps") .returns(r -> { try { @@ -186,6 +209,7 @@ public class OsAdapterTest { @Test public void testVmstat() { Assume.assumeFalse("Skip: the 'files' table does not work on Windows", isWindows()); + assumeToolExists("vmstat"); sql("select * from vmstat") .returns(r -> { try { http://git-wip-us.apache.org/repos/asf/calcite/blob/3f89e037/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 105a2d5..e1b5591 100644 --- a/pom.xml +++ b/pom.xml @@ -631,6 +631,7 @@ limitations under the License. <exclude>**/*TokenManager.class</exclude> <exclude>**/TokenMgrError.class</exclude> <exclude>**/org/apache/calcite/adapter/os/Processes$ProcessFactory.class</exclude> + <exclude>**/org/apache/calcite/adapter/os/OsAdapterTest.class</exclude> <exclude>**/org/apache/calcite/runtime/Resources$Inst.class</exclude> <exclude>**/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript.class</exclude> <exclude>**/org/apache/calcite/test/concurrent/ConcurrentTestCommandScript$ShellCommand.class</exclude>
