@Before
  public void setUp() throws Exception {

    if (tests > 0) {
      return;
    }
    tests = new JUnit4TestAdapter(this.getClass()).countTestCases();
    try {
      conf = new HiveConfForTest(getClass());
      SessionState.start(conf);

      // Test with remote metastore service
      int port = MetaStoreTestUtils.startMetaStoreWithRetry();
      conf.setVar(HiveConf.ConfVars.METASTORE_URIS, "thrift://localhost:" + port);
      conf.setIntVar(HiveConf.ConfVars.METASTORE_THRIFT_CONNECTION_RETRIES, 3);
      conf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
      conf.setVar(HiveConf.ConfVars.METASTORE_WAREHOUSE, new URI(tmppath + "/warehouse").getPath());

      // Initialize second mocked filesystem (implement only necessary stuff)
      // Physical files are resides in local file system in the similar location
      jobConf = new HiveConf(conf);
      miniDfs = new MiniDFSCluster(new Configuration(), 1, true, null);
      fs2 = miniDfs.getFileSystem();
      try {
        fs2.delete(tmppathFs2, true);
      }
      catch (IOException e) {
      }
      fs2.mkdirs(tmppathFs2);
      fs2Uri = fs2.getUri().toString();
      jobConf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fs2Uri);

      driver = DriverFactory.newDriver(jobConf);

      fs = FileSystem.get(conf);
      if (fs.exists(tmppath) && !fs.getFileStatus(tmppath).isDir()) {
        throw new RuntimeException(tmpdir + " exists but is not a directory");
      }

      if (!fs.exists(tmppath)) {
        if (!fs.mkdirs(tmppath)) {
          throw new RuntimeException("Could not make scratch directory "
              + tmpdir);
        }
      }

      db = Hive.get(conf);
      cleanup();
      isInitialized = true;
    } catch (Exception e) {
      throw new RuntimeException("Encountered exception " + e.getMessage()
              + (e.getCause() == null ? "" : ", caused by: " + e.getCause().getMessage()), e);
    }
    finally {
      if (!isInitialized) {
        shutdownMiniDfs();
      }
    }
  }
Tests DDL with remote metastore service and second namenode (HIVE-6374)
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/TestDDLWithRemoteMetastoreSecondNamenode.java