@Before
  public void setUp() throws Exception {


    try {
      os = new ByteArrayOutputStream();
      System.setOut(new PrintStream(os));

      hiveConf = new HiveConfForTest(HiveMetaTool.class);
      client = new HiveMetaStoreClient(hiveConf);

      createDatabase();
      createTable();

      client.close();
      Path workDir = new Path(System.getProperty("test.tmp.dir",
              "target" + File.separator + "test" + File.separator + "tmp"));
      hiveConf.set("mapred.local.dir", workDir + File.separator + this.getClass().getSimpleName()
              + File.separator + "mapred" + File.separator + "local");
      hiveConf.set("mapred.system.dir", workDir + File.separator + this.getClass().getSimpleName()
              + File.separator + "mapred" + File.separator + "system");
      hiveConf.set("mapreduce.jobtracker.staging.root.dir", workDir + File.separator + this.getClass().getSimpleName()
              + File.separator + "mapred" + File.separator + "staging");
      hiveConf.set("mapred.temp.dir", workDir + File.separator + this.getClass().getSimpleName()
              + File.separator + "mapred" + File.separator + "temp");
      hiveConf.set(HiveConf.ConfVars.PRE_EXEC_HOOKS.varname, "");
      hiveConf.set(HiveConf.ConfVars.POST_EXEC_HOOKS.varname, "");
      hiveConf.set(HiveConf.ConfVars.METASTORE_WAREHOUSE.varname, getWarehouseDir());
      hiveConf.setVar(HiveConf.ConfVars.HIVE_INPUT_FORMAT, HiveInputFormat.class.getName());
      hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
                      "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
      hiveConf.setBoolVar(HiveConf.ConfVars.MERGE_CARDINALITY_VIOLATION_CHECK, true);
      HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.SPLIT_UPDATE, true);
      hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_STATS_COL_AUTOGATHER, false);
      hiveConf.setBoolean("mapred.input.dir.recursive", true);
      TestTxnDbUtil.setConfValues(hiveConf);
      txnHandler = TxnUtils.getTxnStore(hiveConf);
      TestTxnDbUtil.prepDb(hiveConf);
      File f = new File(getWarehouseDir());
      if (f.exists()) {
        FileUtil.fullyDelete(f);
      }
      if (!(new File(getWarehouseDir()).mkdirs())) {
        throw new RuntimeException("Could not create " + getWarehouseDir());
      }
      SessionState ss = SessionState.start(hiveConf);
      ss.applyAuthorizationPolicy();
      d = new Driver(new QueryState.Builder().withHiveConf(hiveConf).nonIsolated().build());
      d.setMaxRows(10000);
    } catch (Exception e) {
      System.err.println("Unable to setup the hive metatool test");
      System.err.println(StringUtils.stringifyException(e));
      throw new Exception(e);
    }
  }
Integration tests for the HiveMetaTool program.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/tools/metatool/TestHiveMetaTool.java