diff --git build-common.xml build-common.xml index 7f51c9f..db0f3b2 100644 --- build-common.xml +++ build-common.xml @@ -463,6 +463,7 @@ + diff --git cli/src/test/org/apache/hadoop/hive/cli/TestCmdScript.java cli/src/test/org/apache/hadoop/hive/cli/TestCmdScript.java new file mode 100644 index 0000000..c033c71 --- /dev/null +++ cli/src/test/org/apache/hadoop/hive/cli/TestCmdScript.java @@ -0,0 +1,83 @@ +package org.apache.hadoop.hive.cli; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Map; + +import junit.framework.TestCase; + +import org.junit.Test; + +public class TestCmdScript extends TestCase { + + private String command = null; + private String envs[] = null; + private final String testCommand = new String("test.hive=test.hive.string"); + + @Override + protected void setUp() throws Exception { + String osFamily = System.getProperty("test.os.family"); + if (osFamily != null && osFamily.compareTo("windows") == 0) { + command = new String("cmd.exe /c " + System.getProperty("hive.root") + "\\build\\dist\\bin\\hive.cmd "); + } else { + command = new String(System.getProperty("hive.root") + "/build/dist/bin/hive "); + } + Map variables = System.getenv(); + ArrayList tmp = new ArrayList(); + for (Map.Entry entry : variables.entrySet()) + { + tmp.add(entry.getKey() + "=" + entry.getValue()); + } + envs = (String[]) tmp.toArray(new String[tmp.size()]); + } + + @Test + public void testHiveCmd() { + assertTrue(checkHiveCmd()); + } + + @Test + public void testCliCmd() { + assertTrue(checkCliCmd()); + } + + private boolean checkHiveCmd() { + try { + Process pr = Runtime.getRuntime().exec(command + "--define " + testCommand + " -e \"set\"", + envs); + BufferedReader input = new BufferedReader(new InputStreamReader( + pr.getInputStream())); + + String line = null; + while ((line = input.readLine()) != null) { + if (line.contains(testCommand) == true) { + return true; + } + } + pr.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + private boolean checkCliCmd() { + try { + Process pr = Runtime.getRuntime().exec( + command + "--service cli --define " + testCommand + " -e \"set\"", envs); + BufferedReader input = new BufferedReader(new InputStreamReader( + pr.getInputStream())); + String line = null; + while ((line = input.readLine()) != null) { + if (line.contains(testCommand) == true) { + return true; + } + } + pr.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } +}