List of usage examples for org.apache.commons.exec CommandLine CommandLine
public CommandLine(final CommandLine other)
From source file:org.apache.bigtop.itest.hive.TestBeeline.java
@Test public void checkBeelineShowHeader() { results = HiveHelper.execCommand(new CommandLine(beelineBaseCommand).addArgument("--showHeader=false") .addArgument("-e").addArgument("SHOW DATABASES;")); String consoleMsg = results.get("outputStream").toLowerCase(); Assert.assertEquals("beeline --showHeader FAILED. \n" + results.get("outputStream"), true, consoleMsg.contains("default") && !consoleMsg.contains("database_name") && !consoleMsg.contains("error") && !consoleMsg.contains("exception")); }
From source file:org.apache.bigtop.itest.hive.TestBeeline.java
@AfterClass public static void cleanup() throws FileNotFoundException { results = HiveHelper.execCommand(/*from ww w. j a v a 2 s .co m*/ new CommandLine("/bin/sh").addArgument("-c").addArgument("rm -rf beeline*.sql", false)); results = HiveHelper .execCommand(new CommandLine("/bin/sh").addArgument("-c").addArgument("rm -rf connect.url", false)); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@BeforeClass public static void setup() { results = HiveHelper.execCommand(new CommandLine("which").addArgument("hive")); Assert.assertEquals("Hive is not in the current path.", 0, Integer.parseInt(results.get("exitValue"))); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void help() { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-H")); //LOG.info(results.get("exitValue")); Assert.assertEquals("Error in executing 'hive -H'", 2, Integer.parseInt(results.get("exitValue"))); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--help")); Assert.assertEquals("Error in executing 'hive --help'", 0, Integer.parseInt(results.get("exitValue"))); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-U")); Assert.assertEquals("Unrecognized option should exit 1.", 1, Integer.parseInt(results.get("exitValue"))); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void sqlFromCmdLine() { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("SHOW DATABASES command failed to execute.", 0, Integer.parseInt(results.get("exitValue"))); if (!results.get("outputStream").contains("bigtop_runtime_hive")) { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("CREATE DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive.", 0, Integer.parseInt(results.get("exitValue"))); } else {// w w w . j a v a2 s . c o m results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("DROP DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("CREATE DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive.", 0, Integer.parseInt(results.get("exitValue"))); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("DROP DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void sqlFromFiles() throws FileNotFoundException { try (PrintWriter out = new PrintWriter("hive-f1.sql")) { out.println("SHOW DATABASES;"); }/*from ww w .j a v a 2 s . c o m*/ try (PrintWriter out = new PrintWriter("hive-f2.sql")) { out.println("CREATE DATABASE bigtop_runtime_hive;"); } try (PrintWriter out = new PrintWriter("hive-f3.sql")) { out.println("DROP DATABASE bigtop_runtime_hive;"); out.println("CREATE DATABASE bigtop_runtime_hive;"); } try (PrintWriter out = new PrintWriter("hive-f4.sql")) { out.println("DROP DATABASE bigtop_runtime_hive;"); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-f").addArgument("hive-f1.sql") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("SHOW DATABASES command failed to execute.", 0, Integer.parseInt(results.get("exitValue"))); if (!results.get("outputStream").contains("bigtop_runtime_hive")) { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-f").addArgument("hive-f2.sql") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive.", 0, Integer.parseInt(results.get("exitValue"))); } else { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-f").addArgument("hive-f3.sql") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive.", 0, Integer.parseInt(results.get("exitValue"))); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-f").addArgument("hive-f4.sql") .addArgument("--hiveconf").addArgument(db)); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void silent() { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("-S").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("-S option did not work.", new Boolean(false), results.get("outputStream").contains("Time taken:")); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("--silent").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("--silent option did not work.", new Boolean(false), results.get("outputStream").contains("Time taken:")); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void verbose() { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("-v").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("-v option did not work.", new Boolean(true), results.get("outputStream").contains("SHOW DATABASES")); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("--verbose").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("--verbose option did not work.", new Boolean(true), results.get("outputStream").contains("SHOW DATABASES")); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void initialization() throws FileNotFoundException { try (PrintWriter out = new PrintWriter("hive-init1.sql")) { out.println("CREATE DATABASE bigtop_runtime_hive;"); }/* ww w .j av a 2s . c o m*/ try (PrintWriter out = new PrintWriter("hive-init2.sql")) { out.println("DROP DATABASE bigtop_runtime_hive;"); out.println("CREATE DATABASE bigtop_runtime_hive;"); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("SHOW DATABASES command failed to execute.", 0, Integer.parseInt(results.get("exitValue"))); if (!results.get("outputStream").contains("bigtop_runtime_hive")) { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-i").addArgument("hive-init1.sql") .addArgument("-e").addArgument("SHOW DATABASES").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive using the init -i option.", 0, Integer.parseInt(results.get("exitValue"))); Assert.assertEquals("Could not create database bigtop_runtime_hive using the init -i option.", true, results.get("outputStream").contains("bigtop_runtime_hive")); } else { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-i").addArgument("hive-init2.sql") .addArgument("-e").addArgument("SHOW DATABASES").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Could not create database bigtop_runtime_hive.", 0, Integer.parseInt(results.get("exitValue"))); Assert.assertEquals("Could not create database bigtop_runtime_hive using the init -i option.", true, results.get("outputStream").contains("bigtop_runtime_hive")); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("DROP DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); }
From source file:org.apache.bigtop.itest.hive.TestCLI.java
@Test public void database() { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e").addArgument("SHOW DATABASES") .addArgument("--hiveconf").addArgument(db)); if (!results.get("outputStream").contains("bigtop_runtime_hive")) { results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("CREATE DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); } else {/*from www .j ava 2 s . c o m*/ results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("DROP DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("CREATE DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); } results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--database") .addArgument("bigtop_runtime_hive_1234").addArgument("-e") .addArgument("CREATE TABLE bigtop ( MYID INT );").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals( "Non-existent database returned with wrong exit code: " + Integer.parseInt(results.get("exitValue")), 88, Integer.parseInt(results.get("exitValue"))); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--database") .addArgument("bigtop_runtime_hive").addArgument("-e") .addArgument("CREATE TABLE bigtop ( MYID INT );").addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Failed to create table using --database argument.", 0, Integer.parseInt(results.get("exitValue"))); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--database") .addArgument("bigtop_runtime_hive").addArgument("-e").addArgument("DESCRIBE bigtop") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Failed to get expected column after creating bigtop table using --database argument.", true, results.get("outputStream").contains("myid")); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--database") .addArgument("bigtop_runtime_hive").addArgument("-e").addArgument("DROP TABLE bigtop") .addArgument("--hiveconf").addArgument(db)); Assert.assertEquals("Failed to create table using --database argument.", 0, Integer.parseInt(results.get("exitValue"))); results = HiveHelper.execCommand(new CommandLine("hive").addArgument("-e") .addArgument("DROP DATABASE bigtop_runtime_hive").addArgument("--hiveconf").addArgument(db)); }