diff --git a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java index 8a2151c..4be643e 100644 --- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java +++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/cli/TestPermsGrp.java @@ -18,7 +18,9 @@ */ package org.apache.hive.hcatalog.cli; +import java.io.BufferedReader; import java.io.FileNotFoundException; +import java.io.InputStreamReader; import java.security.Policy; import java.util.ArrayList; import java.util.Arrays; @@ -49,7 +51,6 @@ import org.apache.hadoop.hive.serde.serdeConstants; import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe; import org.apache.hive.hcatalog.DerbyPolicy; -import org.apache.hive.hcatalog.ExitException; import org.apache.hive.hcatalog.NoExitSecurityManager; import org.apache.hive.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer; import org.apache.hive.hcatalog.common.HCatConstants; @@ -92,16 +93,9 @@ protected void setUp() throws Exception { hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://127.0.0.1:" + msPort); hcatConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); hcatConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES, 3); - - hcatConf.set(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname, HCatSemanticAnalyzer.class.getName()); - hcatConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); - hcatConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, ""); hcatConf.setTimeVar(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, 60, TimeUnit.SECONDS); - hcatConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); clientWH = new Warehouse(hcatConf); msc = new HiveMetaStoreClient(hcatConf); - System.setProperty(HiveConf.ConfVars.PREEXECHOOKS.varname, " "); - System.setProperty(HiveConf.ConfVars.POSTEXECHOOKS.varname, " "); } public void testCustomPerms() throws Exception { @@ -120,13 +114,9 @@ public void testCustomPerms() throws Exception { cleanupTbl(dbName, tblName, typeName); // Next user did specify perms. - try { - callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx-wx---"}); - fail(); - } catch (Exception e) { - assertTrue(e instanceof ExitException); - assertEquals(((ExitException) e).getStatus(), 0); - } + int ret = callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", + "-p", "rwx-wx---"}); + assertEquals(ret, 0); dfsPath = clientWH.getDefaultTablePath(db, tblName); assertEquals(FsPermission.valueOf("drwx-wx---"), dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath).getPermission()); @@ -135,12 +125,9 @@ public void testCustomPerms() throws Exception { // User specified perms in invalid format. hcatConf.set(HCatConstants.HCAT_PERMS, "rwx"); // make sure create table fails. - try { - callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx"}); - fail(); - } catch (Exception me) { - assertTrue(me instanceof ExitException); - } + ret = callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx"}); + assertFalse(ret == 0); + // No physical dir gets created. dfsPath = clientWH.getDefaultTablePath(db, tblName); try { @@ -163,13 +150,9 @@ public void testCustomPerms() throws Exception { hcatConf.set(HCatConstants.HCAT_PERMS, "drw-rw-rw-"); hcatConf.set(HCatConstants.HCAT_GROUP, "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER"); - try { - // create table must fail. - callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", "-p", "rw-rw-rw-", "-g", "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER"}); - fail(); - } catch (Exception me) { - assertTrue(me instanceof SecurityException); - } + // create table must fail. + ret = callHCatCli(new String[]{"-e", "create table simptbl (name string) stored as RCFILE", "-p", "rw-rw-rw-", "-g", "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER"}); + assertFalse(ret == 0); try { // no metadata should get created. @@ -193,13 +176,44 @@ public void testCustomPerms() throws Exception { } } - private void callHCatCli(String[] args) { + private int callHCatCli(String[] args) throws Exception { List argsList = new ArrayList(); + argsList.add(System.getProperty("java.home") + "/bin/java"); + argsList.add(HCatCli.class.getName()); argsList.add("-Dhive.support.concurrency=false"); argsList .add("-Dhive.security.authorization.manager=org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); + argsList.add("-D" + HiveConf.ConfVars.METASTOREURIS.varname + "=" + "thrift://127.0.0.1:" + msPort); + argsList.add("-D" + HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES.varname + "=3"); + argsList.add("-D" + HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES.varname + "=3"); + argsList.add("-D" + HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname + "=" + HCatSemanticAnalyzer.class.getName()); + argsList.add("-D" + HiveConf.ConfVars.PREEXECHOOKS.varname + "="); + argsList.add("-D" + HiveConf.ConfVars.POSTEXECHOOKS.varname + "="); + argsList.add("-D" + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname + "=false"); + argsList.add("-D" + HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT.varname + "=60"); + argsList.add("-D" + "test.warehouse.dir=" + System.getProperty("test.warehouse.dir")); argsList.addAll(Arrays.asList(args)); - HCatCli.main(argsList.toArray(new String[]{})); + ProcessBuilder builder = new ProcessBuilder().command(argsList.toArray(new String[] {})); + builder.environment().put("CLASSPATH", System.getProperty("java.class.path")); + + Process p = builder.start(); + + String line; + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = r.readLine()) != null) { + System.out.println(line); + } + r.close(); + + r = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = r.readLine()) != null) { + System.err.println(line); + } + r.close(); + + int ret = p.waitFor(); + + return ret; } private void silentDropDatabase(String dbName) throws MetaException, TException { diff --git a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java index fb6a7f4..c9cc85e 100644 --- a/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java +++ b/hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatPartitionPublish.java @@ -108,7 +108,6 @@ public static void setup() throws Exception { msPort = MetaStoreTestUtils.startMetaStoreWithRetry(); - Thread.sleep(10000); isServerRunning = true; securityManager = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager());